In: Computer Science
Convert to Assembly Language M3 (please use as CMP R1,
#3
....)
#include
#include
int main()
{
int r1 = 3;
int r2 = 15;
int r3 = 0;
if (r1 <= r2)
{ for (int n = r1; n <= r2; n++)
{ r3 += (50 - n - n + r1 + r2); } }
else
{ r3 = abs(r1) + abs(r2); }
return 0; }
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-4], edi
pxor xmm0, xmm0
cvtsi2sd xmm0, DWORD PTR [rbp-4]
movsd xmm1, QWORD PTR .LC0[rip]
andpd xmm0, xmm1
pop rbp
ret
main:
push rbp
mov rbp, rsp
sub rsp, 32
mov DWORD PTR [rbp-12], 3
mov DWORD PTR [rbp-16], 15
mov DWORD PTR [rbp-4], 0
mov eax, DWORD PTR [rbp-12]
cmp eax, DWORD PTR [rbp-16]
jg .L4
mov eax, DWORD PTR [rbp-12]
mov DWORD PTR [rbp-8], eax
.L6:
mov eax, DWORD PTR [rbp-8]
cmp eax, DWORD PTR [rbp-16]
jg .L7
mov eax, 50
sub eax, DWORD PTR [rbp-8]
sub eax, DWORD PTR [rbp-8]
mov edx, eax
mov eax, DWORD PTR [rbp-12]
add edx, eax
mov eax, DWORD PTR [rbp-16]
add eax, edx
add DWORD PTR [rbp-4], eax
add DWORD PTR [rbp-8], 1
jmp .L6
.L4:
mov eax, DWORD PTR [rbp-12]
mov edi, eax
call
__gnu_cxx::__enable_if<std::__is_integer<int>::__value,
double>::__type std::abs<int>(int)
movsd QWORD PTR [rbp-24], xmm0
mov eax, DWORD PTR [rbp-16]
mov edi, eax
call
__gnu_cxx::__enable_if<std::__is_integer<int>::__value,
double>::__type std::abs<int>(int)
addsd xmm0, QWORD PTR [rbp-24]
cvttsd2si eax, xmm0
mov DWORD PTR [rbp-4], eax
.L7:
mov eax, 0
leave
ret
.LC0:
.long 4294967295
.long 2147483647
.long 0
.long 0