SlideShare a Scribd company logo
UNIT-2
INTRODUCTION TO THE ARM
INSTRUCTION SET
Content
ARM Instruction Set:
 Data Processing Instructions
Addressing Modes
Branch
Load, Store Instructions
PSR Instructions
Conditional Instructions
ARM INSTRUCTION SET
Arm instruction set can be categorized into three
groups
1.DATA PROCESSING INSTRUCTIONS
2.DATA TRANSFER INSTRUCTIONS
3.CONTROL FLOW INSTRUCTIONS
Data Processing Instructions
• The data processing instructions manipulate data within
registers.
• They are move instructions, arithmetic instructions, logical
instructions, comparison instructions, and multiply
instructions.
• Most data processing instructions can process one of their
operands using the barrel shifter.
• If you use the S suffix on a data processing instruction, then
it updates the flags in the cpsr.
Move Instructions
 Move is the simplest ARM instruction. It copies N into a
destination register Rd,
 Where N is a register or immediate value. This instruction is
useful for setting initial values and transferring data between
registers.
ARITHMETIC INSTRUCTIONS
• The arithmetic instructions implement addition and
subtraction of 32-bit signed and unsigned values.
LOGICAL INSTRUCTIONS
 Logical instructions perform bitwise logical
operations on the two source registers.
Comparison 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.
 After the bits have been set, the information can then
be used to change program flow by using conditional
execution.
Comparison Instructions
Comparison Instructions
• They update the cpsr flag according to the result but do not
affect other registers
• CMP is effectively a subtract instruction with result discarded
• TST is logical AND operation
• TEQ is logical EOR
MULTIPLY INSTRUCTIONS
 The Basic ARM provides two multiplication instructions.
 Multiply
 MUL{<cond>}{S} Rd, Rm, Rs ; Rd = Rm * Rs
 Multiply Accumulate - does addition for free
 MLA{<cond>}{S} Rd, Rm, Rs,Rn ; Rd = (Rm * Rs) + Rn
MLA : Multiply Accumulate
 MLA is used to multiply registers (signed or unsigned) to
create a 32 bit result, which is then added to another value,
which produces the final result.
 Operand 2 is multiplied by operand 3, the value of operand 4 is
added, and the result is stored in operand 1. All operands
are registers.
MLA : Example
 MOV R1, #5
 MOV R2, #3
 MOV R3, #18
 MLA R0, R1, R2, R3 ; R0 now equals 33
The Barrel Shifter
 The ARM doesn’t have actual shift instructions.
 Instead it has a barrel shifter which provides a
mechanism to carry out shifts as part of other
instructions.
 So what operations does the barrel shifter support?
Barrel Shifter
• Shift the 32 bit binary
pattern in one of the
source registers left or
right by a specific
number of positions
before it enters the
ALU
Arithmetic Logic Unit
Rm
Result N
Rd
Rn
No
pre-processing
Pre-processing
Barrel Shifter
Shift operations
Barrel Shift with Carry
 Barrel Shift with Carry Example
We apply a logical shift left (LSL) to register Rm before moving it to the destination
register.
 This is the same as applying the standard C language shift operator to the
register. TheMOV instruction copies the shift operator result N into register Rd.
N represents the result of the LSL operation described in Table 3.2.
 PRE r5 = 5
 r7 = 8
 MOV r7, r5, LSL #2 ; let r7 = r5*4 = (r5 << 2)
 POST r5 = 5
 r7 = 20
0
31
00000
LSL #5
0
31
00000
LSR #5
0
31
1 1111 1
ASR #5 , negative operand
0
31
00000 0
ASR #5 , positive operand
0 1
0
31
ROR #5
0
31
RRX
C
C C
ARM Shift Operations
Barrel Shift Operations
N Shift Operations Syntax
Immediate #immediate
Register Rm
Logical Shift Left by Immediate Rm, LSL #shift_imm
Logical Shift Left by Register Rm, LSL Rs
Logical Shift Right by Immediate Rm, LSR #shift_imm
Logical Shift Right by Register Rm, LSR Rs
Arithmetic Shift Right by Immediate Rm, ASR #shift_imm
Arithmetic Shift Right by Register Rm, ASR Rs
Rotate right by immediate Rm, ROR #shift_imm
Rotate right by register Rm, ROR Rs
Rotate right with extend Rm, RRX
UNIT 2 ERTS.ppt
DATA TRANSFER INSTRUCTIONS
Single Register Transfer
• Moving a single data item in and out of a register
• Data types supported are signed and unsigned words
(32 bit), half words (16 bit) and bytes
• <LDR|STR> {<cond>}{B} Rd,addressing
• <LDR> {<cond>}SB|H|SH Rd,addressing
• <STR> {<cond>}H Rd,addressing
Single Register Transfer
LDR load word into a register Rd <-mem32[address]
STR save byte or word from a register Rd ->mem32[address]
LDRB load byte into a register Rd <-mem8[address]
STRB save byte from a register Rd ->mem8[address]
LDRH load half word into a register Rd <-mem16[address]
STRH save half word from a register Rd ->mem16[address]
LDRSB load signed byte into a register Rd <-SignExtend
(mem8[address])
LDRSH load signed half word into a
register
Rd <-SignExtend
(mem16[address])
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
Single Register Load Store Addressing
Modes
• The ARM instruction set provides different modes for
addressing memory
• preindex with writeback
• preindex
• postindex
Index Methods
Index
Method
Data Base
Address
Register
Example
preindex
with
writeback
mem[base+offset] base+
offset
LDR r0, [r1, #4]!
preindex mem[base+offset] not
updated
LDR r0, [r1, #4]
postindex mem[base] base+
offset
LDR r0, [r1], #4
Index Methods
• Preindex with writeback calculates an address from a base
register plus address offset and then updates that address base
register with the new address.
• Preindex offset is same as the preindex with writeback but
does not update the address base register.
• Postindex only updates the address base register after the
address is used
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
Multiple Register Transfer
• Load–store multiple instructions can transfer multiple
registers between memory and the processor in a single
instruction.
• Moving blocks of data around memory and saving and
restoring context stacks
• <LDM|STM>{<cond>}<addressing mode> Rn{!},<registers>{^}
LDM load multiple registers {Rd}*N <- mem32[start address +
4*N] optional Rn updated
STM save multiple registers {Rd}*N -> mem32[start address +
4*N] optional Rn updated
UNIT 2 ERTS.ppt
Addressing Mode for Load Store Multiple
Instructions
Add:
Mode
Description Start
Address
End
Address
Rn!
IA increment after Rn Rn +4*N-4 Rn+4*N
IB increment before Rn + 4 Rn + 4*N Rn+4*N
DA decrement after Rn–4*N + 4 Rn Rn+4*N
DB decrement
before
Rn – 4*N Rn - 4 Rn+4*N
Load Store Multiple pairs when base update used
Store Multiple Load Multiple
STMIA LDMDB
STMIB LDMDA
STMDA LDMIB
STMDB LDMIA
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
Addressing Methods for Stack Operations
Add:
Mode
Description Pop =LDM Push =STM
FA full ascending LDMFA LDMDA STMFA STMIB
FD full descending LDMFD LDMIA STMFD STMDB
EA empty ascending LDMEA LDMDB STMEA STMIA
ED empty
descending
LDMED LDMIB STMED STMDA
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
SWAP Instruction
• Swaps the contents of memory with the contents of a
register
• Atomic operation– it reads and writes a location in the
same bus operation,preventing any other instruction from
reading or writing to that location until it completes.
• SWP{B}{<cond>} Rd, Rm, [Rn]
SWAP Instruction
SWP swap a word between
memory and a register
tmp=mem32[Rn]
mem32[Rn]=Rm
Rd=tmp
SWPB swap a byte between
memory and a register
tmp=mem8[Rn]
mem8[Rn]=Rm
Rd=tmp
Branch Instructions
B branch pc = label
BL branch with
link
pc = label
lr = address of the next inst. After BL
BX branch
exchange
pc = Rm & 0xfffffffe,
T = Rm & 1
BLX branch
exchange with
link
pc=label, T = 1
pc = Rm & 0xfffffffe,
T = Rm & 1
lr = address of the next inst. After BL
Software Interrupt Instruction
• Causes a software interrupt exception
• Provides a mechanism to call OS routines
• SWI{<cond>} SWI_number
SWI software
interrupt
lr_svc=address of instruction following
the SWI
spsr_svc=cpsr
pc=vectors+0x8
cpsr mode =SVC
cpsr I = 1 (mask IRQ interrupts)
Program Status Register
Instructions
• 2 instructions to directly control a psr
• MRS - transfers the contents of cpsr or spsr into a
register
• MSR - transfers the contents of register into cpsr or
spsr
N Z C V I F T Mode
31 30 29 28 7 6 5 4 0
Condition Flags Processor Mode
Interrupt
Masks
Thumb State
Function
Bit
Fields
Flags[24:31] Status[16:23] Extension[8:15] Control[0:7]
Program Status Register
Instructions
• MRS{<cond>} Rd,<cpsr|spsr>
• MSR{<cond>} <cpsr|spsr>_<fields>,Rm
• MSR{<cond>} <cpsr|spsr>_<fields>,#immediate
MRS copy psr to a gpr Rd = psr
MSR move gpr to a psr psr[field] = Rm
MSR move an immediate value to
a psr
psr[field] = immediate
Coprocessor Instructions
• Are used to extend the instruction set
• Additional computation capability
• Used to control the memory subsystem
• Used only cores with a coprocessor
• CDP{<cond>} cp,opcode1,Cd,Cn{,opcode2}
• <MRC|MCR>{<cond>} cp, opcode1, Rd, Cn, Cm{, opcode2}
• <LDC|STC>{<cond>} cp, Cd, addressing
Coprocessor Instructions
• cp field represents the coprocessor number between
p0 and p15
• opcode fields describe the operation to take place on
the coprocessor
• Cn, Cm and Cd describe registers within the
coprocessor
• CP15 – system control purposes
• MRC p15, 0, r10, c0, c0, 0
Coprocessor Instructions
CDP coprocessor data processing -perform an
operation in a coprocessor
MRC MCR coprocessor register transfer –move data
to/from coprocessor registers
LDC
STC
coprocessor memory transfers –load and
store blocks of memory to/from a
coprocessor
Loading Constants
• LDR Rd, =constant
• ADR Rd, label
LDR Load constant
pseudoinstruction
Rd = 32 bit constant
ADR Load address
pseudoinstruction
Rd = 32 bit relative
address
Loading Constants
Pseudo instruction Actual instruction
LDR r0, =0xff MOV r0, #0xff
LDR r0, =0x55555555 LDR r0, [pc,#offset_12]
Count Leading Zeroes Instruction
• CLZ
• Counts the number of zeroes between the MSB and
the first bit set to 1
– R1=0x00000010
– CLZ R0,R1
– R0 = 6
Conditional Execution
• The instruction only executes if the condition code
flags pass a given condition or test
• Increase performance & code density
• 2 letter mnemonic (eg: AL)
• Conditional execution depends on
– Condition field
– Condition flags
Summary
• All ARM instructions are 32 bit in length
• Arithmetic, logical, comparison & move
instructions can all use the inline barrel shifter
• 3 types of load store instruction – single register,
multiple register, swap
• SWI & Program Status Register
• ARMv5E –CLZ, saturation, improved multiply
instructions
• Conditional execution

More Related Content

PPTX
PPTX
ARM-7 ADDRESSING MODES INSTRUCTION SET
PPTX
MES_MODULE 2.pptx
PDF
15CS44 MP & MC module 5
PDF
Embedded system and arm with different module
PPTX
ARM Programming.pptxARM instructions process data held in registers and only ...
PDF
Unit II arm 7 Instruction Set
PPTX
Module 2 PPT of ES.pptx
ARM-7 ADDRESSING MODES INSTRUCTION SET
MES_MODULE 2.pptx
15CS44 MP & MC module 5
Embedded system and arm with different module
ARM Programming.pptxARM instructions process data held in registers and only ...
Unit II arm 7 Instruction Set
Module 2 PPT of ES.pptx

Similar to UNIT 2 ERTS.ppt (20)

PPTX
EPC Module-5 ES.pptxModule-5 ES.pptxModule-5 ES.pptx
PPTX
Arm instruction set
PPT
Arm Cortex material Arm Cortex material3222886.ppt
PPTX
module 5.pptx
PPTX
module 5.1.pptx
PPT
ARM Fundamentals
PDF
ARM AAE - Intrustion Sets
PDF
arm-instructionset.pdf
PDF
arm-instructionset.pdf
PDF
ARM Architecture Instruction Set
PPTX
ARM instruction set
PDF
ARM_InstructionSet.pdf; For VTU 22 regulation course code BCS402
PPTX
Cortex_M3 Instruction SetCortex_M3 Instruction SetCortex_M3 Instruction Set.pptx
PPT
Embedded Systems ARM Computer Architecture
PDF
Arm instruction set
PPT
Arm teaching material
PPT
Arm teaching material
PDF
ARM Holings presentation for the worldd.pdf
PDF
Lecture6.pdf computer architecture for computer science
PPTX
Computer Organisation Part 4
EPC Module-5 ES.pptxModule-5 ES.pptxModule-5 ES.pptx
Arm instruction set
Arm Cortex material Arm Cortex material3222886.ppt
module 5.pptx
module 5.1.pptx
ARM Fundamentals
ARM AAE - Intrustion Sets
arm-instructionset.pdf
arm-instructionset.pdf
ARM Architecture Instruction Set
ARM instruction set
ARM_InstructionSet.pdf; For VTU 22 regulation course code BCS402
Cortex_M3 Instruction SetCortex_M3 Instruction SetCortex_M3 Instruction Set.pptx
Embedded Systems ARM Computer Architecture
Arm instruction set
Arm teaching material
Arm teaching material
ARM Holings presentation for the worldd.pdf
Lecture6.pdf computer architecture for computer science
Computer Organisation Part 4
Ad

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Complications of Minimal Access Surgery at WLH
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
master seminar digital applications in india
PDF
VCE English Exam - Section C Student Revision Booklet
O7-L3 Supply Chain Operations - ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Complications of Minimal Access Surgery at WLH
STATICS OF THE RIGID BODIES Hibbelers.pdf
Computing-Curriculum for Schools in Ghana
human mycosis Human fungal infections are called human mycosis..pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Microbial disease of the cardiovascular and lymphatic systems
A systematic review of self-coping strategies used by university students to ...
102 student loan defaulters named and shamed – Is someone you know on the list?
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Final Presentation General Medicine 03-08-2024.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
master seminar digital applications in india
VCE English Exam - Section C Student Revision Booklet
Ad

UNIT 2 ERTS.ppt

  • 1. UNIT-2 INTRODUCTION TO THE ARM INSTRUCTION SET
  • 2. Content ARM Instruction Set:  Data Processing Instructions Addressing Modes Branch Load, Store Instructions PSR Instructions Conditional Instructions
  • 3. ARM INSTRUCTION SET Arm instruction set can be categorized into three groups 1.DATA PROCESSING INSTRUCTIONS 2.DATA TRANSFER INSTRUCTIONS 3.CONTROL FLOW INSTRUCTIONS
  • 4. Data Processing Instructions • The data processing instructions manipulate data within registers. • They are move instructions, arithmetic instructions, logical instructions, comparison instructions, and multiply instructions. • Most data processing instructions can process one of their operands using the barrel shifter. • If you use the S suffix on a data processing instruction, then it updates the flags in the cpsr.
  • 5. Move Instructions  Move is the simplest ARM instruction. It copies N into a destination register Rd,  Where N is a register or immediate value. This instruction is useful for setting initial values and transferring data between registers.
  • 6. ARITHMETIC INSTRUCTIONS • The arithmetic instructions implement addition and subtraction of 32-bit signed and unsigned values.
  • 7. LOGICAL INSTRUCTIONS  Logical instructions perform bitwise logical operations on the two source registers.
  • 8. Comparison 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.  After the bits have been set, the information can then be used to change program flow by using conditional execution.
  • 10. Comparison Instructions • They update the cpsr flag according to the result but do not affect other registers • CMP is effectively a subtract instruction with result discarded • TST is logical AND operation • TEQ is logical EOR
  • 11. MULTIPLY INSTRUCTIONS  The Basic ARM provides two multiplication instructions.  Multiply  MUL{<cond>}{S} Rd, Rm, Rs ; Rd = Rm * Rs  Multiply Accumulate - does addition for free  MLA{<cond>}{S} Rd, Rm, Rs,Rn ; Rd = (Rm * Rs) + Rn
  • 12. MLA : Multiply Accumulate  MLA is used to multiply registers (signed or unsigned) to create a 32 bit result, which is then added to another value, which produces the final result.  Operand 2 is multiplied by operand 3, the value of operand 4 is added, and the result is stored in operand 1. All operands are registers.
  • 13. MLA : Example  MOV R1, #5  MOV R2, #3  MOV R3, #18  MLA R0, R1, R2, R3 ; R0 now equals 33
  • 14. The Barrel Shifter  The ARM doesn’t have actual shift instructions.  Instead it has a barrel shifter which provides a mechanism to carry out shifts as part of other instructions.  So what operations does the barrel shifter support?
  • 15. Barrel Shifter • Shift the 32 bit binary pattern in one of the source registers left or right by a specific number of positions before it enters the ALU Arithmetic Logic Unit Rm Result N Rd Rn No pre-processing Pre-processing Barrel Shifter
  • 18.  Barrel Shift with Carry Example We apply a logical shift left (LSL) to register Rm before moving it to the destination register.  This is the same as applying the standard C language shift operator to the register. TheMOV instruction copies the shift operator result N into register Rd. N represents the result of the LSL operation described in Table 3.2.  PRE r5 = 5  r7 = 8  MOV r7, r5, LSL #2 ; let r7 = r5*4 = (r5 << 2)  POST r5 = 5  r7 = 20
  • 19. 0 31 00000 LSL #5 0 31 00000 LSR #5 0 31 1 1111 1 ASR #5 , negative operand 0 31 00000 0 ASR #5 , positive operand 0 1 0 31 ROR #5 0 31 RRX C C C ARM Shift Operations
  • 20. Barrel Shift Operations N Shift Operations Syntax Immediate #immediate Register Rm Logical Shift Left by Immediate Rm, LSL #shift_imm Logical Shift Left by Register Rm, LSL Rs Logical Shift Right by Immediate Rm, LSR #shift_imm Logical Shift Right by Register Rm, LSR Rs Arithmetic Shift Right by Immediate Rm, ASR #shift_imm Arithmetic Shift Right by Register Rm, ASR Rs Rotate right by immediate Rm, ROR #shift_imm Rotate right by register Rm, ROR Rs Rotate right with extend Rm, RRX
  • 23. Single Register Transfer • Moving a single data item in and out of a register • Data types supported are signed and unsigned words (32 bit), half words (16 bit) and bytes • <LDR|STR> {<cond>}{B} Rd,addressing • <LDR> {<cond>}SB|H|SH Rd,addressing • <STR> {<cond>}H Rd,addressing
  • 24. Single Register Transfer LDR load word into a register Rd <-mem32[address] STR save byte or word from a register Rd ->mem32[address] LDRB load byte into a register Rd <-mem8[address] STRB save byte from a register Rd ->mem8[address] LDRH load half word into a register Rd <-mem16[address] STRH save half word from a register Rd ->mem16[address] LDRSB load signed byte into a register Rd <-SignExtend (mem8[address]) LDRSH load signed half word into a register Rd <-SignExtend (mem16[address])
  • 27. Single Register Load Store Addressing Modes • The ARM instruction set provides different modes for addressing memory • preindex with writeback • preindex • postindex
  • 28. Index Methods Index Method Data Base Address Register Example preindex with writeback mem[base+offset] base+ offset LDR r0, [r1, #4]! preindex mem[base+offset] not updated LDR r0, [r1, #4] postindex mem[base] base+ offset LDR r0, [r1], #4
  • 29. Index Methods • Preindex with writeback calculates an address from a base register plus address offset and then updates that address base register with the new address. • Preindex offset is same as the preindex with writeback but does not update the address base register. • Postindex only updates the address base register after the address is used
  • 36. Multiple Register Transfer • Load–store multiple instructions can transfer multiple registers between memory and the processor in a single instruction. • Moving blocks of data around memory and saving and restoring context stacks • <LDM|STM>{<cond>}<addressing mode> Rn{!},<registers>{^} LDM load multiple registers {Rd}*N <- mem32[start address + 4*N] optional Rn updated STM save multiple registers {Rd}*N -> mem32[start address + 4*N] optional Rn updated
  • 38. Addressing Mode for Load Store Multiple Instructions Add: Mode Description Start Address End Address Rn! IA increment after Rn Rn +4*N-4 Rn+4*N IB increment before Rn + 4 Rn + 4*N Rn+4*N DA decrement after Rn–4*N + 4 Rn Rn+4*N DB decrement before Rn – 4*N Rn - 4 Rn+4*N
  • 39. Load Store Multiple pairs when base update used Store Multiple Load Multiple STMIA LDMDB STMIB LDMDA STMDA LDMIB STMDB LDMIA
  • 55. Addressing Methods for Stack Operations Add: Mode Description Pop =LDM Push =STM FA full ascending LDMFA LDMDA STMFA STMIB FD full descending LDMFD LDMIA STMFD STMDB EA empty ascending LDMEA LDMDB STMEA STMIA ED empty descending LDMED LDMIB STMED STMDA
  • 65. SWAP Instruction • Swaps the contents of memory with the contents of a register • Atomic operation– it reads and writes a location in the same bus operation,preventing any other instruction from reading or writing to that location until it completes. • SWP{B}{<cond>} Rd, Rm, [Rn]
  • 66. SWAP Instruction SWP swap a word between memory and a register tmp=mem32[Rn] mem32[Rn]=Rm Rd=tmp SWPB swap a byte between memory and a register tmp=mem8[Rn] mem8[Rn]=Rm Rd=tmp
  • 67. Branch Instructions B branch pc = label BL branch with link pc = label lr = address of the next inst. After BL BX branch exchange pc = Rm & 0xfffffffe, T = Rm & 1 BLX branch exchange with link pc=label, T = 1 pc = Rm & 0xfffffffe, T = Rm & 1 lr = address of the next inst. After BL
  • 68. Software Interrupt Instruction • Causes a software interrupt exception • Provides a mechanism to call OS routines • SWI{<cond>} SWI_number SWI software interrupt lr_svc=address of instruction following the SWI spsr_svc=cpsr pc=vectors+0x8 cpsr mode =SVC cpsr I = 1 (mask IRQ interrupts)
  • 69. Program Status Register Instructions • 2 instructions to directly control a psr • MRS - transfers the contents of cpsr or spsr into a register • MSR - transfers the contents of register into cpsr or spsr N Z C V I F T Mode 31 30 29 28 7 6 5 4 0 Condition Flags Processor Mode Interrupt Masks Thumb State Function Bit Fields Flags[24:31] Status[16:23] Extension[8:15] Control[0:7]
  • 70. Program Status Register Instructions • MRS{<cond>} Rd,<cpsr|spsr> • MSR{<cond>} <cpsr|spsr>_<fields>,Rm • MSR{<cond>} <cpsr|spsr>_<fields>,#immediate MRS copy psr to a gpr Rd = psr MSR move gpr to a psr psr[field] = Rm MSR move an immediate value to a psr psr[field] = immediate
  • 71. Coprocessor Instructions • Are used to extend the instruction set • Additional computation capability • Used to control the memory subsystem • Used only cores with a coprocessor • CDP{<cond>} cp,opcode1,Cd,Cn{,opcode2} • <MRC|MCR>{<cond>} cp, opcode1, Rd, Cn, Cm{, opcode2} • <LDC|STC>{<cond>} cp, Cd, addressing
  • 72. Coprocessor Instructions • cp field represents the coprocessor number between p0 and p15 • opcode fields describe the operation to take place on the coprocessor • Cn, Cm and Cd describe registers within the coprocessor • CP15 – system control purposes • MRC p15, 0, r10, c0, c0, 0
  • 73. Coprocessor Instructions CDP coprocessor data processing -perform an operation in a coprocessor MRC MCR coprocessor register transfer –move data to/from coprocessor registers LDC STC coprocessor memory transfers –load and store blocks of memory to/from a coprocessor
  • 74. Loading Constants • LDR Rd, =constant • ADR Rd, label LDR Load constant pseudoinstruction Rd = 32 bit constant ADR Load address pseudoinstruction Rd = 32 bit relative address
  • 75. Loading Constants Pseudo instruction Actual instruction LDR r0, =0xff MOV r0, #0xff LDR r0, =0x55555555 LDR r0, [pc,#offset_12]
  • 76. Count Leading Zeroes Instruction • CLZ • Counts the number of zeroes between the MSB and the first bit set to 1 – R1=0x00000010 – CLZ R0,R1 – R0 = 6
  • 77. Conditional Execution • The instruction only executes if the condition code flags pass a given condition or test • Increase performance & code density • 2 letter mnemonic (eg: AL) • Conditional execution depends on – Condition field – Condition flags
  • 78. Summary • All ARM instructions are 32 bit in length • Arithmetic, logical, comparison & move instructions can all use the inline barrel shifter • 3 types of load store instruction – single register, multiple register, swap • SWI & Program Status Register • ARMv5E –CLZ, saturation, improved multiply instructions • Conditional execution