Assembly Program to add two 32-bit numbers given from memory and store the sum.

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, and RESULT into registers R0, R1, and R2, 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 R0 and R1 into registers R3 and R4, respectively.
ADD R5,R3,R4
  • This instruction adds the values in registers R3 and R4 together and stores the result in register R5.
STR R5,[R2]
  • This instruction stores the value in register R5 into the memory location pointed to by R2, which is RESULT.
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, NUM1 and NUM2, 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 RESULT with an initial value of 0x00000000.
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.

Leave a Reply

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