Write a MIPS assembly language program that asks a user and reads in a number of
ID: 668055 • Letter: W
Question
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. ".
Explanation / Answer
Here c program
----------------
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int months,rooms,total=0;
puts(" Enter months: ");
scanf("%d",&months);
puts(" Enter rooms: ");
scanf("%d",&rooms);
if (rooms == 1 && months< 6){
total = months * 600;
}
else if(rooms == 1 && months>=6){
total = (months * 600) - 200;
}
else if(rooms == 2 && months< 6){
total = months * 900;
}
else if(rooms == 2 && months>=6){
total = (months * 900) - 300;
}
else if(rooms <= 0 && rooms >2){
puts("Sorry, we have only one or two bedroom apartments. ");
}
printf(" Total Rent to be Paid: %d", total);
return EXIT_SUCCESS;
}
Here respective Assembly code:
--------------------------------------------------
.Ltext0:
.section .rodata
.LC0:
0000 0A456E74 .string " Enter months: "
6572206D
6F6E7468
733A2000
.LC1:
0010 256400 .string "%d"
.LC2:
0013 0A456E74 .string " Enter rooms: "
65722072
6F6F6D73
3A2000
0022 00000000 .align 8
0000
.LC3:
0028 536F7272 .string "Sorry, we have only one or two bedroom apartments. "
792C2077
65206861
7665206F
6E6C7920
.LC4:
005c 0A546F74 .string " Total Rent to be Paid: %d"
616C2052
656E7420
746F2062
65205061
.text
.globl main
main:
.LFB0:
.cfi_startproc
0000 55 pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
0001 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
0004 4883EC10 subq $16, %rsp
0008 C745FC00 movl $0, -4(%rbp)
000000
000f BF000000 movl $.LC0, %edi
00
0014 E8000000 call puts
00
0019 488D45F4 leaq -12(%rbp), %rax
001d 4889C6 movq %rax, %rsi
0020 BF000000 movl $.LC1, %edi
00
0025 B8000000 movl $0, %eax
00
002a E8000000 call __isoc99_scanf
00
002f BF000000 movl $.LC2, %edi
00
0034 E8000000 call puts
00
0039 488D45F8 leaq -8(%rbp), %rax
003d 4889C6 movq %rax, %rsi
0040 BF000000 movl $.LC1, %edi
00
0045 B8000000 movl $0, %eax
00
004a E8000000 call __isoc99_scanf
00
004f 8B45F8 movl -8(%rbp), %eax
0052 83F801 cmpl $1, %eax
0055 7516 jne .L2
0057 8B45F4 movl -12(%rbp), %eax
005a 83F805 cmpl $5, %eax
005d 7F0E jg .L2
005f 8B45F4 movl -12(%rbp), %eax
0062 69C05802 imull $600, %eax, %eax
0000
0068 8945FC movl %eax, -4(%rbp)
006b EB7D jmp .L3
.L2:
006d 8B45F8 movl -8(%rbp), %eax
0070 83F801 cmpl $1, %eax
0073 751B jne .L4
0075 8B45F4 movl -12(%rbp), %eax
0078 83F805 cmpl $5, %eax
007b 7E13 jle .L4
007d 8B45F4 movl -12(%rbp), %eax
0080 69C05802 imull $600, %eax, %eax
0000
0086 2DC80000 subl $200, %eax
00
008b 8945FC movl %eax, -4(%rbp)
008e EB5A jmp .L3
.L4:
0090 8B45F8 movl -8(%rbp), %eax
0093 83F802 cmpl $2, %eax
0096 7516 jne .L5
0098 8B45F4 movl -12(%rbp), %eax
009b 83F805 cmpl $5, %eax
009e 7F0E jg .L5
00a0 8B45F4 movl -12(%rbp), %eax
00a3 69C08403 imull $900, %eax, %eax
0000
00a9 8945FC movl %eax, -4(%rbp)
00ac EB3C jmp .L3
.L5:
00ae 8B45F8 movl -8(%rbp), %eax
00b1 83F802 cmpl $2, %eax
00b4 751B jne .L6
00b6 8B45F4 movl -12(%rbp), %eax
00b9 83F805 cmpl $5, %eax
00bc 7E13 jle .L6
00be 8B45F4 movl -12(%rbp), %eax
00c1 69C08403 imull $900, %eax, %eax
0000
00c7 2D2C0100 subl $300, %eax
00
00cc 8945FC movl %eax, -4(%rbp)
00cf EB19 jmp .L3
.L6:
00d1 8B45F8 movl -8(%rbp), %eax
00d4 85C0 testl %eax, %eax
00d6 7F12 jg .L3
00d8 8B45F8 movl -8(%rbp), %eax
00db 83F802 cmpl $2, %eax
00de 7E0A jle .L3
00e0 BF000000 movl $.LC3, %edi
00
00e5 E8000000 call puts
00
.L3:
00ea 8B45FC movl -4(%rbp), %eax
00ed 89C6 movl %eax, %esi
00ef BF000000 movl $.LC4, %edi
00
00f4 B8000000 movl $0, %eax
00
00f9 E8000000 call printf
00
00fe B8000000 movl $0, %eax
00
0103 C9 leave
.cfi_def_cfa 7, 8
0104 C3 ret
.cfi_endproc
.LFE0:
.Letext0:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.