Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HIGH RATING FOR CORRECT ANSWER, ASSEMBLY LANGUAGE CODE Write a subroutine called

ID: 3802932 • Letter: H

Question

HIGH RATING FOR CORRECT ANSWER, ASSEMBLY LANGUAGE CODE

Write a subroutine called PIN_CHECK to check if a PIN number entered by a user is among a list of valid PINs. PIN stands for Personal Identification Number. PINs can take values from 00000 to 65, 535. The valid PINs are stored in an array of words and the first word has the total number of PINs, each PIN is stored in a word, and Y points at the beginning of the array, as indicated in the figure. The five digits of the PIN entered by the user are stored in 5 consecutive bytes, where register X points at the beginning address. First, the subroutine should convert the PIN's 5 digits to a decimal number as follows digit #5 X 10000 + digit #4 X 1000 + digit #3 X 100+ digit #2 X 10 + digit#1. For example, the PIN's digits 5, 2, 3, 6, and 1 are converted to 5 X 10000 + 2 X 1000 + 3 X 100 + 6 X 10 + 1 = 52361. The subroutine should return 00 in register B if the PIN is not found otherwise it returns FF in B. B should also have EE if the PIN's decimal value is greater than 65535.

Explanation / Answer

; 32-bit assembly language template ; INCLUDE Irvine32.inc INCLUDELIB C:IrvineKernel32.lib INCLUDELIB C:IrvineIrvine32.lib INCLUDE C:IrvineIrvine32.inc pbyte typedef ptr byte ; pointer to bytes .data VALID_PIN = 0 PIN_SIZE = 5 minVals byte 5,2,4,1,3 ; globally visible maxVals byte 9,5,8,4,6 ; globally visible samplePin_1 byte 6,3,4,4,3 ; valid PIN samplePin_2 byte 5,2,3,2,4 ; digit 3 is invalid samplePin_3 byte 5,2,4,5,3 ; digit 4 is invalid samplePin_4 byte 1,3,4,4,3 ; digit 1 is invalid ptr1 pbyte samplePin_1 ; points to array samplePin_1 ptr2 pbyte samplePin_2 ; points to array samplePin_2 ptr3 pbyte samplePin_3 ; points to array samplePin_3 ptr4 pbyte samplePin_4 ; points to array samplePin_4 ptr5 pbyte minVals ; points to array minVals ptr6 pbyte maxVals ; points to array maxVals ValidPINMsg byte "The PIN is valid ", 0 ; InvalidPINMsg byte "The PIN is invalid. The invalid digit is ", 0 ; .code main proc mov eax,VALID_PIN ; mov edi,ptr5 mov ebp,ptr6 mov esi,ptr1 call ValidatePIN ; determine whether or not the PIN is valid .IF eax == ecx mov edx,OFFSET ValidPINMsg call WriteString call WaitMsg call Crlf .ELSE mov edx,OFFSET InvalidPINMsg call WriteString call WriteDec call WaitMsg call Crlf .ENDIF mov esi,ptr2 call ValidatePIN ; determine whether or not the PIN is valid .IF eax == ecx mov edx,OFFSET ValidPINMsg call WriteString call WaitMsg call Crlf .ELSE mov edx,OFFSET InvalidPINMsg call WriteString call WriteDec call WaitMsg call Crlf .ENDIF mov esi,ptr3 call ValidatePIN ; determine whether or not the PIN is valid .IF eax == ecx mov edx,OFFSET ValidPINMsg call WaitMsg call Crlf .ELSE mov edx,OFFSET InvalidPINMsg call WriteString call WriteDec call WaitMsg call Crlf .ENDIF mov esi,ptr4 call ValidatePIN ; determine whether or not the pin is valid .IF eax == ecx mov edx,OFFSET ValidPINMsg call WriteString call WaitMsg call Crlf .ELSE mov edx,OFFSET InvalidPINMsg call WriteString call WriteDec call WaitMsg call Crlf .ENDIF main endp ValidatePIN PROC mov ecx,PIN_SIZE .REPEAT .IF (esi ebp) call L1 .ELSE add esi,1 add edi,1 add ebp,1 .ENDIF dec ecx .UNTIL ecx == 0 L1: mov eax,ecx ret ret ValidatePIN ENDP END main