NOTE TO EXPERTS: PLEASE DON\'T ATTEMPT THIS QUESTION IF YOU ARE NOT EXPERT AT MI
ID: 3597036 • Letter: N
Question
NOTE TO EXPERTS: PLEASE DON'T ATTEMPT THIS QUESTION IF YOU ARE NOT EXPERT AT MIPS ASSEMBLY LANGUAGE AND PLEASE DON'T POST AN ANSWER YOUR CODE DOESN'T RUN AND PROVIDE THE REQUESTED RESULT.
1. Write a MIPS assembly language program that does currency conversion between US dollar and Japanese Yen.
The program must repeatedly present a menu that has 4 choices:
1) Set the rate: prompts the user to input the exchange rate, e.g. if 1 US dollar = 115 Yen then the user will input 115. The program then stores this information for future use. The initial rate should be set to 115.
2) US $ -> Yen conversion: the program prompts the user for the US amount, then displays the Yen amount.
3) Yen -> US $ conversion: the program prompts the user for the Yen amount, then displays BOTH the US $ amount AND the change in Yen. For example is the input was 250 and the rate is 115, the US $ amount is 2$, and the change is 20 Yen.
4) Exit: the program exits.
and process the choice from the user accordingly.
Note: All numbers are integers, no need for floating point operations.
Explanation / Answer
Given below is the MIPS program with output.
.data
choice1: .asciiz "1. Set the rate "
choice2: .asciiz "2. US $ -> Yen "
choice3: .asciiz "3. Yen -> US $ "
choice4: .asciiz "4. Exit "
prompt1: .asciiz "Enter your choice: "
rate: .word 115 #1 usd = 115 yen
enterrate: .asciiz "Enter the rate for 1 USD: "
enterusd: .asciiz "How may Dollars? "
enteryen: .asciiz "How many Yens? "
usd: .asciiz " USD and change is "
yen: .asciiz " Yens "
.text
lw $t0 , rate #set the initial rate
menu:
#display the choice1
li $v0, 4
la $a0, choice1
syscall
#display the choice2
li $v0, 4
la $a0, choice2
syscall
#display the choice3
li $v0, 4
la $a0, choice3
syscall
#display the choice4
li $v0, 4
la $a0, choice4
syscall
#display the prompt
li $v0, 4
la $a0, prompt1
syscall
#get user choice and store in $t1
li $v0, 5
syscall
move $t1, $v0
#check and branch depending on choice
beq $t1, 4, exit
beq $t1, 1, setrate
beq $t1, 2, usd2yen
#yen to usd
#ask for no. of yens
li $v0, 4
la $a0, enteryen
syscall
#get input and store in $t2
li $v0, 5
syscall
move $t2, $v0
#divide yen by rate to get no. of USD and change
div $t2, $t0
mflo $t3 #quotient in low is usd
mfhi $t4 #remainder in hi is change
#display the result
li $v0, 1
move $a0, $t3
syscall
li $v0, 4
la $a0, usd
syscall
li $v0, 1
move $a0, $t4
syscall
li $v0, 4
la $a0, yen
syscall
b menu
setrate:
#prompt for rate
li $v0, 4
la $a0, enterrate
syscall
#get input and store in $t0
li $v0, 5
syscall
move $t0, $v0
b menu
usd2yen:
#prompt for no. of usd
li $v0, 4
la $a0, enterusd
syscall
#get input and store in $t2
li $v0, 5
syscall
move $t2, $v0
#multiply no. of usd with rate to get no. of yens and store in $t3
mul $t3, $t2, $t0
#display the results
li $v0, 1
move $a0, $t3
syscall
li $v0, 4
la $a0, yen
syscall
b menu
exit:
#exit
li $v0, 10
syscall
output
1. Set the rate
2. US $ -> Yen
3. Yen -> US $
4. Exit
Enter your choice: 2
How may Dollars? 10
1150 Yens
1. Set the rate
2. US $ -> Yen
3. Yen -> US $
4. Exit
Enter your choice: 3
How many Yens? 250
2 USD and change is 20 Yens
1. Set the rate
2. US $ -> Yen
3. Yen -> US $
4. Exit
Enter your choice: 1
Enter the rate for 1 USD: 114
1. Set the rate
2. US $ -> Yen
3. Yen -> US $
4. Exit
Enter your choice: 2
How may Dollars? 10
1140 Yens
1. Set the rate
2. US $ -> Yen
3. Yen -> US $
4. Exit
Enter your choice: 3
How many Yens? 250
2 USD and change is 22 Yens
1. Set the rate
2. US $ -> Yen
3. Yen -> US $
4. Exit
Enter your choice: 4
-- program is finished running --
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.