Question

In: Computer Science

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;

Solutions

Expert Solution

Answer: There are many errors in given c++ program this is a corrected one and now I given the assembly language coding for the c++ program below.

#include <iostream>

using namespace std;

int main ()
{
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 (int i = 0; i < size; i++)

if (x [i] > y[i])
{
int z[i] = {0};
  
}
   else
{
   int z[i] = {1};
  
}
  
}

   return 0;

}

Assembly language

str     fp, [sp, #-4]!

        add     fp, sp, #0

        sub     sp, sp, #12

        str     r0, [fp, #-8]

        mov     r3, #0

        mov     r0, r3

        add     sp, fp, #0

        ldr     fp, [sp], #4

        bx      lr

std::__ioinit:

.LC0:

        .word   8

        .word   2

        .word   9

        .word   6

        .word   7

        .word   0

        .word   1

        .word   3

        .word   5

        .word   4

.LC1:

        .word   399

        .word   -87

        .word   12

        .word   0

        .word   42

        .word   -367

        .word   57

        .word   92

        .word   -1000

        .word   25

main:

        push    {fp, lr}

        add     fp, sp, #4

        sub     sp, sp, #104

        mov     r3, #10

        str     r3, [fp, #-8]

        ldr     r3, .L13

        sub     ip, fp, #68

        mov     lr, r3

        ldmia   lr!, {r0, r1, r2, r3}

        stmia   ip!, {r0, r1, r2, r3}

        ldmia   lr!, {r0, r1, r2, r3}

        stmia   ip!, {r0, r1, r2, r3}

        ldm     lr, {r0, r1}

        stm     ip, {r0, r1}

        ldr     r3, .L13+4

        sub     ip, fp, #108

        mov     lr, r3

        ldmia   lr!, {r0, r1, r2, r3}

        stmia   ip!, {r0, r1, r2, r3}

        ldmia   lr!, {r0, r1, r2, r3}

        stmia   ip!, {r0, r1, r2, r3}

        ldm     lr, {r0, r1}

        stm     ip, {r0, r1}

        mov     r3, #0

        str     r3, [fp, #-12]

.L11:

        ldr     r3, [fp, #-12]

        cmp     r3, #9

        bgt     .L4

        ldr     r3, [fp, #-12]

        lsl     r3, r3, #2

        sub     r2, fp, #4

        add     r3, r2, r3

        ldr     r2, [r3, #-64]

        ldr     r3, [fp, #-12]

        lsl     r3, r3, #2

        sub     r1, fp, #4

        add     r3, r1, r3

        ldr     r3, [r3, #-104]

        cmp     r2, r3

        ble     .L5

        mov     r3, sp

        mov     lr, r3

        ldr     r3, [fp, #-12]

        sub     ip, r3, #1

        str     ip, [fp, #-24]

        mov     r3, ip

        add     r3, r3, #1

        mov     r0, r3

        mov     r1, #0

        mov     r2, #0

        mov     r3, #0

        lsl     r3, r1, #5

        orr     r3, r3, r0, lsr #27

        lsl     r2, r0, #5

        mov     r3, ip

        add     r3, r3, #1

        mov     r0, r3

        mov     r1, #0

        mov     r2, #0

        mov     r3, #0

        lsl     r3, r1, #5

        orr     r3, r3, r0, lsr #27

        lsl     r2, r0, #5

        mov     r3, ip

        add     r3, r3, #1

        lsl     r3, r3, #2

        add     r3, r3, #7

        lsr     r3, r3, #3

        lsl     r3, r3, #3

        sub     sp, sp, r3

        mov     r3, sp

        add     r3, r3, #3

        lsr     r3, r3, #2

        lsl     r3, r3, #2

        str     r3, [fp, #-28]

        ldr     r3, [fp, #-28]

        mov     r2, #0

        str     r2, [r3]

        add     r2, r3, #4

        sub     r3, ip, #1

.L7:

        cmp     r3, #0

        blt     .L6

        mov     r1, #0

        str     r1, [r2]

        add     r2, r2, #4

        sub     r3, r3, #1

        b       .L7

.L6:

        mov     sp, lr

        b       .L8

.L5:

        mov     r3, sp

        mov     lr, r3

        ldr     r3, [fp, #-12]

        sub     ip, r3, #1

        str     ip, [fp, #-16]

        mov     r3, ip

        add     r3, r3, #1

        mov     r0, r3

        mov     r1, #0

        mov     r2, #0

        mov     r3, #0

        lsl     r3, r1, #5

        orr     r3, r3, r0, lsr #27

        lsl     r2, r0, #5

        mov     r3, ip

        add     r3, r3, #1

        mov     r0, r3

        mov     r1, #0

        mov     r2, #0

        mov     r3, #0

        lsl     r3, r1, #5

        orr     r3, r3, r0, lsr #27

        lsl     r2, r0, #5

        mov     r3, ip

        add     r3, r3, #1

        lsl     r3, r3, #2

        add     r3, r3, #7

        lsr     r3, r3, #3

        lsl     r3, r3, #3

        sub     sp, sp, r3

        mov     r3, sp

        add     r3, r3, #3

        lsr     r3, r3, #2

        lsl     r3, r3, #2

        str     r3, [fp, #-20]

        ldr     r3, [fp, #-20]

        mov     r2, #1

        str     r2, [r3]

        add     r2, r3, #4

        sub     r3, ip, #1

.L10:

        cmp     r3, #0

        blt     .L9

        mov     r1, #0

        str     r1, [r2]

        add     r2, r2, #4

        sub     r3, r3, #1

        b       .L10

.L9:

        mov     sp, lr

.L8:

        ldr     r3, [fp, #-12]

        add     r3, r3, #1

        str     r3, [fp, #-12]

        b       .L11

.L4:

        mov     r3, #0

        mov     r0, r3

        sub     sp, fp, #4

        pop     {fp, lr}

        bx      lr

.L13:

        .word   .LC0

        .word   .LC1

__static_initialization_and_destruction_0(int, int):

        push    {fp, lr}

        add     fp, sp, #4

        sub     sp, sp, #8

        str     r0, [fp, #-8]

        str     r1, [fp, #-12]

        ldr     r3, [fp, #-8]

        cmp     r3, #1

        bne     .L17

        ldr     r3, [fp, #-12]

        ldr     r2, .L18

        cmp     r3, r2

        bne     .L17

        ldr     r0, .L18+4

        bl      std::ios_base::Init::Init() [complete object constructor]

        ldr     r2, .L18+8

        ldr     r1, .L18+12

        ldr     r0, .L18+4

        bl      __aeabi_atexit

.L17:

        nop

        sub     sp, fp, #4

        pop     {fp, lr}

        bx      lr

.L18:

        .word   65535

        .word   std::__ioinit

        .word   __dso_handle

        .word   _ZNSt8ios_base4InitD1Ev

_GLOBAL__sub_I_main:

        push    {fp, lr}

        add     fp, sp, #4

        ldr     r1, .L21

        mov     r0, #1

        bl      __static_initialization_and_destruction_0(int, int)

        sub     sp, fp, #4

        pop     {fp, lr}

        bx      lr

.L21:

        .word   65535


Related Solutions

C language <stdio.h> ONLY USE double and const int Write a program to convert Celsius temperature...
C language <stdio.h> ONLY USE double and const int Write a program to convert Celsius temperature to Fahrenheit temperature. The formula for converting Celsius temperature into Fahrenheit temperature is:    F = (9 / 5) * C + 32 Create integer constants for the 3 numbers in the formula (9, 5, and 32).  Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. Convert the 9 to a double when converting the temperature (use type casting). Have a...
Translate the following C++ program to Pep/9 assembly language. const char chConst = '+'; char ch1;...
Translate the following C++ program to Pep/9 assembly language. const char chConst = '+'; char ch1; char ch2; int main() { cin.get(ch1); cin.get(ch2);    cout << ch1 << chConst << ch2;    return 0; }
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; }
c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
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:" <<...
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); }...
**Add comments to existing ARM code to explain steps** Write an ARM assembly program to convert...
**Add comments to existing ARM code to explain steps** Write an ARM assembly program to convert temperatures from Celsius to Fahrenheit or from Fahrenheit to Celsius. Here are the two formulas for your reference. Use variable to read and store values. C= 5* (F - 32) / 9 F = (9 * C / 5 ) + 32 My code below: TempConvert.s LDR R8,=temperature LDR R1,[R8] LDR R8,=unit LDRB R2,[R8] LDR R8,=celsius LDRB R3,[R8] LDR R8,=fahrenheit LDRB R4,[R8] MOV R6,#9...
#include <iostream> using namespace std; const int DECLARED_SIZE = 10; void fillArray(int a[], int size, int&...
#include <iostream> using namespace std; const int DECLARED_SIZE = 10; void fillArray(int a[], int size, int& numberUsed) { cout << "Enter up to " << size << " nonnegative whole numbers.\n" << "Mark the end of the list with a negative number.\n"; int next, index = 0; cin >> next; while ((next >= 0) && (index < size)) { a[index] = next; index++; cin >> next; } numberUsed = index; } int search(const int a[], int numberUsed, int target) {...
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...
Consider the following program: 1 #define Size 64 int A[Size; Size], B[Size; Size], C[Size; Size]; int...
Consider the following program: 1 #define Size 64 int A[Size; Size], B[Size; Size], C[Size; Size]; int register i, j; for (j = 0; j< Size; j ++) { { for (i = 0; i< Size; i++) C[i; j] = A[i; j] + B[i; j]; } } Assume that the program is running on a system using demand paging and the page size is 1 Kilobyte. Each integer is 4 bytes long. It is clear that each array requires a 16-page...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT