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:
Line | Description |
---|---|
MOV R0, #1 | Start counting from 1 |
MOV R1, #0 | Initialize sum = 0 |
ADD R1, R1, R0 | Add current number to sum |
ADD R0, R0, #1 | Move to next number |
CMP R0, #11 | Check if R0 reached 11 (loop ends at 10) |
BNE LOOP | If not equal, go back to loop |
B STOP | End 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 be55 (0x37)
.