Run-
Two terms frequently found in texts on computer architecture and assembly language
programming are run-
It is very important for programmers to be aware of these terms and their implications.
Consider the two assembly language operations:
1. ADD r0,r1,r2
2. MOV r3,#X+Y
These are two legal ARM instructions. The first instruction adds two registers together.
The second instruction moves the sum of two literals to a register. Both instructions
perform an addition. However, one addition takes place at run-
Let’s write these two instructions in ARM format and declare the literals X and Y using the equate statement. We get:
X EQU 1
Y EQU 2
ADD r0,r1,r2
MOV r3,#X+Y
After putting this code in an appropriate ARM environment (with the necessary start-
6: ADD r0,r1,r2
0x00000000 E0810002 ADD R0,R1,R2
7: MOV r3,#X+Y
0x00000004 E3A03003 MOV R3,#0x00000003
The additional operation, ADD r0,r1,r2, is translated into the appropriate op-
So, what’s the point of such an assemble-
However, operations that take place at assemble-
Assemble-
Consider the following three code fragments. The first in red, the second in blue and the third in black.
Fragment 1
Item EQU 4 ;Equate the name Item to the value 4
ADD r5,r5,#4 ;increment r5 by Item
Fragment 2
Item DCW 4 ;Store initial value for Item in memory
ADR r1,Item ;r1 points at Item in memory
LDR r2,[r1] ;r2 contains the value of Item
ADD r5,r5,r2 ;increment r5 by Item
Fragment 3
Item DSW 1 ;Reserve space for Item in memory
ADR r1,Item ;r1 points at Item in memory
MOV r0,#4 ;r0 contains the value of Item
STR r0,[r1] ;Store value of Item in memory
ADR r1,Item ;r1 points at Item in memory
LDR r2,[r1] ;r2 contains the value of Item
ADD r5,r5,r2 ;increment r5 by Item
Fragment 1 uses entirely run-
Now look at code fragment 2. This has the same effect as code fragment 1. However,
in this case Item is made a constant in memory. The value of this constant, 4, is
loaded at assemble-
Finally, consider code fragment 3. Here we use the assembler directive Item DSW 1
to reserve one word of storage for the variable Item. Note that we write DSW 1 because
we are creating one word of storage, whereas in Fragment 2 we wrote DCW 4 because
we were reserving a word of storage and pre-
The first three lines of code in Fragment 3 have the effect of loading the value
4 in the variable Item. This action takes place at run-
We have three fragments of code that do exactly the same thing; each adds 4 to the contents of register r5. The first fragment has one line of executable code, the second had three lines, and the third six lines. What’s the practical difference?
Code Fragment 1 does not use a memory location to store the value of Item. Instead,
it treats Item as a literal in an instruction. This is the most compact code. However,
the value of Item (the increment) cannot be modified without rewriting and re-
In the second fragment of code, we store the increment in memory. When we wish to
use it, we have to load it from memory. However, because the increment is stored
in memory, it can be changed at run-
However, we have to be aware of a hidden and potential problem. Because the value
of Item is initialized at run time by storing 4 in memory, if that value is modified
and we later re-
In the third fragment of code we also use a memory location for Item and we can also
change it at run-
Summary
Assemble-