Vous êtes sur la page 1sur 53

Course Title: Embedded System Design

Course No: EEE G512

CSIR-CEERI

The ARM Processor Architecture: Instruction formats


Kota Solomon Raju

B.E., M.E., Ph.D.

Principle Scientist
Reconfigurable Computing Systems Lab
&
Wireless Sensor Network Systems Lab
Digital Systems Group
CSIR - CENTRAL ELECTERONICS ENGINEERING RESEARCH INSTITUTE (CSIR - CEERI),
Pilani-333031, Rajasthan.

ARM
1 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 1

Addressing modes used with ARM instructions


CSIR-CEERI

Addressing Mode 1 - Data-processing operands (Immediate and Register, with and without shift)
Addressing Mode 2 - Load and Store Word or Unsigned Byte (Immediate offset, Register offset, Scaled

register offset, Immediate pre-indexed, Register pre-indexed, Scaled register pre-indexed, Immediate
post-indexed, Register post-indexed, Scaled register post-indexed)
Addressing Mode 3 - Miscellaneous Loads and Stores (Immediate offset, Register offset, Immediate pre-

indexed, Register pre-indexed, Immediate post-indexed, Register post-indexed)


Addressing Mode 4 - Load and Store Multiple
Load Multiple instructions load a subset (possibly all) of the general-purpose registers from memory.

Store Multiple instructions store a subset (possibly all) of the general-purpose registers to memory
Addressing Mode 5 - Load and Store Coprocessor (Immediate offset, Immediate pre-indexed, Immediate

post-indexed, Unindexed)

ARM
2 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 2

ARM Instruction set Architecture


CSIR-CEERI

The ARM instruction set can be divided into six broad

classes of instruction

Data-processing instructions

Branch instructions
Data-processing instructions

Arithmetic/logic instructions
Comparison instructions
Single Instruction Multiple Data (SIMD) instructions
Multiply instructions
Miscellaneous Data Processing instructions

Status register transfer instructions transfer the contents of

the CPSR or an SPSR to or from a general-purpose


register. Writing to the CPSR can:

Set the values of the condition code flags


Set the values of the interrupt enable bits
Set the processor mode and state
Alter the endianness of Load and Store operations.

Load and store instructions: Load a 64-bit doubleword, a

32-bit / 16-bit or an 8-bit from memory into a register (s)


Load and Store Register
Load and Store Multiple registers
Load and Store Register Exclusive
ARM
3 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

Coprocessor instructions
These start a coprocessor-specific internal
operation.
Data transfer instructions
These transfer coprocessor data to or from memory.
The address of the transfer is calculated by the
ARM processor.
Register transfer instructions
These allow a coprocessor value to be transferred
to or from an ARM register, or a pair of ARM
registers.

Exception-generating instructions
Software interrupt instructions

SWI instructions cause a software interrupt exception


to occur. These are normally used to make calls to an

operating system, to request an OS-defined


service. The exception entry caused by a SWI
instruction also changes to a privileged
processor mode.
Software breakpoint instructions
BKPT instructions cause an abort exception to
occur

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 3

ARM instructions: Shift and Rotate


CSIR-CEERI

Logical Shift Left (LSL):


Each bit of register shifted to the left as shown in Fig. 1
and a zero will placed in the least significant bit (LSB),
LSL logical shift by n bits multiplication by 2 n

Fig. 1. (a)

Logical Shift Right (LSR):


Each bit of register shifted to the right as shown in Fig. 2.
and a zero will placed in the most significant Bit (MSB)
LSL logical shift by n bits unsigned division by 2 n
Fig. 1. (b)

Fig. 2. (a)

Fig. 2. (a)
ARM
4 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 4

ARM instructions: Shift and Rotate


CSIR-CEERI

Arithmetic Shift Right (ASR):


In Arithmetic shift right the most significant bit does not
change and each bit shifted to the right as shown in Fig. 3
Arithmetic shift by n bits signed division by 2n

Fig. 3. (a)

Rotate Right (ROR):


Rotate Right: Figure 4 shows an eight bit register and Fig.
3.7shows the register
ROR logical rotate by n bits 32 bit rotate

Fig. 3. (b)

Fig. 4. (a)

Fig. 4. (b)
ARM
5 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 5

Addressing modes: Data-processing operands


CSIR-CEERI

Addressing Mode 1 - Data-processing operands (Immediate and Register, with and without shift)

There are 11 formats used to calculate the <shifter_operand> in an ARM data-processing instruction
The general instruction syntax is:
<opcode>{<cond>}{S} <Rd>, <Rn>, <shifter_operand>
Register

Immediate
where <shifter_operand> is one of the following:
1. #<immediate>
Data-processing operands - Immediate
2. <Rm>, LSL #<shift_imm>
Data-processing operands - Logical shift left by immediate
3. <Rm>, LSR #<shift_imm>
Data-processing operands - Logical shift right by immediate
5. <Rm>, ASR #<shift_imm>
Data-processing operands - Arithmetic shift right by immediate
6. <Rm>, ROR #<shift_imm>
Data-processing operands - Rotate right by immediate
7. <Rm>, RRX
Data-processing operands - Rotate right with extend
ARM
6 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

where <shifter_operand> is one of the following:


1. <Rm>
Data-processing operands - Register
2. <Rm>, LSL <Rs>
Data-processing operands - Logical shift left by register
3. <Rm>, LSR <Rs>
Data-processing operands - Logical shift right by register
4. <Rm>, ASR <Rs>
Data-processing operands - Arithmetic shift right by register
5. <Rm>, ROR <Rs>
Data-processing operands - Rotate right by register

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 6

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Immediate)

CSIR-CEERI

S bit Indicates that the instruction updates the condition codes.; Rd Specifies the destination register; Rn Specifies the first source
operand register.

The <shifter_operand> value is formed by rotating (to the right) an 8-bit immediate value to any
even bit position in a 32-bit word. If the rotate immediate is zero, the carry-out from the shifter is
the value of the C flag, otherwise, it is set to bit[31] of the value of <shifter_operand>.
Specifies the immediate constant wanted. It is encoded in the instruction as
an 8-bit immediate (immed_8) and a 4-bit immediate (rotate_imm), so that
<immediate> is equal to the result of rotating immed_8 right by (2
rotate_imm) bits <opcode>{<cond>}{S} <Rd>, <Rn>, <shifter_operand>
Immediate:
ADD r0, r1, #0xFF
With rotate-right
ADD r0,r1, #0xFF, 28
(Rotate value must be even: #0xFF ROR 28 generates:0XFF00000000)
ARM
7 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 7

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Immediate)

CSIR-CEERI

S bit Indicates that the instruction updates the condition codes.; Rd Specifies the destination register; Rn Specifies the first source
operand register.

ARM
8 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 8

Addressing modes: Data-processing operands (Contd.)


Examples of Creating Constants with Rotation

CSIR-CEERI

Calculate the rotation necessary to generate the constant 4080 using the byte rotation scheme.
solution:
Since 4080 is 111111110000, the byte 11111111 or 0xFF can be rotated to the left by four bits. However,
the rotation scheme rotates a byte to the right; therefore, a rotation factor of 28 is needed, since rotating to
the left n bits is equivalent to rotating to the right by (32-n) bits. The ARM instruction would be
MOV
ARM
9 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

r0, #0xFF, 28;


EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 9

Addressing modes: Data-processing operands (Contd.)


CSIR-CEERI

ARM
10 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 10

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Logical shift left by immediate)

CSIR-CEERI

Syntax
<Rm>, LSL #<shift_imm>; where: <Rm> Specifies the register whose value is to be shifted; LSL = a logical shift left.
<shift_imm> Specifies the shift. This is a value between 0 and 31.
Default shift If the value of <shift_imm> == 0, the operand can be written as just <Rm>

ARM
11 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 11

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Logical shift left by immediate)

ARM
12 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

CSIR-CEERI

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 12

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Logical shift right by immediate)

CSIR-CEERI

Syntax
<Rm>, LSR #<shift_imm>; where: <Rm> Specifies the register whose value is to be shifted; LSL = a logical shift
right.
<shift_imm> Specifies the shift. This is an immediate value between 1 and 32. (A shift by 32 is encoded by shift_imm
== 0.)

ARM
13 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 13

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Arithmetic shift right by immediate)

CSIR-CEERI

Syntax
<Rm>, ASR #<shift_imm>;
where: <Rm> Specifies the register whose value is to be shifted; ASR = arithmetic shift right
<shift_imm> Specifies the shift. This is an immediate value between 1 and 32. (A shift by 32 is encoded by shift_imm
== 0.)
Operation

ARM
14 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 14

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Rotate right by immediate)

CSIR-CEERI

Syntax
<Rm>, ROR #<shift_imm>;
where: <Rm> Specifies the register whose value is to be shifted; ROR = a rotate right
<shift_imm> Specifies the rotation. This is an immediate value between 1 and 31. When shift_imm == 0, an RRX
operation (rotate right with extend) is performed. This is described in Data-processing operands - Rotate right with
extend.
Operation

ARM
15 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 15

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Rotate right by immediate)

ARM
16 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

CSIR-CEERI

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 16

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Rotate right with extend)

CSIR-CEERI

Syntax
<Rm>, RRX ;
where: <Rm> Specifies the register whose value is shifted right by one bit; RRX = a rotate right with extend
Operation

ARM
17 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 17

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Logical shift left by register)

Syntax
<Rm>, LSL <Rs>
where: <Rm> Specifies the register whose value is to be shifted.
<Rs> Is the register containing the value of the shift.

CSIR-CEERI

LSL = a logical shift left.

Use of R15 Specifying R15 as


register Rd, register Rm, register Rn,
or register Rs has UNPREDICTABLE
results.

ARM
18 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 18

Addressing modes: Data-processing operands (Contd.)


CSIR-CEERI

Addressing Mode 1 - Data-processing operands (register)

Syntax
where:

<Rm>
<Rm> Specifies the register whose value is to be shifted.

This instruction is encoded as a


logical shift left by immediate with a
shift of zero (shift_imm == 0)

ARM
19 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 19

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Logical shift left by register)

Syntax
<Rm>, LSL <Rs>
where: <Rm> Specifies the register whose value is to be shifted.
<Rs> Is the register containing the value of the shift.

CSIR-CEERI

LSR = a logical shift left.

Use of R15 Specifying R15 as


register Rd, register Rm, register Rn,
or register Rs has UNPREDICTABLE
results.

ARM
20 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 20

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Logical shift left by register)

Syntax

CSIR-CEERI

<Rm>, LSL <Rs>

ARM
21 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 21

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Logical shift right by register)

Syntax
<Rm>, LSR <Rs>
where: <Rm> Specifies the register whose value is to be shifted.
<Rs> Is the register containing the value of the shift.

CSIR-CEERI

LSR = a logical shift right.

Use of R15 Specifying R15 as


register Rd, register Rm, register Rn,
or register Rs has UNPREDICTABLE
results.

ARM
22 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 22

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Arithmetic shift right by register)

Syntax
<Rm>, ASR <Rs>
where: <Rm> Specifies the register whose value is to be shifted.
<Rs> Is the register containing the value of the shift.

CSIR-CEERI

ASR = arithmetic shift right.

Use of R15 Specifying R15 as


register Rd, register Rm, register Rn,
or register Rs has UNPREDICTABLE
results.

ARM
23 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 23

Addressing modes: Data-processing operands (Contd.)


Addressing Mode 1 - Data-processing operands (Rotate right by register)

Syntax
<Rm>, ROR <Rs>
where: <Rm> Specifies the register whose value is to be shifted.
<Rs> Is the register containing the value of the rotation.

CSIR-CEERI

ROR = a rotate right.

Use of R15 Specifying R15 as


register Rd, register Rm, register Rn,
or register Rs has UNPREDICTABLE
results.

ARM
24 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 24

Addressing modes: Data-processing operands (Contd.)


CSIR-CEERI

Addressing Mode 1 - Data-processing operands

Constant Multiplication:
Constant multiplication is often faster using shifts
and additions

MUL r0, r2, #7 ; r0 = r2 * 7

Is the same as:

MUL r0, r2, #8 ; r0 = r2 * 8

Is the same as:

RSB r0, r2, r2, LSL #3 ; r0 = r2 * 7


; r0 = -r2 + 8*r2 = 7*r2
RSB r0, r1, r2 is the same as
SUB r0, r2, r1 ; r0 = r1 r2

MOV r0, r2, LSL #3 ; r0 = r2 * 8

Constant division
MOV r1, r3, ASR #7 ; r1 = r3/128
Treats the register value like signed values (shifts in MSB).

Vs.
MOV r1, r3, LSR #7 ; r1 = r3/128
Treats register value like unsigned values (shifts in 0)

ARM
25 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

Constant Multiplication:
with subtractions

Multiply by 35:
ADD
RSB

r9,r8,r8,LSL #2 ; r9=r8*5
r10,r9,r9,LSL #3 ; r10=r9*7

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 25

Addressing modes: Load and Store Word or Unsigned Byte


Addressing Mode 2 - Load and Store Word or Unsigned Byte

CSIR-CEERI

There are nine formats used to calculate the address for a Load and Store Word or Unsigned Byte
instruction.
The syntax is: LDR|STR{<cond>}{B}{T} <Rd>, <addressing_mode>
where <addressing_mode> is one of the nine options listed below.
1. [<Rn>, #+/-<offset_12>]
Load and Store Word or Unsigned Byte - Immediate offset.
2. [<Rn>, #+/-<offset_12>]!
Load and Store Word or Unsigned Byte - Immediate pre-indexed with auto update.
3. [<Rn>], #+/-<offset_12>
Load and Store Word or Unsigned Byte - Immediate post-indexed.

pre-indexed = Offset
pre-indexed with auto update = Pre-Index Addressing with Auto Index =
Pre-index write back = Pre-index with write back = Auto Index
ARM
26 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 26

Addressing modes: Load and Store Word or Unsigned Byte


Addressing Mode 2 - Load and Store Word or Unsigned Byte

CSIR-CEERI

Register
1. [<Rn>, +/-<Rm>]
Load and Store Word or Unsigned Byte - Register offset (pre-index).
2. [<Rn>, +/-<Rm>, <shift> #<shift_imm>]
Load and Store Word or Unsigned Byte - Scaled register offset (pre-index).
3. [<Rn>, +/-<Rm>]!
Load and Store Word or Unsigned Byte - Register pre-indexed with auto update.
4. [<Rn>], +/-<Rm>
Load and Store Word or Unsigned Byte - Register post-indexed.
5. [<Rn>], +/-<Rm>, <shift> #<shift_imm>
Load and Store Word or Unsigned Byte - Scaled register post-indexed
6. [<Rn>, +/-<Rm>, <shift> #<shift_imm>]!
Load and Store Word or Unsigned Byte - Scaled register pre-indexed with auto update.

RegisterOffset (pre index) with and without scale


Index pre with auto update & post with and without scale
ARM
27 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 27

Load and Store Word or Unsigned Byte: Pre and Post Index
CSIR-CEERI

Pre-index addressing (LDR

R0, [R1, #4])

without a writeback
Auto-indexing addressing (LDR

R0, [R1, #4]!)

Pre-index with writeback


calculation before accessing with a writeback
Post-index addressing (LDR

R0, [R1], #4)

calculation after accessing with a writeback

ARM
28 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 28

Pre-index (Offset) addressing


CSIR-CEERI

LDR

R0, [R1, #4]

@ R0=mem[R1+4]
@ R1 unchanged

LDR R0, [R1,

R1

+
R0

ARM
29 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 29

Load and Store Word or Unsigned Byte: Pre and Post Index
CSIR-CEERI

Memory is addressed by a register and an offset.

LDR

R0, [R1]@ mem[R1]

Three ways to specify offsets:

Immediate

LDR R0, [R1, #4] @ mem[R1+4]


Register
LDR R0, [R1, R2] @ mem[R1+R2]
Scaled register
@ mem[R1+4*R2]
LDR

R0, [R1, R2, LSL #2]

ARM
30 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 30

Pre-Index with auto-indexing addressing


CSIR-CEERI

Base register is first updated, the updated address is used

ARM
31 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 31

Pre-Index with auto-update addressing


CSIR-CEERI

LDR

R0, [R1, #4]!

@ R0=mem[R1+4]
@ R1=R1+4

No extra time; Fast;

LDR R0, [R1,

R1

]!

+
R0

ARM
32 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 32

Pre-Index with auto-indexing addressing


CSIR-CEERI

Post-indexed addressing: Base register is updated after load / store

ARM
33 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 33

Post-index addressing
LDR

R0, R1, #4

CSIR-CEERI

@ R0=mem[R1]
@ R1=R1+4

LDR R0,[R1],

R0

R1
+
ARM
34 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 34

Use of Pre-Index Post-indexing


CSIR-CEERI

ARM
35 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 35

Addressing modes: Load and Store Word or Unsigned Byte


Addressing Mode 2 - Load and Store Word or Unsigned Byte

CSIR-CEERI

There are nine formats used to calculate the address for a Load and Store Word or Unsigned Byte
instruction.
The syntax is: LDR|STR{<cond>}{B}{T} <Rd>, <addressing_mode>
where <addressing_mode> is one of the nine options listed below.
1. [<Rn>, #+/-<offset_12>] Immediate
Load and Store Word or Unsigned Byte - Immediate offset.
2. [<Rn>, #+/-<offset_12>]!
Load and Store Word or Unsigned Byte - Immediate pre-indexed with auto update.
3. [<Rn>], #+/-<offset_12>
Load and Store Word or Unsigned Byte - Immediate post-indexed.

ARM
36 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 36

Addressing mode2: Load and Store Word or Unsigned Byte


Addressing Mode 2 - Load and Store Word or Unsigned Byte (Immediate offset)

CSIR-CEERI

Syntax [<Rn>, #+/-<offset_12>]; where: <Rn> Specifies the register containing the base address. <offset_12> Specifies the immediate
offset used with the value of Rn to form the address.

The B bit This bit distinguishes between an unsigned byte (B==1) and a word (B==0) access.
The L bit This bit distinguishes between a Load (L==1) and a Store (L==0) instruction.
Use of R15 If R15 is specified as register Rn, the value used is the address of the instruction plus eight.

ARM
37 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 37

Addressing mode2: Load and Store Word or Unsigned Byte


CSIR-CEERI

Addressing Mode 2 - Load and Store Word or Unsigned Byte (Immediate pre-indexed auto update)

Syntax [<Rn>, #+/-<offset_12>]!


;where: <Rn> Specifies the register containing the base address. <offset_12> Specifies the immediate
offset used with the value of Rn to form the address. ! Sets the W bit, causing base register update

The B bit This bit distinguishes between an unsigned byte (B==1) and a word (B==0) access.
The L bit This bit distinguishes between a Load (L==1) and a Store (L==0) instruction.
Use of R15 Specifying R15 as register Rn has UNPREDICTABLE results.

! Sets the W bit, causing base register update.

ARM
38 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 38

Addressing mode2: Load and Store Word or Unsigned Byte


Addressing Mode 2 - Load and Store Word or Unsigned Byte (Immediate post-indexed)

CSIR-CEERI

Syntax [<Rn>], #+/-<offset_12>


;where: <Rn> Specifies the register containing the base address. <offset_12> Specifies the immediate
offset used with the value of Rn to form the address.

The B bit This bit distinguishes between an unsigned byte (B==1) and a word (B==0) access.
The L bit This bit distinguishes between a Load (L==1) and a Store (L==0) instruction.
Use of R15 Specifying R15 as register Rn has UNPREDICTABLE results.

This addressing mode is used for pointer access


to arrays with automatic update of the pointer
value.

ARM
39 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 39

Addressing modes: Miscellaneous Loads and Stores


Addressing Mode 3 - Miscellaneous Loads and Stores

CSIR-CEERI

There are six formats used to calculate the address for load and store (signed or unsigned) half word,
load signed byte, or load and store double word instructions.
The general instruction syntax is: LDR|STR{<cond>}H|SH|SB|D <Rd>, <addressing_mode>
where <addressing_mode> is one of the following six options:
1. [<Rn>, #+/-<offset_8>]

Miscellaneous Loads and Stores - Immediate offset.

2.

[<Rn>, +/-<Rm>]

Miscellaneous Loads and Stores - Register offset

3.

[<Rn>, #+/-<offset_8>]!

Miscellaneous Loads and Stores - Immediate pre-indexed

4.

[<Rn>, +/-<Rm>]!

Miscellaneous Loads and Stores - Register pre-indexed

5.

[<Rn>], #+/-<offset_8>

Miscellaneous Loads and Stores - Immediate post-indexed

6.

[<Rn>], +/-<Rm>

Miscellaneous Loads and Stores - Register post-indexed

ARM
40 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 40

Addressing modes: Miscellaneous Loads and Stores


Addressing Mode 3 - Miscellaneous Loads and Stores

CSIR-CEERI

The P bit Has two meanings:


P == 0 Indicates the use of post-indexed addressing. The base register value is used for
the memory address, and the offset is then applied to the base register value and
written back to the base register.
P == 1 Indicates the use of offset addressing or pre-indexed addressing (the W bit
determines which). The memory address is generated by applying the offset to
the base register value.

ARM
41 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 41

Addressing modes: Miscellaneous Loads and Stores


Addressing Mode 3 - Miscellaneous Loads and Stores

CSIR-CEERI

The L, S and H bits


These bits combine to specify signed or unsigned loads or stores, and doubleword, halfword,
or byte accesses:
L=0, S=0, H=1 Store halfword.
L=0, S=1, H=0 Load doubleword.
L=0, S=1, H=1 Store doubleword.
L=1, S=0, H=1 Load unsigned halfword.
L=1, S=1, H=0 Load signed byte.
L=1, S=1, H=1 Load signed halfword.
Prior to v5TE, the bits were denoted as Load/!Store (L), Signed/!Unsigned (S) and
halfword/!Byte (H) bits.
Signed bytes and halfwords can be stored with the same STRB and STRH instructions as are
used for unsigned quantities, so no separate signed store instructions are provided.

ARM
42 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 42

Addressing modes: Miscellaneous Loads and Stores


Addressing Mode 3 - Miscellaneous Loads and Stores

CSIR-CEERI

The U bit Indicates whether the offset is added to the base (U == 1) or subtracted from the base (U == 0).
The W bit Has two meanings:
P == 0 The W bit must be 0 or the instruction is UNPREDICTABLE.
P == 1 W == 1 indicates that the memory address is written back to the base register
(pre-indexed addressing), and W == 0 that the base register is
unchanged (offset addressing).
Unsigned bytes
If S == 0 and H == 0, apparently indicating an unsigned byte,
Unsigned bytes are accessed by the LDRB, LDRBT, STRB and STRBT instructions, which use
addressing mode 2 rather than addressing mode 3.
Signed stores If S ==1 and L == 0, apparently indicating a signed store instruction, the encoding along
with the H-bit is used to support the LDRD (H == 0) and STRD (H == 1) instructions.

ARM
43 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 43

Addressing modes: Load and Store Multiple


Addressing Mode 4 - Load and Store Multiple

CSIR-CEERI

Load and Store Multiple addressing modes produce a sequential range of addresses. The lowestnumbered register is stored at the lowest memory address and the highest-numbered register at the
highest memory address
The general instruction syntax is: LDM|STM{<cond>}<addressing_mode> <Rn>{!}, <registers>{^}
where <addressing_mode> is one of the following the options:
1. IA (Increment After)

Load and Store Multiple - Increment after.

2. IB (Increment Before)

Load and Store Multiple - Increment before.

3. DA (Decrement After)

Load and Store Multiple - Decrement after.

4. DB (Decrement Before)

Load and Store Multiple - Decrement before.

ARM
44 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 44

Addressing modes: Load and Store Multiple


Addressing Mode 4 - Load and Store Multiple

ARM
45 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

CSIR-CEERI

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 45

Addressing modes: Load and Store Multiple


Addressing Mode 4 - Load and Store Multiple

CSIR-CEERI

The P bit Has two meanings:


P == 0
indicates that the word addressed by Rn is included in the range of memory
locations accessed, lying at the top (U==0) or bottom (U==1) of that range.
P == 1

indicates that the word addressed by Rn is excluded from the range of memory
locations accessed, and lies one word beyond the top of the range (U==0) or one
word below the bottom of the range (U==1).

The U bit Indicates that the transfer is made upwards (U==1) or downwards (U==0) from the base register.
The S bit
For LDMs that load the PC, the S bit indicates that the CPSR is loaded from the SPSR.
For LDMs that do not load the PC and all STMs, the S bit indicates that when the
processor is in a privileged mode, the User mode banked registers are transferred instead
of the
registers of the current mode.
LDM with the S bit set is UNPREDICTABLE in User or System mode.

ARM
46 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 46

Addressing modes: Load and Store Multiple


Addressing Mode 4 - Load and Store Multiple

CSIR-CEERI

The W bit
Indicates that the base register is updated after the transfer. The base register is
incremented (U==1) or decremented (U==0) by four times the number of registers
in the
register list.
The L bit

Distinguishes between Load (L==1) and Store (L==0) instructions.

Register list
The register_list field of the instruction has one bit for each general-purpose
register: bit[0] for register zero through to bit[15] for register 15 (the PC). If no
bits are set,
the result is UNPREDICTABLE.
The instruction syntax specifies the registers to load or store in <registers>,
which is a comma-separated list of registers, surrounded by { and }.

ARM
47 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 47

Addressing modes: Load and Store Coprocessor


Addressing Mode 5 - Load and Store Coprocessor

CSIR-CEERI

There are four addressing modes which are used to calculate the address of a Load or Store
Coprocessor instruction.
The general instruction syntax is: <opcode>{<cond>}{L} <coproc>,<CRd>,<addressing_mode>
where <addressing_mode> is one of the following the options:
1. [<Rn>,#+/-<offset_8>*4]
Load and Store Coprocessor - Immediate offset
2. [<Rn>,#+/-<offset_8>*4]!

Load and Store Coprocessor - Immediate pre-indexed

3. [<Rn>],#+/-<offset_8>*4

Load and Store Coprocessor - Immediate post-indexed

4. [<Rn>],<option>

Load and Store Coprocessor - Unindexed

ARM
48 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 48

Addressing modes: Load and Store Coprocessor


Addressing Mode 5 - Load and Store Coprocessor

CSIR-CEERI

The P bit Has two meanings:


P == 0
Indicates the use of post-indexed addressing or unindexed addressing (the W bit
determines which). The base register value is used for the memory address
P == 1

The U bit

Indicates the use of offset addressing or pre-indexed addressing (the W bit


determines which). The memory address is generated by applying the offset to
the base register value.
U == 1 Indicates that the offset is added to the base.
U == 0 Indicates that the offset is subtracted from the base

The N bit
The meaning of this bit is coprocessor-dependent. Its recommended use is to
distinguish between different-sized values to be transferred.

ARM
49 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 49

Addressing modes: Load and Store Coprocessor


Addressing Mode 5 - Load and Store Coprocessor

CSIR-CEERI

The W bit Has two meanings:


W == 1 Indicates that the memory address is written back to the base register.
W == 0 Indicates that the base register value is unchanged.
Also:
If P == 0, this distinguishes unindexed addressing (W == 0) from post-indexed addressing
== 1). For unindexed addressing, U must equal 1 or the result is either
UNDEFINED or
If P == 1,
this distinguishes offset addressing (W == 0) from pre-indexed addressing (W == 1).
The L bit

(W

Distinguishes between Load (L == 1) and Store (L == 0) instructions.

ARM
50 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 50

CSIR-CEERI

Break

ARM
51 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 51

ARM Instruction set Architecture


CSIR-CEERI

The ARM instruction set can be divided into six broad

classes of instruction
Branch instructions
Data-processing instructions
Status register transfer instructions transfer the contents of

the CPSR or an SPSR to or from a general-purpose


register. Writing to the CPSR can:

Set the values of the condition code flags


Set the values of the interrupt enable bits
Set the processor mode and state
Alter the endianness of Load and Store operations.

Instruction formats
A. Data Processing Instructions
B. Single Data Swap
C. Shift and Rotate Instructions
D. Unconditional Instructions and Conditional
Instructions:
E. Stack Operations
F. Branch
G. Multiply Instructions
E: Data Transfer

Load and store instructions: Load a 64-bit double word, a

32-bit / 16-bit or an 8-bit from memory into a register (s)


Coprocessor instructions
Exception-generating instructions

ARM
52 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 52

Data Types
CSIR-CEERI

Data type

Size

Signed range

Unsigned range

char, int8_t, uint8_t

Byte

-128 to 127

0 to 255

short, int16_t, uint16_t

Half word

-32768 to 32767

0 to 65535

int, int32_t, uint32_t, long

Word

-2147483648 to
2147483647

0 to 4294967295

long long, int64_t,


uint64_t

Double word

-263 to 263-1

0 to 264-1

float

Word

-3.4028234 1038 to 3.4028234 1038

double, long double

Double word

-1.7976931348623157 10308 to
1.7976931348623157 10308

pointers

Word

0x00 to 0xFFFFFFFF

enum

Byte/ half word/ word

Smallest possible data type

bool (C++), _bool(C)

Byte

True or false

wchar_t

Half word

0 to 65535

ARM
53 University Program
Copyright
ARM Ltd 2013
solomon@ceeri.ernet.in,
/ kota_solomonraju@yahoo.co.uk

EEE G512_ Embedded Systems Design: ARM Architectures; RCS & WSN LABs, DSG, CSIRCEERI, Pilani 53

Vous aimerez peut-être aussi