Write an Assembly Language program to add two 32-bit numbers given from memory and store the sum.
Program:-
AREA PROGRAM,CODE,READONLY
ENTRY
LDR R0,=NUM1
LDR R1,=NUM2
LDR R2,=RESULT
LDR R3,[R0]
LDR R4,[R1]
ADD R5,R3,R4
STR R5,[R2]
STOP B STOP
NUM1 DCD 0x11223344
NUM2 DCD 0x55667788
AREA INFO,DATA,READWRITE
RESULT DCD 0x00000000
END
Explanation:-
This ARM assembly code appears to perform some simple operations, including loading values from memory, adding them together, and storing the result back in memory. Let’s break down the code step by step:
AREA PROGRAM,CODE,READONLY ENTRY
- This section defines the program area as read-only code and specifies the entry point of the program.
LDR R0,=NUM1 LDR R1,=NUM2 LDR R2,=RESULT
- These instructions load the addresses of
NUM1,NUM2, andRESULTinto registersR0,R1, andR2, respectively. This allows you to access these data values in memory.
LDR R3,[R0] LDR R4,[R1]
- These instructions load the values from memory addresses pointed to by
R0andR1into registersR3andR4, respectively.
ADD R5,R3,R4
- This instruction adds the values in registers
R3andR4together and stores the result in registerR5.
STR R5,[R2]
- This instruction stores the value in register
R5into the memory location pointed to byR2, which isRESULT.
STOP B STOP
- This is an infinite loop that serves as the program’s halt condition. It branches (jumps) to itself, effectively causing the program to stop here.
NUM1 DCD 0x11223344 NUM2 DCD 0x55667788
- These lines define two 32-bit data values,
NUM1andNUM2, with specific hexadecimal values.
AREA INFO,DATA,READWRITE RESULT DCD 0x00000000
- This section defines another area for data, specifying that it’s read-write. It defines a 32-bit data value
RESULTwith an initial value of0x00000000.
END
- This marks the end of the program.
In summary, this ARM assembly code loads two values (NUM1 and NUM2) from memory, adds them together, and stores the result in RESULT. The program then enters an infinite loop, effectively stopping execution.
