Assume that you are system engineer and the designated bank has assigned you a task that if any customer wants to use her internet banking facility, he must have to enter two different 8-bit pin codes one by one. Computer gets these two 8 bits numbers, converts them into binary and performs addition on both of these numbers. If the result matches with the code that is stored for this account, internet banking facility will be provided otherwise, the system will not allow the use of internet banking.
#MIPS assembly
#************************************************
.data
Enter_1: .asciiz "Enter first pin-code: "
Enter_2: .asciiz "Enter second pin-code: "
msgUnCorrect: .asciiz "UnCorrect"
msgCorrect: .asciiz "Correct"
code8: .word 0x0AA
# code segment
.text
.globl main
main:
li $v0,4 # print string
la $a0,Enter_1 # Print first pin-code: "
syscall
# Input first integer pin-code
li $v0, 5 # read integer
syscall
add $t0,$zero,$v0 # save pin-code in $t0
andi $t0, $t0, 0x0ff # leave only 8 bits
li $v0,4 # print string
la $a0,Enter_2 # Print second pin-code: "
syscall
# Input second integer pin-code
li $v0, 5 # read integer
syscall
add $t1,$zero,$v0 # save pin-code in $t1
andi $t1,$t1, 0x0ff # leave only 8 bits
add $t0, $t0, $t1 # add first code and second cpde
la $s0, code8
lw $t1, 0($s0) # load the code that is stored for this account
bne $t0, $t1, err # compare
li $v0,4 # print string
la $a0,msgCorrect # Print "UnCorrect"
syscall
j exitP
err:
li $v0,4 # print string
la $a0,msgUnCorrect # Print "Correct"
syscall
exitP:
li $v0, 10 # finished .. stop .. return
syscall # make the syscall
Comments
Leave a comment