Hey I need help with advanced MIPS assembly language questio
Hey, I need help with advanced MIPS assembly language question.
Solution
Answer:
Assembly Language Code :
.zero 1
main:
push rbp
mov rbp, rsp
sub rsp, 8
push 5
mov r9d, 6
mov r8d, 8
mov ecx, 4
mov edx, 2
mov esi, 3
mov edi, 1
call fn(int, int, int, int, int, int, int)
add rsp, 16
mov eax, 0
leave
ret
fn(int, int, int, int, int, int, int):
push rbp
mov rbp, rsp
push r13
push r12
push rbx
sub rsp, 40
mov DWORD PTR [rbp-36], edi
mov DWORD PTR [rbp-40], esi
mov DWORD PTR [rbp-44], edx
mov DWORD PTR [rbp-48], ecx
mov DWORD PTR [rbp-52], r8d
mov DWORD PTR [rbp-56], r9d
mov eax, DWORD PTR [rbp-40]
imul eax, DWORD PTR [rbp-44]
mov edx, eax
mov eax, DWORD PTR [rbp-36]
lea ebx, [rdx+rax]
mov eax, DWORD PTR [rbp-52]
cdq
idiv DWORD PTR [rbp-56]
mov edx, eax
mov eax, DWORD PTR [rbp-48]
sub eax, edx
mov r12d, eax
mov esi, DWORD PTR [rbp+16]
mov edi, ebx
call power(int, int)
mov r13d, eax
lea eax, [rbx+r12]
add eax, r13d
add rsp, 40
pop rbx
pop r12
pop r13
pop rbp
ret
power(int, int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-20], edi
mov DWORD PTR [rbp-24], esi
mov DWORD PTR [rbp-4], 1
.L7:
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-24]
jg .L6
add DWORD PTR [rbp-4], 1
jmp .L7
.L6:
nop
pop rbp
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 .L10
cmp DWORD PTR [rbp-8], 65535
jne .L10
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
.L10:
nop
leave
ret
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret

