Translating Java to MIPS For the Java statements on the left

Translating Java to MIPS

For the Java statements on the left, provide the corresponding MIPS assembly code in the corresponding space on the right. Assume f, g, and j are assigned to registers $s0, $s1, and $s2 respectively, and h is assigned to register $v0. Also assume that the starting address of the array A (which is an array of 15 words) is in register $ra

C statements

MIPS Assembly code

f = (g + h) + (j + 13)

A[12] = h + A[8]

if (f != 0) {

f = f + j;

j = j - 1;

}

if (j==h) f = g+h;
else f = g-h;

f = f + A[2];

if (j !=h ) f = f + 1;

f = g + h;

THANKS IN ADVANCE!!

C statements

MIPS Assembly code

f = (g + h) + (j + 13)

A[12] = h + A[8]

if (f != 0) {

f = f + j;

j = j - 1;

}

if (j==h) f = g+h;
else f = g-h;

f = f + A[2];

if (j !=h ) f = f + 1;

f = g + h;

Solution

Answer:

Assembly Language Code:

1)mov edx, DWORD PTR [rbp-4]
mov eax, DWORD PTR [rbp-8]
add edx, eax
mov eax, DWORD PTR [rbp-12]
add eax, 13
add eax, edx
mov DWORD PTR [rbp-16], eax

2)

mov edx, DWORD PTR [rbp-64]
mov eax, DWORD PTR [rbp-4]
add eax, edx
mov DWORD PTR [rbp-48], eax

3)

cmp DWORD PTR [rbp-4], 0
je .L2
mov eax, DWORD PTR [rbp-8]
add DWORD PTR [rbp-4], eax
sub DWORD PTR [rbp-8], 1

4)

mov eax, DWORD PTR [rbp-8]
cmp eax, DWORD PTR [rbp-12]
jne .L2
mov edx, DWORD PTR [rbp-16]
mov eax, DWORD PTR [rbp-12]
add eax, edx
mov DWORD PTR [rbp-4], eax
jmp .L3
.L2:
mov eax, DWORD PTR [rbp-16]
sub eax, DWORD PTR [rbp-12]
mov DWORD PTR [rbp-4], eax
.L3:
mov eax, DWORD PTR [rbp-136]
add DWORD PTR [rbp-4], eax

5)

mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-8]
je .L2
add DWORD PTR [rbp-12], 1
.L2:
mov edx, DWORD PTR [rbp-16]
mov eax, DWORD PTR [rbp-8]
add eax, edx
mov DWORD PTR [rbp-12], eax

Translating Java to MIPS For the Java statements on the left, provide the corresponding MIPS assembly code in the corresponding space on the right. Assume f, g,
Translating Java to MIPS For the Java statements on the left, provide the corresponding MIPS assembly code in the corresponding space on the right. Assume f, g,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site