Question

In: Computer Science

Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored...

Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are
stored in memory with base addresses at 1000, 2000 and 3000 respectively.

int absoluteDifference(int x, int y) {
int r;
if (x > y)
r = x - y;
else
r = y - x;
return r;
}
int main() {
for (int i=0; i < 10; i++) {
int a = array1[i];
int b = array2[i];
int c = absoluteDifference(a, b);
array3[i] = c;
}
}

Solutions

Expert Solution

Please give positve ratings for my effort. Thanks.

ANSWER

absoluteDifference:

        str     fp, [sp, #-4]!

        add     fp, sp, #0

        sub     sp, sp, #20

        str     r0, [fp, #-16]

        str     r1, [fp, #-20]

        ldr     r2, [fp, #-16]

        ldr     r3, [fp, #-20]

        cmp     r2, r3

        ble     .L2

        ldr     r2, [fp, #-16]

        ldr     r3, [fp, #-20]

        sub     r3, r2, r3

        str     r3, [fp, #-8]

        b       .L3

.L2:

        ldr     r2, [fp, #-20]

        ldr     r3, [fp, #-16]

        sub     r3, r2, r3

        str     r3, [fp, #-8]

.L3:

        ldr     r3, [fp, #-8]

        mov     r0, r3

        add     sp, fp, #0

        ldr     fp, [sp], #4

        bx      lr

.LC0:

        .word   1

        .word   2

        .word   3

        .word   4

        .word   5

        .word   6

        .word   7

        .word   8

        .word   9

        .word   0

main:

        push    {fp, lr}

        add     fp, sp, #4

        sub     sp, sp, #136

        ldr     r3, .L9

        sub     ip, fp, #60

        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, .L9

        sub     ip, fp, #100

        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, .L9

        sub     ip, fp, #140

        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, #-8]

        b       .L6

.L7:

        ldr     r3, [fp, #-8]

        lsl     r3, r3, #2

        sub     r2, fp, #4

        add     r3, r2, r3

        ldr     r3, [r3, #-56]

        str     r3, [fp, #-12]

        ldr     r3, [fp, #-8]

        lsl     r3, r3, #2

        sub     r2, fp, #4

        add     r3, r2, r3

        ldr     r3, [r3, #-96]

        str     r3, [fp, #-16]

        ldr     r1, [fp, #-16]

        ldr     r0, [fp, #-12]

        bl      absoluteDifference

        str     r0, [fp, #-20]

        ldr     r3, [fp, #-8]

        lsl     r3, r3, #2

        sub     r2, fp, #4

        add     r3, r2, r3

        ldr     r2, [fp, #-20]

        str     r2, [r3, #-136]

        ldr     r3, [fp, #-8]

        add     r3, r3, #1

        str     r3, [fp, #-8]

.L6:

        ldr     r3, [fp, #-8]

        cmp     r3, #9

        ble     .L7

        mov     r3, #0

        mov     r0, r3

        sub     sp, fp, #4

        pop     {fp, pc}

.L9:

        .word   .LC0


Related Solutions

Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored...
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored in memory with base addresses at 1000, 2000 and 3000 respectively. int absoluteDifference(int x, int y) { int r; if (x > y) r = x - y; else r = y - x; return r; } int main() { for (int i=0; i < 10; i++) { int a = array1[i]; int b = array2[i]; int c = absoluteDifference(a, b); array3[i] = c;...
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored...
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored in memory with base addresses at 1000, 2000 and 3000 respectively. int absoluteDifference(int x, int y) { int r; if (x > y) r = x - y; else r = y - x; return r; } int main() { for (int i=0; i < 10; i++) { int a = array1[i]; int b = array2[i]; int c = absoluteDifference(a, b); array3[i] = c;...
5. Two arrays “Array1” and “Array2” are given with 25 words each. Design an ARM assembly...
5. Two arrays “Array1” and “Array2” are given with 25 words each. Design an ARM assembly code to compare sum of the numbers sotred in the arrays. If sum of Array1 is greater, save a “1” in R10, otherwise, save “0’ in R10.    
Two arrays “Array1” and “Array2” are given with 25 words each. Design an ARM assembly code...
Two arrays “Array1” and “Array2” are given with 25 words each. Design an ARM assembly code to compare sum of the numbers sotred in the arrays. If sum of Array1 is greater, save a “1” in R10, otherwise, save “0’ in R10.
Write a RARS assembly language program to solve the following: For a set of integers stored...
Write a RARS assembly language program to solve the following: For a set of integers stored in an array, calculate the sum of the positive numbers and the sum of the negative numbers, storing the results into memory. In the data segment of the program, define an array consisting of 25 integers (words) that are a mix of positive and negative values. You can select any values you wish but try to create a balance of positive and negative numbers....
Compile the following C code to MIPS assembly. a. Assume that i and j are stored...
Compile the following C code to MIPS assembly. a. Assume that i and j are stored in register $s1 and $s2, respectively. i = i – 2 + j; b. Assume base address of Array B and the variable i are stored in registers $s3 and $s1, respectively. B[1] = (B[0] x 4) - I; Explain each step in detail! my professor has the following answer: 1) addi $t0, $s1, -2 add $s1, $$t0, $s2 2) lw $t0, 0 ($s3)...
Write in Java: Write a method called: public static String[] noIdenticalCombine(String[] array1, String[] array2) { //...
Write in Java: Write a method called: public static String[] noIdenticalCombine(String[] array1, String[] array2) { // instructions: returns an array that contains all the Strings in array1 and array2 but without repetition. order does not matter, but it will return array1's elements and then array2's element that are not in array1. Assume there are no duplicates are in array1 and array2. Could use count which is how many str there are in array2, where !contains(array1, str). May an array of...
Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored...
Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored in a 16-bit integers array. The size of the array is provided in a separate variable. Use the following design: Sum = 0 FOR i = 0 TO SizeOfArray - 1     IF Arr[i] % 2 = 1           Sum = Sum + Arr[i]     END IF END FOR
Write an Intel 8085 assembly program to find the largest of N numbers stored in memory...
Write an Intel 8085 assembly program to find the largest of N numbers stored in memory using the algorithm below. Hand trace (execute) the program showing the changes made to all affected registers and memory locations. Max = a(1) For i = n to N If max < a(i) then max = a(i) Next i
Represent following LEGv8 machine code into assembly instruction. 0x784302CD
Represent following LEGv8 machine code into assembly instruction. 0x784302CD
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT