In: Electrical Engineering
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.
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 ************