- ARM

ARM code: Assembly code to add numbers from array

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:

  1. Start
  2. Create an array of numbers
  3. Initialize a counter register to the number of elements in an array
  4. Load base address of an array to a register.
  5. Load value to a temporary register
  6. Add and store number in destination register
  7. Decrement counter value
  8. Repeat steps 5-7 till counter value becomes zero
  9. 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

Leave a Reply