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...
Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array...
Multidimensional Arrays Design a C 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...
Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array...
Multidimensional Arrays Design a C 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...
Write a MIPS assembly language program to find the addition of two arrays
Write a MIPS assembly language program to find the addition of two arrays
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...
Write a recursive ARM Assembly program that takes two integers as input and outputs the greatest...
Write a recursive ARM Assembly program that takes two integers as input and outputs the greatest common divisor. *I am using Eclipse DS-5 Community Workspace with A64 Instruction Set) Use the following algorithm: // Given two integers m and n: if (m < n) gcd(n, m) if n is a divisor of m gcd(m, n) = n else gcd (m, n) = gcd (n, m % n) Your program must be recursive. You must create a function that calls itself,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT