Question

In: Electrical Engineering

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.

Solutions

Expert Solution

Hello,
          Please find the answer attached as under. Please give a thumbs up rating if you find the answer useful! Have a rocking day ahead!

******* 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, SUM1; /*store result in SUM1 */

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

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

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.    
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...
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that...
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that it is equivalent to the following C code. int counter; int x = 5; int y = 6; for (counter =10; counter >0;counter--) IF(X==Y) Y = Y + 1 ; ELSE Y = Y + 2} Fill in the blanks in the following code: MOV__________ ;loop counter into r0-ten times round the loop MOV__________ ;Value of y loaded into r1 MOV__________ ;Value of x...
**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...
The following code fragment is expressed in arm assembly code.Fill in the blanks, so that...
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that it is equivalent to the following C code.int counter;int x = 5;int y = 6;for (counter =10; counter >0;counter--)IF(X==Y)Y = Y + 1 ;ELSEY = Y + 2}Fill in the blanks in the following code:MOV__________ ;loop counter into r0-ten times round the loopMOV__________ ;Value of y loaded into r1MOV__________ ;Value of x loaded into r2Next CMP ____________ ;assume r1 contains y and r2 contains...
HCS12 Assembly code please. Translate the following code into assembly. Allocate each variable on the stack....
HCS12 Assembly code please. Translate the following code into assembly. Allocate each variable on the stack. Simulate your program and screenshot the final value of the variables in memory. { char A,B,C; int F; A = 2; B = 6; C = - 10; F = (A + B)*C; C = F +10 }
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT