Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Convert the Following C++/Java Code into MIPS. Make sure to initialize all varia

ID: 3812692 • Letter: C

Question

Convert the Following C++/Java Code into MIPS. Make sure to initialize all variables and registers. Please denote what variables are in which registers. The use of temporary registers and values do not need to be listed. Commenting the MIPS code will help your grade. Assume the array arr is already initialized in the data section and its label is arr. Therefore, its address needs to be loaded into a register. int [] arr = {1, 2, 3, 4, 4, 3, 2, 6, 3}; int min = arr[0]; int idx = 0; for (int i = 0; i arr[i]) {min = arr[i]; idx = i;}}

Explanation / Answer

main:
push rbp
mov rbp, rsp
sub rsp, 48
mov DWORD PTR [rbp-48], 1
mov DWORD PTR [rbp-44], 2
mov DWORD PTR [rbp-40], 3
mov DWORD PTR [rbp-36], 4
mov DWORD PTR [rbp-32], 4
mov DWORD PTR [rbp-28], 3
mov DWORD PTR [rbp-24], 2
mov DWORD PTR [rbp-20], 6
mov DWORD PTR [rbp-16], 3
mov eax, DWORD PTR [rbp-48]
mov DWORD PTR [rbp-4], eax
mov DWORD PTR [rbp-8], 0
mov DWORD PTR [rbp-12], 0
.L4:
cmp DWORD PTR [rbp-12], 8
jg .L2
mov eax, DWORD PTR [rbp-12]
cdqe
mov eax, DWORD PTR [rbp-48+rax*4]
cmp eax, DWORD PTR [rbp-4]
jge .L3
mov eax, DWORD PTR [rbp-12]
cdqe
mov eax, DWORD PTR [rbp-48+rax*4]
mov DWORD PTR [rbp-4], eax
mov eax, DWORD PTR [rbp-12]
mov DWORD PTR [rbp-8], eax
.L3:
mov eax, DWORD PTR [rbp-8]
mov esi, eax
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
add DWORD PTR [rbp-12], 1
jmp .L4
.L2:
mov eax, 0
leave
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L8
cmp DWORD PTR [rbp-8], 65535
jne .L8
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
call __cxa_atexit
.L8:
nop
leave
ret
_GLOBAL__sub_I_main:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret