In: Computer Science
Assembly Language Visual Studio.
Problem 1
College Registration
Using the College Registration example from Section 6.7.3
(textbook) as a starting point, do the
following:
1. Recode the logic using CMP and conditional jump instructions
(instead of the .IF and .ELSEIF
directives).
2. Perform range checking on the credits value; it cannot be less
than 1 or greater than 30. If
an invalid entry is discovered, display an appropriate error
message.
3. Prompt the user for the grade average and credits values.
4. Display a message that shows the outcome of the evaluation, such
as “The student can registe”r or “The student cannot
register”.
(The Irvine32 library is required for this solution program.)
50 points
Problem 2
Validating a PIN
Banks use a Personal Identification Number (PIN) to uniquely
identify each customer. Let us
assume that our bank has a specified range of acceptable values for
each digit in its customers’
5-digit PINs. The table shown below contains the acceptable ranges,
where digits are numbered
Page 1
from left to right in the PIN. Then we can see that the PIN 52413
is valid. But the PIN 43534 is
invalid because the first digit is out of range. Similarly, 64535
is invalid because of its last digit.
Digit Number Range
1 5 to 9
2 2 to 5
3 4 to 8
4 1 to 4
5 3 to 6
Your task is to create a procedure named Validate PIN that receives
a pointer to an array of
byte containing a 5-digit PIN. Declare two arrays to hold the
minimum and maximum range
values, and use these arrays to validate each digit of the PIN that
was passed to the procedure. If
any digit is found to be outside its valid range, immediately
return the digit’s position (between 1
and 5) in the EAX register. If the entire PIN is valid, return 0 in
EAX. Preserve all other register
values between calls to the procedure. Write a test program that
calls Validate PIN at least four
times, using both valid and invalid byte arrays. By running the
program in a debugger, verify that
the return value in EAX after each procedure call is valid. Or, if
you prefer to use the book’s
library, you can display ”Valid” or ”Invalid” on the console after
each procedure call.
Answer :
2) The assembly code for pin validation is:
code:
INCLUDE Irvine32.inc
.data
str1 BYTE "valid",0
str2 BYTE "Invalid",0
minArr BYTE 5,2,4,1,3
maxArr BYTE 9,5,8,4,6
arr1 BYTE 5,1,5,3,6
arr2 BYTE 8,4,5,2,5
arr3 BYTE 6,4,5,3,5
arr4 BYTE 5,4,9,2,6
.code
main PROC
call Clrscr
mov ebx OFFSET arr1
mov esi OFFSET minArr
mov edi,OFFSET maxArr
call Validate_PIN
.IF eax==0
mov edx,OFFSET str1
call WriteString
call Crlf
.ELSE
mov edx,OFFSET str2
call WriteString
call Crlf
.ENDIF
mov ebx OFFSET arr1
call Validate_PIN
.IF eax==0
mov edx,OFFSET str1
call WriteString
call Crlf
.ELSE
mov edx,OFFSET str2
call WriteString
call Crlf
.ENDIF
mov ebx,OFFSET arr3
call Validate_PIN
.IF eax==0
mov edx,OFFSET str1
call WriteString
call Crlf
.ELSE
mov edx,OFFSET str2
call WriteString
call Crlf
.ENDIF
mov ebx,OFFSET arr4
call Validate_PIN
.IF eax==0
mov edx,OFFSET str1
call WriteString
call Crlf
.ELSE
mov edx,OFFSET str2
call WriteString
call Crlf
.ENDIF
exit
main ENDP
Validate_PIN PROC USES ecx edx esi edi
mov ecx,5
mov eax,0
L1:
mov a1[ebx]
.IF(a1>=[esi])&&(a<=[edi])
inc ebx
inc esi
inc edi
.ELSE
mov eax,6
sub eax,ecx
ja L2
.ENDIF
loop L1
mov eax,0
l2:
ret
Validate_PIN ENDP
END main
Result:
Invalid
valid
valid
Invalid
=============================================================================
ANSWERED AS PER MY KNOWLEDGE
IF ANY DOUBTS COMMENT IT