Calculate 1 + 2 + 3 + … + 10 = 55 using ARM assembly

ARM Assembly Code (using ARM syntax):

        AREA SumProgram, CODE, READONLY     ; Define a code section
ENTRY ; Mark the entry point of the program

START MOV R0, #1 ; R0 = current number to add (start at 1)
MOV R1, #0 ; R1 = accumulator (sum), initially 0

LOOP ADD R1, R1, R0 ; R1 = R1 + R0
ADD R0, R0, #1 ; R0 = R0 + 1
CMP R0, #11 ; Compare R0 with 11 (end condition)
BNE LOOP ; If not equal to 11, repeat loop

STOP B STOP ; Infinite loop to stop execution

END ; Mark the end of this file

Explanation:

LineDescription
MOV R0, #1Start counting from 1
MOV R1, #0Initialize sum = 0
ADD R1, R1, R0Add current number to sum
ADD R0, R0, #1Move to next number
CMP R0, #11Check if R0 reached 11 (loop ends at 10)
BNE LOOPIf not equal, go back to loop
B STOPEnd the program

Final Output:

At the end of the loop:

  • R1 = 55 (sum of 1 to 10)

Test:

If you’re using an ARM emulator or toolchain like Keil uVision, QEMU, or ARMulator:

  • Load this program into the debugger.
  • After execution, check the value in R1 — it will be 55 (0x37).

Leave a Reply

Your email address will not be published. Required fields are marked *