You are to write a MIPS program that will execute the following simple C stateme
ID: 3666598 • Letter: Y
Question
You are to write a MIPS program that will execute the following simple C statement, f = 2*g + 5*h; You can implement the multiplication in any way you choose. You should assume that f, g, and h are of type int and therefore are 4 bytes in length. You must declare the variables appropriately and initialize them to some value of your choice. The values of g and h should be clearly displayed on the screen and the output of the instruction should be displayed on the screen as well. All output should be clearly labeled.Explanation / Answer
Answer:
.Ltext0:
.section .rodata
.LC0:
0000 456E7465 .string "Enter the g number:"
.LC1:
0014 256400 .string "%d"
.LC2:
0017 456E7465 .string "Enter the h number:"
.LC3:
002b 663D2564 .string "f=%d"
.text
.globl main
main:
.LFB0:
.cfi_startproc
0000 55 pushq %rbp
0001 4889E5 movq %rsp, %rbp
0004 4883EC10 subq $16, %rsp
0008 BF000000 movl $.LC0, %edi
000d B8000000 movl $0, %eax
0012 E8000000 call printf
0017 488D45F4 leaq -12(%rbp), %rax
001b 4889C6 movq %rax, %rsi
001e BF000000 movl $.LC1, %edi
0023 B8000000 movl $0, %eax
0028 E8000000 call __isoc99_scanf
002d BF000000 movl $.LC2, %edi
0032 B8000000 movl $0, %eax
0037 E8000000 call printf
003c 488D45F8 leaq -8(%rbp), %rax
0040 4889C6 movq %rax, %rsi
0043 BF000000 movl $.LC1, %edi
0048 B8000000 movl $0, %eax
004d E8000000 call __isoc99_scanf
0052 8B45F4 movl -12(%rbp), %eax
0055 8D0C00 leal (%rax,%rax), %ecx
0058 8B55F8 movl -8(%rbp), %edx
005b 89D0 movl %edx, %eax
005d C1E002 sall $2, %eax
0060 01D0 addl %edx, %eax
0062 01C8 addl %ecx, %eax
0064 8945FC movl %eax, -4(%rbp)
0067 8B45FC movl -4(%rbp), %eax
006a 89C6 movl %eax, %esi
006c BF000000 movl $.LC3, %edi
0071 B8000000 movl $0, %eax
0076 E8000000 call printf
007b B8000000 movl $0, %eax
0080 C9 leave
0081 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.