Question

In: Computer Science

Write a MIPS assembly program to first set up 10 bank accounts. Store the 10 account...

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

Solutions

Expert Solution

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:


Related Solutions

Write a MIPS assembly program that prompts the user first for a string, then for a...
Write a MIPS assembly program that prompts the user first for a string, then for a character. The program should then search the string for the character and print out the number of times the character appears in the string. You can use as many restrictions as you want, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS)...
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS) which works as a simple calculator. The program will get two integer numbers, and based on the requested operation, the result should be shown to the user. a. The program should print a meaningful phrase for each input, and the result. i. “Enter the first number” ii. “Enter the second number” iii. “Enter the operation type” iv. “The result is” b. The user should...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
Binary Search. Write a MIPS assembly program to perform a binary search on A[10], which is an array of 10 positive integers.
Binary Search. Write a MIPS assembly program to perform a binary search on A[10], which is an array of 10 positive integers. Your program should have a main routine that does the following:(a) Prompt the user to enter all the 10 integers in the array.(b) Prompt the user to enter the number to be searched.(c) Reads the integer values and makes sure it is a positive integer.(d) Prints the index of the integer. If the input is not available in...
Write a mips assembly language program. Ask the user whether he wants to repeat the program:...
Write a mips assembly language program. Ask the user whether he wants to repeat the program: "\nRepeat [y/n]? ". Use service code 12 to read a character and the branch instruction to repeat the main function if the user input is character 'y'.
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT