In: Computer Science
Write a MIPS assembly program to first set up 10 bank accounts. Store the 10 account numbers in an array named Accounts and the 10 balances in an array named Balances (hard-code them into your program). Your program will then repeatedly read in an account number, a transaction type (0 for deposit and 1 for withdraw), and a transaction amount. Your program will display the new balance after the transaction. An error massage will be printed if an incorrect account number is entered. A withdraw request will be rejected if not enough fund is in the account. Your program will terminate when -1 is entered as an account number.
Use following account numbers and balances to initialize the arrays:
Account Balance
205 123
212 5000
200 4
203 79
201 987
231 500
209 40
207 904
211 33
250 200
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
.data
.data
Accounts : .word 205,212,200,203,201,231,209,207,211,250
balances :.word 123,500,4,79,987,500,40,904,33,200
prompt: .asciiz "\nPlease enter bank account number : "
transMsg: .asciiz "\nEnter 0 for deposit or 1 for withdraw :
"
amntMSg: .asciiz "\nPlease enter amount : "
newBalMsg: .asciiz "\nNew Balance is : "
errMsg: .asciiz "\nInsufficient balance"
notFound: .asciiz "\nAccount ID not found!!!"
currBalIsMSg: .asciiz "\nYour current balance is : "
errorTransMsg: .asciiz "\nInvalid transaction type
entered!!!"
.globl main
.text
main:
la $a3,Accounts
la $a2,balances
li $s0,10 #size of array
while:
li $v0,4
la $a0,prompt #it will print prompt
syscall
li $v0,5
syscall
beq $v0,-1,exit
li $t0,0 #index
loopSearch:
mul $t1,$t0,4 #get index of i
add $t2,$t1,$a3 #get index of array[i]
lw $t2,($t2) #get value of array[i]
beq $t2,$v0,found
addi $t0,$t0,1 #i++
blt $t0,$s0 loopSearch
li $v0,4
la $a0,notFound #it will print prompt
syscall
j while
found:
add $t3,$t1,$a2 #get index of array[i]
lw $t2,($t3) #get value of array[i]
li $v0,4
la $a0,currBalIsMSg #it will print prompt
syscall
li $v0,1
move $a0,$t2
syscall
li $v0,4
la $a0,transMsg #it will print prompt
syscall
li $v0,5
syscall
move $t7,$v0
beq $t7,0,deposite
beq $t7,1,withDraw
li $v0,4
la $a0,errorTransMsg #it will print prompt
syscall
j exitTransIF
deposite:
li $v0,4
la $a0,amntMSg #it will print prompt
syscall
li $v0,5
syscall
add $t2,$t2,$v0
sw $t2,($t3)
j exitTransIF
withDraw:
li $v0,4
la $a0,amntMSg #it will print prompt
syscall
li $v0,5
syscall
blt $t2,$v0,errorWithd
sub $t2,$t2,$v0
sw $t2,($t3)
j exitTransIF
errorWithd:
li $v0,4
la $a0,errMsg #it will print prompt
syscall
j exitTransIF
exitTransIF:
li $v0,4
la $a0,newBalMsg #it will print prompt
syscall
move $a0,$t2
li $v0,1
syscall
j while
exit: