Question

In: Computer Science

Convert to Assembly Language M3 (please use as CMP R1, #3 ....) #include #include int main()...

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; }

Solutions

Expert Solution

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


Related Solutions

Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main()...
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main() { int i = 2, j = 2 + i, k; k = i * j; printf("%d\n", k + j); return 0; } 2) #include <stdio.h> int main() { int i = 2, j = 2 + i, k = j / 2; if (k == 1) { printf("%d\n", j) k = k * 2; if ( k == j) { printf("%d\n|, j); }...
Translate the following C program to PEP/9 assembly language. #include <stdio.h> Int main (){ int number;...
Translate the following C program to PEP/9 assembly language. #include <stdio.h> Int main (){ int number; Scanf (“%d”, & number); if (number % 2 ==0) { printf (“Even\n”); } else { printf(“Odd\n”); } Return 0; }
convert following C++ code into MIPS assembly: int main() {                                 &
convert following C++ code into MIPS assembly: int main() {                                         int x[10], occur, count = 0;                                                              cout << "Type in array numbers:" << endl; for (int i=0; i<10; i++) // reading in integers                               { cin >> x[i];        } cout << "Type in occurrence value:" << endl;                                 cin >> occur;                                                 // Finding and printing out occurrence indexes in the array                                  cout << "Occurrences indices are:" <<...
Translate the following C program to Pep/9 assembly language. #include <stdio.h.> int main() { int numitms,j,data,sum;...
Translate the following C program to Pep/9 assembly language. #include <stdio.h.> int main() { int numitms,j,data,sum; scanf("%d", &numitms); sum=0; for (j=1;j<=numitms;j++) { scanf("%d", &data); sum+=data; } printf("sum: %d\n",sum); return0; } I got an answer with an error. Please debug the answer or have a new correct answer (don't copy and paste others' answer) main: SUBSP 2,i DECI numItms,i DECI j,j DECI data,d DECI sum,s LDWA numItms,i sum: .EQUATE 0 LDWA 1,i STWA j,j for: CPWA numItms, j BRGE endFor STRO...
Convert the following C++ statements to an ARM assembly language program: const int size = 10;...
Convert the following C++ statements to an ARM assembly language program: const int size = 10; int x[size] = {8, 2, 9, 6, 7, 0, 1, 3, 5, 4}; int y[size] = {399, -87, 12, 0, 42, -367, 57, 92, -1000, 25}; for i = 0; i < size; i++) if (x([ i ] > y[ i ]) z[ i ] = 0 else z[ i ] = 1;
Convert this C++ program exactly as you see it into x86 assembly language: // Use the...
Convert this C++ program exactly as you see it into x86 assembly language: // Use the Irvine library for the print function #include <iostream> // The string that needs to be printed char word[] = "Golf\0"; // Pointer to a specific character in the string char * character = word; //NOTE: This main() function is not portable outside of Visual Studio void main() { // Set up a LOOP - See the while loop's conditional expression below int ecx =...
REWRITE THE FOLLOWING CODES USING FOR LOOP. PLS USE C LANGUAGE FORMAT #include <stdio.h> int main(void)...
REWRITE THE FOLLOWING CODES USING FOR LOOP. PLS USE C LANGUAGE FORMAT #include <stdio.h> int main(void) {      int count ; scanf("%d",&count);           while(count--){                printf("\--------------------------------------------\ \n"); printf("\          BBBBB               A                   \ \n"); printf("\          B    B             A A                  \ \n"); printf("\          BBBB              A   A                 \ \n"); printf("\          B    B           AAAAAAA                \ \n"); printf("\          BBBBB           A       A               \ \n"); printf("\---------------------------------------------\ \n");             }                            return 0; }
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0) return 0; else if (n <= 2) return 1; else { temp = fib(n – 1); return temp + fib(n-2); } } int main() { int num; cout << "Which fibonacci number? "; cin >> num; cout << fib(num) << endl; return 0; } You must use equates to access the stack and follow the...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x...
#include <stdio.h> #include <math.h> int fun(int); int main(void)    {     int i = 5, x = 3;     i = fun(x);     printf("%d\n", i);     return 0; } int fun(int i) {      int res = 0;      res = pow (i , 3.0);      return ( res); }
1. Convert the machine language instructions into assembly language instructions: 7976C1 06
1. Convert the machine language instructions into assembly language instructions: 7976C1 06
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT