DCD, LDR
DCD, LDR
Here b here
A dcb 0x25
end
Addressing modes
• The CPU can access operands (data) in various
ways, called addressing modes.
• The number of addressing modes is determined
when the microprocessor is designed and
cannot be changed.
• Some of the simple ARM addressing modes are
– Register
– Immediate
– Memory addressing
• register indirect (indexed addressing mode)
Register addressing mode
• The register addressing mode involves the use of
registers to hold the data to be manipulated.
• Memory is not accessed when this addressing
mode is executed; therefore, it is relatively fast.
• Examples
MOV R6,R2 ;copy the contents of R2 into R6
ADD R1,R1,R3 ;add the contents of R3 to
contents of R1
SUB R7,R7,R2 ;subtract R2 from R7
Immediate addressing mode
• In the immediate addressing mode, the source
operand is a constant.
• In immediate addressing mode, as the name implies,
when the instruction is assembled, the operand
comes immediately after the opcode. For this reason,
this addressing mode executes quickly.
• Examples
MOV R9,#0x25 ;move 0x25 into R9
MOV R3,#62 ;load the decimal value 62 into R3
ADD R6,R6,#0x40 ; add 0x40 to R6
Memory addressing mode
• In the first two addressing modes, the operands
are either inside the microprocessor or tagged
along with the instruction.
• In most programs, the data to be processed is
often in some memory location outside the
CPU. There are many ways of accessing the data
in the data memory space.
• The ARM supports Register indirect or indexed
addressing mode
Register Indirect Addressing Mode (Indexed
addressing mode)
• Register indirect addressing means that the location
of an operand is held in a register.
• It is also called indexed addressing or base
addressing.
• Example
STR R5,[R6] ;move R5 into the memory location
;pointed to by R6
LDR R10,[R3] ;move into R10 the contents of the
;memory location pointed to by R3.
Register Indirect Addressing with an Offset
• ARM supports a memory-addressing mode
where the effective address of an operand is
computed by adding the content of a register
and a literal offset coded into load/store
instruction.
• This offset can be specified in one of three
ways
– Immediate
– Register
– Scaled register
Immediate offset
• The offset is an unsigned integer that is stored as part of
the instruction.
• It can be added to or subtracted from the value in the
base register.
• If a label is used to specify the address, the assembler uses
the pc as the base register and computes the appropriate
offset.
• If no offset is specified an immediate constant value of
zero is assumed.
• Example
LDR R0, [R1] ; Zero offset
LDR R0, [R1, #4] ; R1=R1+4 offset with value 4
Register offset
• The offset is an unsigned integer that is in a
register other than the pc.
• It can be added to or subtracted from the value in
the base register.
• Example
LDR R1,=0x40000000
MOV R2,#0x4
LDR R0, [R1, R2] ;R1=R1+R2=0x40000004
Scaled Register Offset
• The offset is an unsigned integer that is in a
register other than the pc.
• It is shifted by an immediate amount before it
is added to or subtracted from the value in the
base register.
• Example
LDR R0, [R1, R2, LSL #2]
• These addressing modes can affect the offset
value in the base register in three different
ways
– Pre-index addressing (LDR R0, [R1, #4]!)
• Pre-index with write back
• calculation before accessing with a write back
– Auto-indexing addressing (LDR R0, [R1, #4])
• Without a write back
– Post-index addressing (LDR R0, [R1], #4)
• Calculation after accessing with a write back
Pre-index addressing
• The offset is combined with the value in the
base register, and the base register is updated
with this new address before being used to
access memory.
– Immediate Pre-indexed
• Ex: LDR R0, [R1, #4]!
– Register Pre-indexed
• Ex: LDR R0, [R1, R2]!
– Scaled Register Pre-indexed
• Ex: LDR R0, [R1, R2, LSL #2]!
Auto-indexing addressing
– Immediate Pre-indexed
• Ex: LDR R0, [R1, #4]
– Register Pre-indexed
• Ex: LDR R0, [R1, R2]
– Scaled Register Pre-indexed
• Ex: LDR R0, [R1, R2, LSL #2]
Post-Index Addressing
– Immediate Post-indexed
• LDR R0, [R1], #4
– Register Post-indexed
• LDR R0, [R1], R2
– Scaled Register Post-indexed
• LDR R0, [R1], R2, LSL #2