Convert the following C program to MIPS assembly code a00 i1
Convert the following C program to MIPS assembly code
a=0.0; i=10;
while (i>0)
{
i=i-1;
a=a*B[i];
}
where a is a single-precision floating-point number stored in register $f0, i is an integer stored in register $s0, and B is a single-precision floating-point array with starting address stored in register $s1.
Solution
Answer:
MIPS Assembly Language Code:
main:
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], 0
mov DWORD PTR [rbp-8], 10
.L3:
cmp DWORD PTR [rbp-8], 0
jle .L2
sub DWORD PTR [rbp-8], 1
mov eax, DWORD PTR [rbp-8]
cdqe
mov eax, DWORD PTR [rbp-48+rax*4]
mov edx, DWORD PTR [rbp-4]
imul eax, edx
mov DWORD PTR [rbp-4], eax
jmp .L3
.L2:
mov eax, 0
pop rbp
ret
![Convert the following C program to MIPS assembly code a=0.0; i=10; while (i>0) { i=i-1; a=a*B[i]; } where a is a single-precision floating-point number store Convert the following C program to MIPS assembly code a=0.0; i=10; while (i>0) { i=i-1; a=a*B[i]; } where a is a single-precision floating-point number store](/WebImages/30/convert-the-following-c-program-to-mips-assembly-code-a00-i1-1086558-1761571432-0.webp)