Question

In: Electrical Engineering

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.    

Solutions

Expert Solution

ARM Code

ENTRY;/* starting of program*/

LDR r2, LENGTH ;/*length of the array(=25)*/

SUB r2,r2, #1;/*r2 contains (LENGTH-1)*/

MOV r6, #0;/*r6 sum set to 0*/

FOR_INIT MOV r1, #0; /*r1 index I set to 0 forA[I]*/

ADR r3, ARRAY1 ; /*start r3 with address of A[0] */

FOR_CMP CMP r1, r2; /*compare I and (LENGTH-1)*/

BGT END_FOR; /*drop out of loop if I < (LENGTH-1) */

LDR r4, [r3],#4; /*load r4 with A[I] then walk r3 down ARRAY */

ADD r6, r6, r4; /*update sum with A[I]*/

ADD r1, r1, #1; /*Increment I*/

B FOR_CMP; /*loop back to for-loop check */

END_FOR

STR r6, SUM.1; /*store result in SUM1*/

/*****the second array summing operation *****/

LDR 2, LENGTH ; /*length of the array(=25)*/

SUB r2,r2,#1; /*r2 contains (LENGTH-1)*/

MOV r6, #0; /*r6 sum set to 0*/

FOR_INIT MOV r1, #0 ; /*r1 index I set to 0 for A[I]*/

ADR r3, ARRAY2: /*start r3 with address of A[0] */

FOR_CMP CMP r1, r2; /*compare I and (LENGTH-1)*/

BGT END_FOR; /*drop out of loop if I < (LENGTH-1) */

LDR r4, [r3],#4; /*load r4 with A[I] then walk r3 down ARRAY */

ADD r6, r6, r4; /*update sum with A[I]*/

ADD r1, r1, #1; /*Increment I*/

B FOR_CMP; /*loop back to for-loop check */

END_FOR

STR r7, SUM2; /*store result in SUM2*/

CMP r6,r7;

BLT R6_lower /*jump to R6_lower in case R7 is bigger*/

MOV r10, #1 /*if not, save 1 to R10*/

B STOP

R6_lower:

MOV r10, #0      /*save 0 to R10*/

B STOP

STOP B STOP

********End of code*******


Related Solutions

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 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;...
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 an arm assembly program that will multiply two arrays (index by index) and store the...
Write an arm assembly program that will multiply two arrays (index by index) and store the result in a third array. Declare an array: .data Arr1: .quad 10    #index 0             .quad 4      #index 1          ….. Arr2: .quad 2,5,6…. Arr3: .quad 0,0,0…. To load array pointer address:      Movq $Arr1, %rdx   #stores address of Arr1 index 0 in rdx To move to the next index of an array:     Addq $8,%rdx To retrieve data: Movq (%rdx), %rcx         # will...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
(Java) Create a new linked list from two given arrays with the greater element from each...
(Java) Create a new linked list from two given arrays with the greater element from each corresponding array element placed into the linked list. Given two arrays of varying size initialized with integers of varying values, the task is to create a new linked list using those arrays. The condition is that the greater element value from each corresponding array element will be added to the new linked list in the list position that maintains the integers in ascending order....
Write a program that uses two identical arrays of at least 25 integers. It should call...
Write a program that uses two identical arrays of at least 25 integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in descending order. The function should keep a count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other array. It should also keep count of the number of exchanges it makes. Display these values on...
You are given two integer arrays a and b of the same length. Let's define the...
You are given two integer arrays a and b of the same length. Let's define the difference between a and b as the sum of absolute differences of corresponding elements: difference = |a[0] - b[0]| + |a[1] - b[1]| + ... + |a[a.length - 1] - b[b.length - 1]| You can replace one element of a with any other element of a. Your task is to return the minimum possible difference between a and b that can be achieved by...
How (by what way) is each detail drawing connected with the assembly drawing of the design?...
How (by what way) is each detail drawing connected with the assembly drawing of the design? (keep your answer brief and concise, all lower cases) HTML EditorKeyboard Shortcuts
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT