1. Write a MIPS assembly language program that asks a user and reads in a number
ID: 668098 • Letter: 1
Question
1. Write a MIPS assembly language program that asks a user and reads in a number of months to rent an apartment and how many bedroom to have.
Then it should compute its total rent, based on the following:
If the number of rooms is 1 and the number of months to rent is less than 6 (and more than 0), then the rent will be $600 x the number of months.
If the number of rooms is 1 and the number of months to rent is greater than or equals to 6, then there is a discount of $200, and the rent will be $600 x the number of months - $200.
If the number of rooms is 2 and the number of months to rent is less than 6 (and more than 0), then the rent will be $900 x the number of months.
If the number of rooms is 2 and the number of months to rent is greater than or equals to 6, then there is a discount of $300, and the rent will be $900 x the number of months - $300.
If the number of rooms a user chooses is not 1 or 2, then print out the message: "Sorry, we have only one or two bedroom apartments. "
Objectives:
-write assembly language programs to:
-perform decision making using branch instructions.
-use syscall operations to display integers and strings on the console window
-use syscall operations to read integers from the keyboard.
The following shows how it looks like in a C program:
Here is a sample output (user input is in bold):
Please enter a number of months to rent an apartment:
5
Would you like to rent an apartment of one bedroom or two bedrooms?
Please enter 1 or 2:
1
Your total rent: 3000 dollars for 5 months
-----------------------------------------------
Here is another sample output (user input is in bold):
Please enter a number of months to rent an apartment:
7
Would you like to rent an apartment of one bedroom or two bedrooms?
Please enter 1 or 2:
1
Your total rent: 4000 dollars for 7 months
-----------------------------------------------
Here is the third sample output (user input is in bold):
Please enter a number of months to rent an apartment:
9
Would you like to rent an apartment of one bedroom or two bedrooms?
Please enter 1 or 2:
2
Your total rent: 7800 dollars for 9 months
-----------------------------------------------
Here is the forth sample output (user input is in bold):
Please enter a number of months to rent an apartment:
4
Would you like to rent an apartment of one bedroom or two bedrooms?
Please enter 1 or 2:
3
Sorry, we have only one or two bedroom apartments.
--------------------------------------------
Explanation / Answer
Hi,
I Will give clear solution for your work to complete.
Step1:
this above code can be converted in this way,
step 2:
For this code you include this type of MIPS solution.
this code can be changed by below MIPS form
tips :
blt $t0, $t1, L1 // Branch if $t0 < $t1
ble $t0, $t1, L2 // Branch if $t0 <= $t1
bgt $t0, $t1, L3 // Branch if $t0 > $t1
bge $t0, $t1, L4 // Branch if $t0 >= $t1
sol: for above statement : you include step 1 solution
Step 4:
from this above all code you should change your code like this
and if you want to branch condition you include
bne and beq $r1, $r2, label // for conditional branches
slt and slti $rd, $rs, $rt // set if less than (w/ and w/o an immediate)
or $rs, $rt, imm
by above details make code is very easy.
li $v0, 1 or 4 // service 1 is print integer move $a0, $t0 // move register to be printed into argument register $a0 syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.