Write an ARM assembly program that tallies the number of 0s,1s, 2s … 9s in the D
ID: 3732234 • Letter: W
Question
Write an ARM assembly program that tallies the number of 0s,1s, 2s … 9s in the DCB array sourceArray and stores the 10 number counts in a 10-element word array starting at location 0x40000000. For example, the 0s count will be in location 0x40000000, the 1s count will be in location 0x40000004, etc. Your code must initialize each element of the “count” array to zero.
Use the following data definitions in your program.
sourceArray DCB 2,4,6,6,0,1,4,8,3,0,3,1,2,2,5,2,2,3, 8,1
DCB 9,1,5,3,4,2,6,7,8,9,0,4,4,3,2,3,6,5,4,5,6,7
DCB 4,1,2,1,4,6,7,6,3,3,2,6,8,9,9,9,1,4,2,3,4,5
File Edit View Project Flash Debug Peripherals Tools SVCS Window Help lid |"e .) .. | P1// Project Program2s Project: Programs Target 1 Reaet, CODE READHRITE Source Group 1 Startups 2, LENGTH r2, r2, #1 re, #0 FOR INIT MOV r1,#0 3, ARRAY END FOR , [3],#4 6, 6, 4 FOR CHE 13 END FOR r, sunM STOP STOP 19 AREA SUMARRAY,DATA,EADWRITE 23 DCD 5, 10, 15, 20, 30, 40, SO DCD 7 0×FFFFFFFF ARRAY LENGTH 26 Build Output TrialalSet 21Program2.(7) error: A1163E: Unknown opcode FOR INIT expecting opcode or Hacro Trial5Set 2Program2.5(9): error : A1163E: Unknown opcode FORCMP expecting opcode or M cro Trial Set 2Program2.s (11): error: 1647E: Bad register name symbol, expected Integer register Trials Set 2Program2.8 (12):error: A1163E: Unknown opcode n, expecting opcode or Hacro TrialsSet 2Program2.5(16): error : A1163E: Unknown opcode END FOR , expecting opcode or Hacro TrialsSet 2Program2.s(18): error : 1163E : Unknown opcode STOP , expecting opcode or Macro - .ATrialaSet 21Program2.8 (20) error:A1l63E: Unknown opcode sourceArray, expecting opcode or Macro Trials', Set 2Program2.s(30): error: 1163E: Unknown opcode SUM , expecting opcode or Macro TrialaSet 2Program2. 8 (31) error: A1l63E: Unknown opcode ARRAY, expecting opcode or Nacro Trials Set 2Program2.s (32) ero:Al163E: Unknown opcode LENGTHexpecting opcode or MacroExplanation / Answer
Please find my answer. Your code is not visible(image posted):
; SUM = 0 (uses r6 for sum)
; for I = 0 to LENGTH - 1 do (uses r1 for I)
; SUM = SUM + ARRAY[I] (uses r3 for address of
A[I])
; end for
AREA SUMARRAY, CODE, READONLY
ENTRY ; Always needed to indicate where to start pgm
LDR r2, LENGTH
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
ADR r3, ARRAY ; 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 dow
n 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 ; store result in SUM
STOP B STOP
AREA SUMARRAY, DATA, READWRITE
ALIGN
SUM DCD 0XFFFFFFFF
ARRAY DCD 5, 10, 15, 20, 30, 40, 50
LENGTH DCD 7
END ; Needed to stop assembly
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.