ARM processor is used in all the Embedded systems that are being built now. Here I explain ARM assembly program to add numbers declared in an array.
ALGORITHM:
- Start
- Create an array of numbers
- Initialize a counter register to the number of elements in an array
- Load base address of an array to a register.
- Load value to a temporary register
- Add and store number in destination register
- Decrement counter value
- Repeat steps 5-7 till counter value becomes zero
- Stop.
Here is a example code to add numbers in array with 5 elements.
CODE:
AREA program,CODE,READONLY
ENTRY
MOV R0,#5 ; Initializing counter register
LDR R1,=array ; Loading base address to a register
loop LDR R2,[R1],#4 ; Loading value from array and updating(increment) the address
ADD R3,R3,R2 ; Sum is stored in R3 register
SUB R0,R0,#1 ; Decrementing counter value
CMP R0,#00 ; Checking counter value
BNE loop
array DCD 0x00000001,0x000000AF,0x00000002,0x00000DC,0x000001FB
END