Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an ARM assembly program that tallies the number of 0s,1s, 2s … 9s in the D

ID: 3733041 • 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

sourceArraySize  DCB  (sourceArraySize-sourceArray)

I realize this has been previously posted, however, I am not sure my assembly is the same syntax as what has been posted. Here is an example of our last assignment:

GLOBAL reset_handler

AREA RESET, CODE, READONLY

ENTRY

reset_handler

LDR r1,=0x120A760C ;loading value that we are trying to find the number of bits set to 0

MOV r3,#32 ;setting register 3 to 32 so that in the loop there is a count down

loop MOV r2,#1 ;setting register r2 to 1 every iteration of the loop

AND r2,r1 ;this is putting register 2 and register one together

CMP r2,#0 ;comparing register 2 to the number 0

ADDEQ r0,r0,#1 ;add 1 to register 0 if register 2 is equal to 0

LSR r1,r1,#1 ;shifting one bit in register 1 to the right each iteration of loop

SUB r3,r3,#1 ;subtracting 1 from register 3, which is 32, so that the loop ends after 32 iterations

CMP r3,#0 ;comparing r3 to 0 to be able to exit loop

BNE loop ;exiting loop

stop B stop

END

I have the code exactly as posted previously, however, it will not build. I am assuming this is because the assembly language we use it not quite the same. We are unable to use FOR_INIT, FOR_CMP, END_FOR, LENGTH, and a lot of the text commands as seen in the previously posted code. I am also confused as to why the code does not have these values:

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

I would have thought they are necessary as the point is to tally each number and place them in location 0x40000000 and 0x00000004 and so forth.

Here are the errors that I am encountering.

Program3.s(10): error: A1647E: Bad register name symbol, expected Integer register
Program3.s(12): error: A1647E: Bad register name symbol, expected Integer register
Program3.s(16): error: A1163E: Unknown opcode FOR_INIT , expecting opcode or Macro
Program3.s(18): error: A1163E: Unknown opcode FOR_CMP , expecting opcode or Macro
Program3.s(20): error: A1647E: Bad register name symbol, expected Integer register
Program3.s(25): error: A1163E: Unknown opcode END_FOR , expecting opcode or Macro
Program3.s(27): error: A1163E: Unknown opcode STOP , expecting opcode or Macro
Program3.s(32): error: A1163E: Unknown opcode SUM , expecting opcode or Macro
Program3.s(33): error: A1163E: Unknown opcode ARRAY , expecting opcode or Macro
Program3.s(34): error: A1163E: Unknown opcode LENGTH , expecting opcode or Macro
".ObjectsProgram2.axf" - 10 Error(s), 0 Warning(s).
Target not created.

I believe my compiler, Keil uVision 5, along with the flavor of assembly we are using, is the reason it will not compile. I was wondering if there is another way to go about programming this that aligns with the version I use?

Here is the code that will not compile:

SUB r2, r2, #1

MOV r6, #0

FOR_INIT MOV r1, #0

ADR r3, ARRAY

FOR_CMP CMP r1, r2

BGT END_FOR

LDR r4, [3], #4

n ARRAY

ADD r6, r6, r4

ADD r1, r1, #1

B FOR_CMP

END_FOR

STR r6, SUM

STOP B STOP

AREA SUMARRAY, DATA, READWRITE

ALIGN

SUM DCB 0xFFFFFFFF

ARRAY 5,10,15,20,30,40,50

LENGTH DCB 7

END

Explanation / Answer

SourceCode:

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote