Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 ".\Objects\Program2.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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions