Microcontroller Module-2 Notes
Microcontroller Module-2 Notes
MICROCONTROLLER
BCS402-Notes
Contents
MODULE-2
INTRODUCTION TO THE ARM INSTUCTION SET
Instruction Format:
Label - Labels are symbols representing the addresses in memory of instructions or data.
MNEMONIC - Short name (mnemonic) of the instruction.
{S} - An optional suffix, If S is specified; the condition flags are updated on the result of the
operation.
{condition} - Condition that is needed to be met in order for the instruction to be executed.
{Rd} - Register (destination) for storing the result of the instruction
Operand1 - First operand, either a register or an immediate value
Operand2 - Second (flexible) operand, Can be an immediate value (number) or a register with an
optional shift.
MAC Unit:
• Multiply Accumulate operation is that computes the product of two numbers and adds
that product to an accumulator.
• The hardware unit that performs the operation is known as a multiplier–
accumulator (MAC, or MAC unit)
• The MAC operation modifies an accumulator, Rd Rn + (Rm x Rs)
• MAC operation is widely used in convolution.
Example:
Pre R4=0x0000 0001
R3=0x0000 0002
R2=0x0000 0002
R1=0x0000 0002
MLA R4, R3, R2, R1
Post R4=0x0000 0006
R3=0x0000 0002
R2=0x0000 0002
R1=0x0000 0002
R4 R1 + (R3 x R2)
Barrel Shifter:
• A unique and powerful feature of ARM Processor is that, it has in built barrel shifter used
to shifts or rotates (preprocessing) the 32 bit binary pattern in one of the source operand
register Rm left or right by a specific number of positions before it enters the ALU.
• Shifts increases the power and flexibility of data processing operations.
• The preprocessing or shift occurs in one cycle time of execution.
• It is useful to achieve fast multiplication or division by a power of 2.
1. Move Instructions:
• It is used to copies data from source operand registers or a immediate constant 32 bit
value to destination operand register.
Syntax:<Instruction>{<cond>}{S} Rd, N
1. MOV
• MOV (Move), copies a value into the destination register.
• The value can be either an immediate value or a value from a register, and can be shifted
before the write.
• MOV can optionally update the condition code flags, based on the result.
Syntax:
MOV{<cond>}{S} <Rd>, N
Rd N
Where, N can be an immediate value (number) or a register with an optional shift.
Ex_1:
PRE r5 = 5
r7 = 8
MOV r7, r5 ; r7 = r5
POST r5 = 5
r7 = 5
Ex_2:
PRE cpsr = nzcvqiFt_USER
r0 = 0x00000000
r1 = 0x80000004
2. MVN
• MVN (Move Not) generates the logical one’s complement of a value and places result in
Rd.
• The value can be either an immediate value or a value from a register, and can be shifted
before the MVN operation.
• MVN can optionally update the condition code flags, based on the result.
Syntax:
MVN{<cond>}{S} <Rd>, N
Rd Not ( N )
Ex_1: PRE r5 = 5
r7 = 8
MVN r7, r5 ; r5= 0000 0000 0000 0000 0000 0000 0000 0101
POST r5 = 5 ; ~r5= 1111 1111 1111 1111 1111 1111 1111 1010
r7 = 0xFFFFFFFA ; (0xFFFFFFFA)
2. Arithmetic Instructions:
• The arithmetic instructions implement addition and subtraction of 32-bit signed and
unsigned values.
Syntax:
<instruction>{<cond>}{S} Rd, Rn, N
ADC:
• ADC (Add with Carry), adds two values and the Carry flag.
• The first value comes from a register.
• The second value can be either an immediate value or a value from a register, and can be
shifted before the addition.
• ADC can optionally update the condition code flags, based on the result.
Syntax:-
ADC{<cond>}{S} Rd, Rn , N
Rd →Rn + N
Example_1: PRE R0 = 0x0000 0005
R2 = 0x0000 0008
R4 = 0x0000 0000
ADD R4,R0,R2
POST R0 = 0x0000 0005
R2 = 0x0000 0008
R4 = 0x0000 000D
ADD
• ADD, adds two 32 bit values.
• The first value comes from a register.
• The second value can be either an immediate value or a value from a register, and can be
shifted before the addition.
• ADD can optionally update the condition code flags, based on the result.
Syntax:
ADD{<cond>}{S} Rd, Rn, N
SUB
• SUB (Subtract) subtracts one value from a first value.
• The first value comes from a register.
• The second value can be either an immediate value or a value from a register, and can be
shifted before the subtraction.
• SUB can optionally update the condition code flags, based on the result.
Syntax:
SUB{<cond>}{S} <Rd>, <Rn>, N
SBC
• SBC (Subtract with Carry), subtracts the value of its second operand and the value of
NOT(Carry flag) from the value of its first operand.
• The first operand comes from a register.
• The second operand can be either an immediate value or a value from a register, and can
be shifted before the subtraction.
• Use SBC to synthesize multi-word subtraction.
• SBC can optionally update the condition code flags, based on the result.
Syntax:
SBC{<cond>}{S} <Rd>, <Rn>, N
RSB
RSC
• RSC (Reverse Subtract with Carry) subtracts a value from a second value, and the value
of NOT(Carry flag) from the value of its second operand.
• The normal order of the operands is reversed, to allow subtraction from a shifted register
value, or from an immediate value.
• RSC can optionally update the condition code flags, based on the result.
Syntax:
RSC{<cond>}{S} <Rd>, <Rn>, N
Logical Instructions:
• Logical instructions perform bitwise logical operations on the two source registers.
Syntax: <instruction>{<cond>}{S} Rd, Rn, N
1. AND
• AND performs a bitwise AND of two values.
• The first value comes from a register.
• The second value can be either an immediate value or a value from a register, and can be
shifted before the AND operation.
• AND can optionally update the condition code flags, based on the result.
Syntax:
AND{<cond>}{S} <Rd>, <Rn>, N
2. ORR
• ORR (Logical OR) performs a bitwise (inclusive) OR of two values.
• The first value comes from a register.
• The second value can be either an immediate value or a value from a register, and can be
shifted before the OR operation.
• ORR can optionally update the condition code flags, based on the result.
Syntax:
ORR{<cond>}{S} <Rd>, <Rn>, N
3. EOR
• EOR (Exclusive OR) performs a bitwise Exclusive-OR of two values.
• The first value comes from a register.
• The second value can be either an immediate value or a value from a register, and can be
shifted before the exclusive OR operation.
• EOR can optionally update the condition code flags, based on the result.
Syntax:
EOR{<cond>}{S} <Rd>, <Rn>, N
4. BIC
• BIC (Bit Clear) performs a bitwise AND of one value with the complement of a second
value.
• The first value comes from a register.
• The second value can be either an immediate value or a value from a register, and can be
shifted before the BIC operation.
• BIC can optionally update the condition code flags, based on the result.
Syntax:
BIC{<cond>}{S} <Rd>, <Rn>, N
Compare Instructions:
• The comparison instructions are used to compare or test a register with a 32-bit value.
• They update the cpsr flag bits according to the result, but do not affect other registers.
1. CMP
• CMP (Compare) compares two values.
• The first value comes from a register.
• The second value can be either an immediate value or a value from a register, and can be
shifted before the comparison.
• CMP updates the condition flags, based on the result of subtracting the second value from
the first.
Syntax:
CMP{<cond>} <Rn>, N
2. CMN
• CMN (Compare Negative) compares one value with the twos complement of a second
value.
• The first value comes from a register.
• The second value can be either an immediate value or a value from a register, and can be
shifted before the comparison.
• CMN updates the condition flags, based on the result of adding the two values.
Syntax:
CMN{<cond>} Rn, N
3. TEQ
• TEQ (Test Equivalence) compares a register value with another arithmetic value.
• The condition flags are updated, based on the result of logically exclusive-ORing the two
values, so that subsequent instructions can be conditionally executed.
Syntax:
TEQ{<cond>} <Rn>, N
4. TST
• TST (Test) compares a register value with another arithmetic value.
• The condition flags are updated, based on the result of logically ANDing the two values,
so that subsequent instructions can be conditionally executed.
Syntax:
TST{<cond>} <Rn>, N
Multiple Instructions:
• The multiply instructions multiply the contents of a pair of registers and, depending upon
the instruction, accumulate the results in with another register.
• The long multiplies accumulate onto a pair of registers representing a 64-bit value. The
final result is placed in a destination register or a pair of registers.
Syntax:
MLA{<cond>}{S} Rd, Rm, Rs, Rn
MUL{<cond>}{S} Rd, Rm, Rs
<Long_instruction>{<cond>}{S} RdLo, RdHi, Rm, Rs
Types:
1. MUL
• MUL (Multiply) multiplies two signed or unsigned 32-bit values.
• The least significant 32 bits of the result are written to the destination register.
• MUL can optionally update the condition code flags, based on the result.
Syntax:
MUL{<cond>}{S} <Rd>, <Rm>, <Rs>
where
<Rd> - Specifies the destination register for the instruction.
<Rm> - Specifies the register that contains the first value to be multiplied.
<Rs> - Holds the value to be multiplied with the value of <Rm>.
2. MLA
• MLA (Multiply Accumulate) multiplies two signed or unsigned 32-bit values, and adds a
third 32-bit value.
• The least significant 32 bits of the result are written to the destination register.
• MLA can optionally update the condition code flags, based on the result.
Syntax:
MLA{<cond>}{S} <Rd>, <Rm>, <Rs>, <Rn>
Where,
<Rd> - Specifies the destination register.
<Rm> - Holds the value to be multiplied with the value of <Rs>.
<Rs> - Holds the value to be multiplied with the value of <Rm>.
<Rn> - Contains the value that is added to the product of <Rs> and <Rm>.
SMULL
• SMULL (Signed Multiply Long) multiplies two 32-bit signed values to produce a 64-bit
result.
• SMULL can optionally update the condition code flags, based on the 64-bit result.
Syntax:
SMULL{<cond>}{S} <RdLo>, <RdHi>, <Rm>, <Rs>
Where,
<RdLo> - Stores the lower 32 bits of the result.
<RdHi> - Stores the upper 32 bits of the result.
<Rm> - Holds the signed value to be multiplied with the value of <Rs>.
<Rs> - Holds the signed value to be multiplied with the value of <Rm>.
SMLAL
• SMLAL (Signed Multiply Accumulate Long) multiplies two signed 32-bit values to
produce a 64-bit value, and accumulates this with a 64-bit value.
• SMLAL can optionally update the condition code flags, based on the result.
Syntax:
SMLAL{<cond>}{S} <RdLo>, <RdHi>, <Rm>, <Rs>
Where,
<RdLo> - Stores the lower 32 bits of the result.
<RdHi> - Stores the upper 32 bits of the result.
<Rm> - Holds the signed value to be multiplied with the value of <Rs>.
<Rs> - Holds the signed value to be multiplied with the value of <Rm>.
UMLAL
• UMLAL (Unsigned Multiply Accumulate Long) multiplies the unsigned value of register
<Rm> with the unsigned value of register <Rs> to produce a 64-bit product.
• This product is added to the 64-bit value held in <RdHi> and <RdLo>, and the sum is
written back to <RdHi> and <RdLo>.
• The condition code flags are optionally updated, based on the result.
Syntax:
UMLAL{<cond>}{S} <RdLo>, <RdHi>, <Rm>, <Rs>
Where,
<RdLo> - Stores the lower 32 bits of the result.
<RdHi> - Stores the upper 32 bits of the result.
<Rm> - Holds the signed value to be multiplied with the value of <Rs>.
<Rs> - Holds the signed value to be multiplied with the value of <Rm>.
UMULL
• UMULL (Unsigned Multiply Long) multiplies the unsigned value of register <Rm> with
the unsigned value of register <Rs> to produce a 64-bit result.
• The upper 32 bits of the result are stored in <RdHi>.
• The lower 32 bits are stored in <RdLo>.
• The condition code flags are optionally updated, based on the 64-bit result.
Syntax
UMULL{<cond>}{S} <RdLo>, <RdHi>, <Rm>, <Rs>
Where,
<RdLo> - Stores the lower 32 bits of the result.
<RdHi> - Stores the upper 32 bits of the result.
<Rm> - Holds the signed value to be multiplied with the value of <Rs>.
<Rs> - Holds the signed value to be multiplied with the value of <Rm>.
Example 1:
PRE r0 = 0x00000000
r1 = 0x00000002
r2 = 0x00000002
MUL r0, r1, r2 ; r0 = r1*r2
POST r0 = 0x00000004
r1 = 0x00000002
r2 = 0x00000002
Example 2:
PRE r0 = 0x00000000
r1 = 0x00000000
r2 = 0xf0000002
r3 = 0x00000002
UMULL r0, r1, r2, r3 ; [r1,r0] = r2*r3
POST r0 = 0xe0000004 ; = RdLo
r1 = 0x00000001 ; = RdHi
Branch Instructions:
• These control flow of execution include the various forms of PC-
relative branch and branch-and-link instruction seen in the ARM
instruction set, and
• Branch-and-exchange instruction for switching between the ARM and
Thumb instruction sets.
Syntax: B{<cond>} label
BL{<cond>} label
BX{<cond>} Rm
BLX{<cond>} label | Rm
Types
1. B branch pc = label
1. B
• B (Branch), causes a branch to a target address, and provide both conditional and
unconditional changes to program flow.
Syntax:
B{<cond>} <target_address>
2. BL
• BL (Branch and Link) cause a branch to a target address, and provide both conditional
and unconditional changes to program flow.
• BL also stores a return address in the link register, R14 (also known as LR).
Syntax:
BL{<cond>} <target_address>
3. BX:
• BX (Branch and Exchange) branches to an address, with an optional switch to Thumb
state.
Syntax:
BX{<cond>} <Rm>
<Rm> - Holds the value of the branch target address. Bit[0] of Rm is 0 to select a target ARM
instruction, or 1 to select a target Thumb instruction
4. BLX
• BLX, (Branch with Link and Exchange) calls a Thumb subroutine from the ARM
instruction set at an address specified in the instruction.
• Execution of Thumb instructions begins at the target address.
• After completion of execution it return from the subroutine, use a BX R14 instruction, or
store R14 on the stack and reload the stored value into the PC.
Syntax
BLX{<cond>} <target_addr> | Rm
Example 1:
B forward
ADD r1, r2, #4
ADD r0, r6, #2
ADD r3, r7, #4
forward
SUB r1, r2, #4
Backward
ADD r1, r2, #4
SUB r1, r2, #4
ADD r4, r6, r7
B backward
Example 2:
BL subroutine ; branch to subroutine
CMP r1, #5 ; compare r1 with 5
MOVEQ r1, #0 ; if (r1==5) then r1 = 0
:
subroutine
<subroutine code>
MOV pc, lr ; return by moving pc = lr
1. LDR
• LDR (Load Register) loads a word from a memory address.
• If the PC is specified as register <Rd>, the instruction loads a data word which it treats as
an address, then branches to that address.
Syntax:
LDR{<cond>} <Rd> , <addressing_mode>
where:
<Rd> Specifies the destination register for the loaded value.
2. LDRB
• LDRB (Load Register Byte) loads a byte from memory and zero-extends the byte to a 32-
bit word.
Syntax:
LDR{<cond>}B <Rd>, <addressing_mode>
3. LDRH
• LDRH (Load Register Halfword) loads a halfword from memory and zero-extends it to a
32-bit word.
Syntax:
LDR{<cond>}H <Rd>, <addressing_mode>
4. LDRSB
• LDRSB (Load Register Signed Byte) loads a byte from memory and sign-extends the
byte to a 32-bit word.
Syntax:
LDR{<cond>}SB <Rd>, <addressing_mode>
5. LDRSH
• LDRSH (Load Register Signed Halfword) loads a halfword from memory and sign-
extends the halfword to a 32-bit word.
• If the address is not halfword-aligned, the result is UNPREDICTABLE.
Syntax:
LDR{<cond>}SH <Rd>, <addressing_mode>
6. STR
• STR (Store Register) stores a word from a register to memory.
Syntax:
STR{<cond>} <Rd>, <addressing_mode>
7. STRB
• STRB (Store Register Byte) stores a byte from the least significant byte of a register to
memory.
Syntax:
STR{<cond>}B <Rd>, <addressing_mode>
8. STRH
• STRH (Store Register Halfword) stores a halfword from the least significant halfword of
a register to memory.
• If the address is not halfword-aligned, the result is UNPREDICTABLE.
Syntax:
STR{<cond>}H <Rd>, <addressing_mode>
Example:
;load register r0 with the contents of the memory address pointed to by register r1.
; store the contents of register r0 to ; the memory address pointed to by register r1.
Types:
1. LDM load multiple registers {Rd}*N mem32[start address + 4*N] optional Rn updated
2. STM save multiple registers {Rd}*N → mem32[start address + 4*N] optional Rn updated
LDM
• LDM (Load Multiple), loads a non-empty subset, or possibly all, of the general-purpose
registers from sequential memory locations.
• It is useful for block loads, stack operations and procedure exit sequences.
• The general-purpose registers loaded can include the PC.
Syntax:
LDM{<cond>}<addressing_mode> <Rn>{!}, <registers>
STM
• STM (Store Multiple), stores a non-empty subset (or possibly all) of the general-purpose
registers to sequential memory locations.
Syntax:
STM{<cond>}<addressing_mode> <Rn>{!}, <registers>
STM
• STM stores a subset (or possibly all) of the User mode general-purpose registers to
sequential memory locations.
Syntax:
STM{<cond>}<addressing_mode> <Rn>, <registers>^
Where,
^ - For an STM instruction, indicates that User mode registers are to be stored.
Example 1:
PRE mem32[0x80010] = 0x01r0
= 0x00080010
r1 = 0x00000000
r2 = 0x00000000
r3 = 0x00000000
LDMIA r0!, {r1-r3}
POST r0 = 0x0008001c
r1 = 0x00000001
r2 = 0x00000002
r3 = 0x00000003
Example 2:
PRE r0 = 0x0000900c
r1 = 0x00000001
r2 = 0x00000002
r3 = 0x00000003
STMIB r0!, {r1-r3}
POST
Example 3:
PRE r0 = 0x0000900c
r1 = 0x00000001
r2 = 0x00000002
r3 = 0x00000003
0x00009000 0x00000007
0x00009004 0x00000009
0x00009008 0x00000008
0x0000900c 0x00000007
Example:
PRE r1 = 0x00000002
r4 = 0x00000003
sp = 0x00080014
STMFD sp!, {r1,r4}
POST r1 = 0x00000002
r4 = 0x00000003
sp = 0x0008000c
Swap Instructions:
• Swap instructions combine a load and a store of a word or an
unsigned byte in a single instruction.
• These instructions allow a value in a register to be exchanged with a
value in memory.
• Their principal use is to implement semaphores to ensure mutual
exclusion.
SWP
• SWP (Swap) swaps a word between registers and memory.
• SWP loads a word from the memory address given by the value of register <Rn>. The
value of register <Rm> is then stored to the memory address given by the value of <Rn>,
and the original loaded value is written to register <Rd>.
• If the same register is specified for <Rd> and <Rm>, this instruction swaps the value of
the register and the value at the memory address.
Syntax:
SWP{<cond>} <Rd>, <Rm>, [<Rn>]
Where,
<Rd> - Specifies the destination register for the instruction.
<Rm> - Contains the value that is stored to memory.
<Rn> - Contains the memory address to load from.
Example:
SWP r1, r1, [r0] ; exchange 32 bit value
SWPB
• SWPB (Swap Byte), swaps a byte between registers and memory.
• SWPB loads a byte from the memory address given by the value of register <Rn>.
• The value of the least significant byte of register <Rm> is stored to the memory address
given by <Rn>, the original loaded value is zero-extended to a 32-bit word, and the word
is written to register <Rd>.
• If the same register is specified for <Rd> and <Rm>, this instruction swaps the value of
the least significant byte of the register and the byte value at the memory address.
Syntax:
SWP{<cond>}B <Rd>, <Rm>, [<Rn>]
Where,
<Rd> - Specifies the destination register for the instruction.
<Rm> - Contains the value that is stored to memory.
<Rn> - Contains the memory address to load from.
Example:
SWPB r1, r1, [r0] ; exchange byte
Software Instructions:
• A software interrupt instruction (SWI) causes a software interrupt exception, which force
the processor into supervisor mode.(privileged mode).
• Each SWI has an associated SWI Number which is used to represent a particular function
call.
• ARM exception entry sequence. In detail, the processor actions are:
1. Save the address of the instruction after the SWI in r14_svc.
2. Save the CPSR in SPSR_svc.
3. Enter supervisor mode and disable IRQs (but not FIQs) by setting
CPSR[4:0] to
100112andCPSR[7]tol.
4. Set the PC to 08 and begin executing the instructions there.
5. A special form of data processing instruction used to return to the
instruction after the SWI the system routine must not only copy
r14_svc back into the PC, but it must also restore the CPSR from
SPSR_svc.
Syntax:
SWI{<cond>} SWI_number
Where,
SWI_number - Is a 24-bit immediate value that is put into bits[23:0] of the instruction.
Example:
PRE
cpsr = nzcVqift_USER
pc = 0x00008000
lr = 0x003fffff; lr = r14
r0 = 0x12
0x00008000 SWI 0x123456 ; used by ARM toolkits as a debugging SWI
POST
cpsr = nzcVqIft_SVC
spsr = nzcVqift_USER
pc = 0x00000008
lr = 0x00008004
r0 = 0x12
Note: SWI number using the address of the executed instruction, which is calculated from
the link register lr. The SWI number is determined by,
SWI_Number = <SWI instruction> AND NOT(0xff000000).
Example:
• ARM has two instructions for moving the contents of a program status register to or from
a general-purpose register.
• Both the CPSR and SPSR can be accessed.
1. MRS
• MRS (Move PSR to general-purpose register) moves the value of the CPSR or the SPSR
of the current mode into a general-purpose register.
• In the general-purpose register, the value can be examined or manipulated with normal
data-processing instructions.
Syntax:
MRS{<cond>} <Rd>, CPSR
MRS{<cond>} <Rd>, SPSR
Where
<Rd> specifies the destination register.
Note:If R15 is specified for <Rd>, the result is UNPREDICTABLE.
2. MSR
• MSR (Move to Status Register from ARM Register) transfers the value of a general-
purpose register or an immediate constant to the CPSR or the SPSR of the current mode.
Syntax:
MSR{<cond>} CPSR_<fields>, #<immediate>
MSR{<cond>} CPSR_<fields>, <Rm>
MSR{<cond>} SPSR_<fields>, #<immediate>
MSR{<cond>} SPSR_<fields>, <Rm>
Where,
<fields> - These fields relate to particular byte regions in a psr register,
c sets the control field mask bit (bit 16)
x sets the extension field mask bit (bit 17)
s sets the status field mask bit (bit 18)
f sets the flags field mask bit (bit 19).
<immediate> -Is the immediate value to be transferred to the CPSR or SPSR.
<Rm> Is the general-purpose register to be transferred to the CPSR or SPSR.
Example 1:
MRS R0, CPSR ; Read the CPSR
BIC R0, R0, #0xF0000000 ; Clear the N, Z, C and V bits
MSR CPSR_f, R0 ; Update the flag bits in the CPSR
; N, Z, C and V flags now all clear
Example 2:
PRE
cpsr = nzcvqIFt_SVC
MRS r1, cpsr ; The MSR first copies the cpsr into register r1
BIC r1, r1, #0x80 ; 0b01000000 (The BIC instruction clears bit 7 of r1)
MSR cpsr_c, r1 ; Register r1 is then copied back into the cpsr
; enables IRQ interrupts
POST
i
cpsr = nzcvq Ft_SVC
Indexed Addressing:
▪ The offset address is added to the value in Rn before the transfers take place.
▪ The result is used as the memory address for the transfers.
▪ The base address Rn is not updated with new value.
Example:
PRE r0 = 0x00000000
r1 = 0x00090000
mem32[0x00009000] = 0x01010101
mem32[0x00009004] = 0x02020202
LDR r0, [r1, #4]
POST r0 = 0x02020202
r1 = 0x00009000
Exmple_2:
LDR R0, [R1],#4 ; R0 value at [R1], R1 R1+4
LDR R0, [R1],R2 ; R0 value at [R1], R1 R1+R2
3. Post-indexed offset
▪ The value in Rn is used as the memory address for the transfer.
▪ The offset is applied to the value in Rn after the transfer takes place.
▪ The result is written back into Rn.
Example:
Postindexing:
PRE r0 = 0x00000000
r1 = 0x00090000
mem32[0x00009000] = 0x01010101
mem32[0x00009004] = 0x02020202
POST r0 = 0x01010101
r1 =0x00009004
Example_2:
LDR R0, [R1],#4 ; R0 value at [R1], R1 R1+4
LDR R0, [R1],R2 ; R0 value at [R1], R1 R1+R2
Distinguish between post & pre indexed addressing mode with an example
Pre-indexing Post-indexing
Pre-indexing involves direct addressing and Post-indexing also uses direct addressing and
indexing indexing
Indexing is performed before indirection Indexing is performed after indirection
Base register contains memory address Memory address is base register value.
Base register value can be updated by
Offset can be added or subtracted using base
incrementing or decrementing the offset value (i.e.
updated base register). register value (i.e. updated base register).
Sum of base address plus offset yields effective Base address stored in base register is used
address. directly as effective address
Result is stored in updated base register Result is stored in original base register
Example:
return_address ; resume
• Call the function pointed to by r9. We use ADR to
• Set lr to the return address;
• In this case, it will assemble to ADD lr, pc, #4.
• Recall that pc reads as the address of the current instruction plus eight in this case.
Endianness:
• A memory system uses one of the two following mapping schemes.
1. Little-endian memory system:
• A byte or halfword at a word-aligned address is the least significant byte or
halfwordwithin the word at that address.
• A byte at a halfword-aligned address is the least significant byte within the
halfword atthat address.
Example:
0x12345678
0x0000 78(LSB)
0x0004 56
0x0008 34
0x000C 12(MSB)
register r0