The following must be done is assembly language for x86 processors using 32-bit
ID: 3568453 • Letter: T
Question
The following must be done is assembly language for x86 processors using 32-bit programming. ASSEMBLY LANGUAGE
Create a procedure named ValidatePIN that receives a pointer to an array of bytes containing a 5-digit PIN from your main proc. You are required to use the four byte arrays samplePin_1, samplePin_2, samplePin_3 and samplePin_4 declared below. Use the two arrays (minVals and maxVals) declared below to hold the minimum and maximum range values, and use these arrays to validate each digit of the PIN that was passed to the proc ValidatePIN. If any digit is found to be outside its valid range, immediatey return the digit's position (between 1 and 5) in the EAX register to the main proc. The main proc should then display a message like "digit 3 is invalid". If the entire PIN is valid, return 0 in EAX and display "PIN is valid". Note: After the main proc displays a message indicating the validity of a PIN is it should then call the WaitMsg library procedure. Preserve all other register values between calls to the ValidatePIN procedure. Your main proc should call Validate_PIN at least four times, using both valid and invalid byte arrays.
Digit Number Range
1 5 to 9
2 2 to 5
3 4 to 8
4 1 to 4
5 3 to 6
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
samplePin_2 byte 5,2,3,2,4
samplePin_3 byte 5,2,4,5,3
samplePin_4 byte 1,3,4,4,3
Note: must be in assembly language for x86 processors using 32-bit programming, otherwise no points will be awarded. Also, need to include screenshot of output from .exe file so I know it works.
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 // it is in Irvine32.lib file it calls the new line
.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
EXIT
main endp
ValidatePIN PROC
mov ecx,PIN_SIZE
.REPEAT
.IF (al < [edi]) || (al > [ebp])
neg ecx
add ecx, 6
jmp 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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.