Convert the following program into MIPS Instructions int a

Convert the following program into MIPS Instructions: int a = 0; int b = 10; int c = 100; result = isSorted(a, b, c); if (!result) isSorted(c, b, a); int isSorted(int a, int b, int c) {if (a

Solution

Answer:

MIPS Assembly Language Code:

.zero 1
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], 0
mov DWORD PTR [rbp-8], 10
mov DWORD PTR [rbp-12], 100
mov edx, DWORD PTR [rbp-12]
mov ecx, DWORD PTR [rbp-8]
mov eax, DWORD PTR [rbp-4]
mov esi, ecx
mov edi, eax
call isSorted(int, int, int)
mov DWORD PTR [rbp-16], eax
cmp DWORD PTR [rbp-16], 0
jne .L2
mov edx, DWORD PTR [rbp-4]
mov ecx, DWORD PTR [rbp-8]
mov eax, DWORD PTR [rbp-12]
mov esi, ecx
mov edi, eax
call isSorted(int, int, int)
.L2:
mov eax, 0
leave
ret
isSorted(int, int, int):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
mov DWORD PTR [rbp-12], edx
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-8]
jge .L5
mov eax, DWORD PTR [rbp-8]
cmp eax, DWORD PTR [rbp-12]
jge .L5
mov eax, 1
jmp .L6
.L5:
mov eax, 0
.L6:
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 .L9
cmp DWORD PTR [rbp-8], 65535
jne .L9
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

 Convert the following program into MIPS Instructions: int a = 0; int b = 10; int c = 100; result = isSorted(a, b, c); if (!result) isSorted(c, b, a); int isSor
 Convert the following program into MIPS Instructions: int a = 0; int b = 10; int c = 100; result = isSorted(a, b, c); if (!result) isSorted(c, b, a); int isSor

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site