SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Downloaden Sie, um offline zu lesen
ARM Instruction Set
Dr. N. Mathivanan,
Department of Instrumentation and Control Engineering
Visiting Professor,
National Institute of Technology,
TRICHY, TAMIL NADU,
INDIA
Instruction Set Architecture
• Describes how processor processes instructions
• Makes available instructions, binary codes, syntax, addressing modes,
data formats etc.
• ARM defines two separate instruction sets
o ARM state instruction set – 32-bit wide
o Thumb state instruction set – 16-bit wide
N. Mathivanan
ARM State Instruction Set
• Features
o 3-address data processing instructions
o Conditional execution of each instruction
o Shift and ALU operations in single instruction
o Load-Store and Load-Store multiple instructions
o Single cycle execution of all instructions
o Instruction set extension through coprocessor instructions
N. Mathivanan
• Classes of instructions
o Data processing instructions
o Branch instructions
o Load-Store instructions
o Software interrupt instructions
o Program status register instructions
o Coprocessor instructions
N. Mathivanan
Data Processing Instructions
• Perform move, arithmetic, logical, compare and multiply operations
• All operations except multiply instructions are carried out in ALU
• Multiply instructions are carried out in multiplier block
• Data processing instructions do not access memory
• Instructions operate on two 32-bit operands, produce 32-bit result.
• Instructions can pre-process one operand using barrel shifter
• No. of basic instructions: 16 (excluding two basic multiply instrs.)
Syntax:
<opcode>{<cond>}{S} Rd, Rn, n
‘cond’- indicates flags to test, ‘S’ – set condition flags in CPSR
‘n’ may be ‘Rm’, ‘#const’ or ‘ Rs, <shift|rotate> N’
Rd – destination, Rn – 1st operand, Rn/Rm/Rs remains unchangedN. Mathivanan
• Condition codes & flag states tested
Mnemonic
Extension
Condition
Tested
Cond.
Code
Flags
Tested
Mnemonic
Extension
Condition Tested
Cond.
Code
Flags
Tested
EQ Equal 0000 Z = 1 HI Unsigned higher 1000 C=1, Z=0
NE Not Equal 0001 Z = 0 LS
Unsigned Lower or
same
1001 C=0, Z=1
CS/HS
Carry Set /
unsigned higher
or same
0010 C = 1 GE
Signed Greater
than or Equal
1010 N = V
CC/LO
Carry Clear /
unsigned lower
0011 C = 0 LT Signed Less Than 1011 N  V
MI
Minus /
Negative
0100 N = 1 GT
Signed Greater
Than
1100
Z = 0 &
N = V
PL
Plus / Positive
or Zero
0101 N = 0 LE
Signed Less Than
or Equal
1101
Z = 1 or
N  V
VS Overflow 0110 V = 1 AL Always 1110 ---
VC No overflow 0111 V = 0 NV Never (Don’t use) 1111 ---
N. Mathivanan
• Examples of shift, rotate operations
‘Rm’ reg
Rm, LSL #3
Rm, LSR #3
Rm, ASR #3
Rm, ROR #3
Rm, RRX
N. Mathivanan
• Binary encoding of data processing instructions
N. Mathivanan
• Immediate constants
o Construction of 32-bit const. using 8-bit value and 4-bit rotation
o Example: MOV r0,#0xFF000000 is MOV r0,#0xFF,8
MOV r0,#0xFFFFFFFF is MVN r0,#0x00
N. Mathivanan
EXAMPLE: Write down the assembler assembled equivalent
instructions for copying immediate constants with MOV and MVN
assembly instructions given below. (verify using Keil mVision)
MOV r0,#0x00 MOV r0,#0xFF000000 MOV r0,#0xFFFFFFFF
MVN r1,#0x01 MOV r0,#0xFC000003 MOV r0,#0x55555555
Solution: (Demo: Prog01.s)
Assembly Instruction Assembled equivalent
MOV r0,#0x00 MOV r0,#0x00
MOV r0,#0xFF000000 MOV r0,#0xFF,8
MOV r0,#0xFFFFFFFF MVN r0,#00
MVN r1,#0x01 MVN r1,#0x01
MOV r0,#0xFC000003 MOV r0,#0xFF,6
MOV r0,#0x55555555 Error generated
N. Mathivanan
• Basic data processing instructions
MOV Move a 32-bit value MOV Rd,n Rd = n
MVN Move negated (logical NOT) 32-bit value MVN Rd,n Rd = n
ADD Add two 32-bit values ADD Rd,Rn,n Rd = Rn+n
ADC Add two 32-bit values and carry ADC Rd,Rn,n Rd = Rn+n+C
SUB Subtract two 32-bit values SUB Rd,Rn,n Rd = Rn–n
SBC Subtract with carry of two 32-bit values SBC Rd,Rn,n Rd = Rn–n+C–1
RSB Reverse subtract of two 32-bit values RSB Rd,Rn,n Rd = n–Rn
RSC Reverse subtract with carry of two 32-bit values RSC Rd,Rn,n Rd = n–Rn+C–1
AND Bitwise AND of two 32-bit values AND Rd,Rn,n Rd = Rn AND n
ORR Bitwise OR of two 32-bit values ORR Rd,Rn,n Rd = Rn OR n
EOR Exclusive OR of two 32-bit values EOR Rd,Rn,n Rd = Rn XOR n
BIC
Bit clear. Every ‘1’ in second operand clears
corresponding bit of first operand
BIC Rd,Rn,n Rd = Rn AND (NOT n)
CMP Compare CMP Rd,n Rd-n & change flags only
CMN Compare Negative CMN Rd,n Rd+n & change flags only
TST Test for a bit in a 32-bit value TST Rd,n Rd AND n, change flags
TEQ Test for equality TEQ Rd,n Rd XOR n, change flags
MUL Multiply two 32-bit values MUL Rd,Rm,Rs Rd = Rm*Rs
MLA Multiple and accumulate MLA Rd,Rm,Rs,Rn Rd = (Rm*Rs)+Rn
N. Mathivanan
Data Processing Instructions - Examples
1. ADDS r0,r1,r2, LSL #3; r0=r1+(r2*8),flags change
2. CMP r0,#5 ; If r0 == 5, set Z flag
ADDEQ r1,r2,r3 ; If Z=1, r1=r2+r3 else skip
3. AND r0,r0,#0x1 ; status of bottom bit of r0
4. BIC r0,r1,r2 ; 1 in r2 bits clears r1 bits
5. CMN r0,#6400 ; flags change on r0+6400,r0 is same
6. The following program fragment implements ‘is the value of ‘A’ 1 or 5 or 8?’
functionality. Let the value of ‘A’ be in register r0.
TEQ r0,#1 ; if r0 == 0, then Z = 1
TEQNE r0,#5 ; if Z != 1 & if r0==5, then Z=1
TEQNE r0,#8 ; if Z != 1 & if r0==8, then Z=1
BNE error ; if Z != 1 branch to report error
N. Mathivanan
• Features of Conditional Execution instructions
Improves execution speed and offers high code density
Illustration:
‘C’ Program
fragment
ARM program using
branching instructions
ARM program using
conditional instructions
if (r0==0)
{
r1=r1+1;
}
else
{
r2=r2+1;
}
CMP r0,#0
BNE else
ADD r1,r1,#1
B end
else ADD r2,r2,#1
end ---
Instructions – 5
Memory space – 20 bytes
No. of cycles – 5 or 6
CMP r0,#0
ADDEQ r1,r1,#1
ADDNE r2,r2,#1
Instructions – 3
Memory space – 12 bytes
No. of cycles – 3
N. Mathivanan
Questions
1. What is the result of execution of the following?
(i) ADD r9,r8,r8,LSL #2
RSB r10,r9,r9 LSL #3
(ii) MOVS r7,r7
RSBMI r7,r7,#00
2. Place two’s complement of -1 in r6.
3. Implement ARM assembly program for the ‘C’ loop:
if((a==b) && (c==d)) e++;
3. Write an ARM instruction that converts ASCII codes of lower case
alphabets to upper case.
4. Implement (if --- then ---else) functionality using ARM instructions
for “Test whether a value in a register is positive or negative, if
positive save +1 else save -1 in a register”.
N. Mathivanan
Branch instructions
• Divert sequential execution / CALL a subroutine,
• Range: +/- 32 MB from current position (i.e. PC-8), PC relative offset
• Instruction has 24 bits allocated for specifying word offset
• With 24-bit offset append ‘00’ at LSB, extend sign bit, place into PC
• PC is set to point to new address
• How is asm instruction ‘here B here’ encoded? – Ans. 0xEAFFFFFE
o Hint: [31:28] = 1110, [27:24] = 1010, [23:0] = 24-bit offset
B Branch B label PC = label, (unconditional branch)
BL Branch and Link BL label LR = PC-4, PC = label, (CALL functionality)
BX Branch and Exchange BX Rm PC = Rm, ‘T’ bit of CPSR = 1 (to ARM state)
BLX
Branch with Link
Exchange
BLX Rm LR = PC-4, PC = Rm, ‘T’ bit of CPSR = 1
BLX label LR = PC-4, ‘T’ bit of CPSR = 1, PC = label
N. Mathivanan
Branch Instructions - Examples
1. Example of using ‘B’ instruction:
CMP r0,#0 ; check if r0 == 0
BNE r2inc ; if r0 !=0 branch to ‘r2inc’
ADD r1,r1,#1 ; r1 += 1
B next ; unconditional branch to ‘next’
r2inc ADD r2,r2,#1 ; r2 += 1
next ---- ; continue
2. Example of using ‘BL’ instruction
BL funct1 ; save return addr. & subroutine
CMP r0,#5 ; next instruction
---
func1 ADD r0,r0,#1 ; subroutine
--- ; codes
MOV pc,lr ; return to programN. Mathivanan
Subroutines
• Called from main program using ‘BL’ instruction
• The instruction places PC-4 in LR and addr of subroutine in PC
• Last instruction in subroutine is MOV PC, LR or BX LR
• If not a leaf routine (nested subroutine):
o Store LR in stack using STMxx r13,{……,r14} at entry
o Restore LR from stack using LDMxx r13,{…,r14} before exit
• Passing parameters between procedures: Methods –
o Using Registers, Parameter Block, Stack
N. Mathivanan
3. Example of using ‘BX’ instruction
; ARM state codes
CODE32 ; 32-bit instructions follow
LDR r0,=tcode+1 ; address of tcode to r0,
; +1 to enter Thumb state
MOV lr,pc ; save return address
BX r0 ; branch to thumb code
--- ; ARM code continues
; Thumb state codes
CODE16 ; to begin Thumb code execution
tcode ADD r0,#1 ; Thumb code halfword aligned
---
---
BX lr ; return to ARM code & state
4. Example of using ‘BLX’ instruction
In the above example replace ‘MOV lr,pc’ and ‘BX r0’ by ‘BLX r0’
Branch Instructions - Examples
N. Mathivanan
Load-Store Instructions
• Single Transfer Instruction
o Transfers boundary aligned Word/HW/Byte between mem & reg
o LDR and STR instructions
o Address of mem loc. is given by Base Addr. +/- Offset
o Addressing modes: method of providing offset
 Register addressing – A register contains offset
 Immediate addressing – Immediate constant is offset
 Scaled addressing – Offset in a reg is scaled using shift operation
o Syntax:
<opcode>{<condition>}{<type>}Rd,[Rn{,<offset>}]
 <type> - H, HS, B, BS
 Rd – source/destination register
 Rn – Base address
 <offset> - ‘Rm’ or #(0-4095) or ‘Rm,<shift>#n’
N. Mathivanan
• Single register transfer instructions addressing modes - Examples
1. LDRB r3,[r8,#3] ; load at bottom byte of r3 from mem8[r8+3]
2. STRB r10,[r7,-r4] ; store bottom byte of r10 at mem8[r7-r4]
3. LDRH r1,[r0] ; load at bottom halfword of r1 from mem16[r0]
4. STRH r10,[r7,-r4] ; store bottom halfword of r10 at mem16[r7-r4]
5. LDR r0,[r1,r2] ; r0=mem32[r1+r2]
Addressing mode Instruction Operation
STR
Register addressing STR Rd,[Rn,Rm] mem32[Rn+Rm]=Rd
Immediate addressing
(with offset zero)
STR Rd,[Rn] mem32[Rn]=Rd
Immediate addressing STR Rd,[Rn,#offset] mem32[Rn+offset]=Rd
Scaled addressing STR Rd,[Rn,Rm LSL #n] mem32[Rn+(Rm<<n)]=Rd
LDR
Register addressing LDR Rd,[Rn,Rm] Rd=mem32[Rn+Rm]
Immediate addressing
(with offset zero)
LDR Rd,[Rn] Rd=mem32[Rn]
Immediate addressing LDR Rd,[Rn,#offset] Rd=mem32[Rn+offset]
Scaled addressing LDR Rd,[Rn,Rm LSL #n] Rd=mem32[Rn+(Rm<<n)]N. Mathivanan
• Indexing methods (base pointer update options)
o Preindexed:
<opcode>{<cond>}{<type>}Rd,[Rn{,<offset>]
o Preindexed with write back (note the exclamation symbol)
<opcode>{<cond>}{<type>}Rd,[Rn{,<offset>]!
o Postindexed
<opcode>{<cond>}Rd,[Rn],<offset>
Indexing Instruction Operation
Preindex
LDR Rd,[Rn,n] Rd=[Rn+n],
STR Rd,[Rn,n] [Rn+n]=Rd
Preindex with
write back
LDR Rd,[Rn,n]! Rd=[Rn+n],Rn=Rn+n
STR Rd,[Rn,n]! [Rn+n]=Rd, Rn=Rn+n
Postindex
LDR Rd,[Rn],n Rd=[Rn],Rn=Rn+n
STR Rd,[Rn],n [Rn]=Rd,Rn=Rn+n
N. Mathivanan
• Indexing methods – Examples
1. LDR r0,[r1,#04]! ; preindex with write back,
; r0 = mem32[r1+04], r1 += 04
2. LDR r0,[r1,r2] ; preindex,
; r0 = mem32[r1+r2], r1 not updated
3. LDR r0,[r1],r2 LSR #04; postindex,
; r0 = mem32[r1], r1 += r2 >> 04
4. LDRB r7,[r6,#-1]! ; preindex with write back
; bottom byte of r7 = mem8[r6-1],
; then r6 = r6-1
5. STRH r0,[r1,r2]! ; preindex with write back,
; mem16[r1+r2] = bottom halfword of r0,
; r1 += r2
6. STRH r0,[r1],#04 ; postindex,
; mem16[r1] = r0, r1 += 04
N. Mathivanan
Multiple Load-Store Instructions
• Transfers data between multiple regs & mem in single instruction
• Instructions: LDM and STM
• Use: stack, block move, temporary store & restore
• Advantages: small code size, single instruction fetch from memory
• Disadvantages: can’t be interrupted, increases interrupt latency
• Syntax:
<opcode>{<cond>}<mode>Rn{!},<registers>
• Rn – Base register, ‘!’ update base reg. after data transfer (option)
<mode> Description Start address End address Rn!
IA Increment After Rn Rn+N*4-4 Rn+N*4
IB Increment Before Rn+4 Rn+N*4 Rn+N*4
DA Decrement After Rn–N*4+4 Rn Rn-N*4
DB Decrement Before Rn-N*4 Rn-4 Rn-N*4N. Mathivanan
• Examples
STMxx r9, {r0-r2}
LDMxx r9, {r0-r2}
• Used in pairs for temp store/restore
STMIA – LDMDB, STMIB – LDMDA
STMDA – LDMIB, STMDB – LDMIA
• Store & restore operation by STMIB & LDMDA pair (testprog2)
Program
R0 r1 r2 r3 [r0+0x04] [r0+0x08] [r0+0x0C]
0x00000100 0x00000011 0x00000022 0x00000033 0x00000000 0x00000000 0x00000000
STMIB r0!, {r1-r3} 0x0000010C 0x00000011 0x00000022 0x00000033 0x00000011 0x00000022 0x00000033
MOV r1,#00 0x0000010C 0x00000000 0x00000022 0x00000033 0x00000011 0x00000022 0x00000033
MOV r2,#00 0x0000010C 0x00000000 0x00000000 0x00000033 0x00000011 0x00000022 0x00000033
MOV r3,#00 0x0000010C 0x00000000 0x00000000 0x00000000 0x00000011 0x00000022 0x00000033
LDMDA r0!, {r1-r3} 0x00000100 0x00000011 0x00000022 0x00000033 0x00000011 0x00000022 0x00000033
N. Mathivanan
• Stack operations
o Alternative suffixes to IA, IB, DA and DB
o Full/Empty, Ascending/Descending (FD, FA, ED, EA) (8085 stack–FD)
o E.g.: STMFD r13, {r2, r0, r3-r8, r1}
• Swap instructions (also known as semaphore instructions)
Stack type
Store multiple instruction
(Push operation)
Load multiple instruction
(Pop operation)
Full Descending STMFD (STMDB) LDMFD (LDMIA)
Full Ascending STMFA (STMIB) LDMFA (LDMDA)
Empty Descending STMED (STMDA) LDMED (LDMIB)
Empty Ascending STMEA (STMIA) LDMEA (LDMDB)
SWP
Swap a word between register and
memory
SWP Rd,Rm,[Rn]
temp = mem32[Rn]
mem32[Rn] = Rm
Rd = temp
SWPB
Swap a byte between register and
memory
SWPB
Rd,Rm,[Rn]
temp = mem8[Rn]
mem8[Rn] = Rm
Rd = temp
N. Mathivanan
Software Interrupt Instructions
• Use: User mode applications to execute OS routines
• When executed, mode changes to supervisor mode
• Syntax: SWI{cond} SWI_number
• Example: SWI 0x123456
• Return instruction from SWI routine: MOVS PC, r14
• Examples – Semihosting
o Mechanism to communicate & use I/O facilities on host computer running
debugger
MOV r0,#0x18 ; program termination
LDR r1,=0x20026 ;
SVC #0x123456 ; semihosting CALL
• Distinguish subroutine call and SWI instruction execution
N. Mathivanan
• Semihosting overview
N. Mathivanan
Program Status Register Instructions
• Instructions to read/write from/to CPSR or SPSR
• Instructions: MRS, MSR
• Syntaxes:
MRS{<cond>} Rd,<CPSR|SPSR>
MSR{<cond>} <CPSR|SPSR>,Rm
MSR{<cond>} <CPSR|SPSR>_<fields>,Rm
MSR{<cond>} <CPSR|SPSR>_<fields>,#immediate
• Modifying CPSR, SPSR: Read, Modify and Write back technique
o Read CPSR/SPSR using MRS
o Modify relevant bits
o Transfer to CPSR/SPSR using MSR
• Note:
• In user mode all fields can be read, but flags alone can be modified
N. Mathivanan
• Examples:
o Program to enable FIQ (executed in svc mode)
MRS r1,cpsr ; copies CPSR into r1
BIC r1,#0x40 ; clears B6, i.e. FIQ interrupt mask bit
MSR cpsr,r1 ; copies r1 into CPSR
o Program to change mode (from svc mode to fiq mode)
MRS r0,cpsr ; get CPSR into r0
BIC r0,r0,0x1F ; clear the mode bits, i.e. 5 LSB bits - B[4:0]
ORR r0,r0,0x11 ; set to FIQ mode
MSR cpsr,r0 ; write r0 into CPSR
N. Mathivanan
Coprocessor Instructions
• ARM supports 16 coprocessors
• Coprocessor implemented in hardware, software or both
• Coprocessor contains instruction pipeline, instruction decoding logic,
handshake logic, register bank, special processing logic with its own
data path.
• It is also connected to data bus like ARM core processor
• Instructions in program memory are available for coprocessors also.
• Works in conjunction with ARM core and process same instruction
stream as ARM, but executes only instructions meant for
coprocessor and ignores ARM and other coprocessor’s instructions
• 3 types of instructions: data processing, register transfer, memory
transfer
N. Mathivanan
• Coprocessor instructions
CDP
Coprocessor data
processing
CDP p5,2,c12,c10,c3,4
Coprocessor number 5,
opcode1 – 2, opcode2 – 4,
Coprocessor destination register – 12,
Coprocessor source registers – 10 & 3
MCR
Move to
coprocessor from
ARM register
MCR p14,1,r7,c7,c12,6
Coprocessor number 14,
opcode1 – 2, opcode2 – 4,
ARM source register – r7,
Coprocessor destination registers – 10 & 3
MRC
Move to ARM
register from
coprocessor
MRC p15,5,r4,c0,c2,3
Coprocessor number 15,
opcode1 – 5, opcode2 – 3,
ARM destination register – r4,
Coprocessor source registers – 0 & 2
MCRR
Move to
coprocessor from
two ARM
registers
MCRR p10,3,r4,r5,c2
Coprocessor number 10,
opcode1 – 3,
ARM source registers – r4, r5
Coprocessor destination register – 2
MRRC
Move to two
ARM registers
from coprocessor
MRCC p8,4,r2,r3,c3
Coprocessor number 8,
opcode1 – 4,
ARM destination registers – r2, r3
Coprocessor source register – 3
N. Mathivanan
• Coprocessor instructions continued……
LDC
Load
coprocessor
register
LDC p6,c1,[r4]
Coprocessor number 6,
Coprocessor register c1 is loaded with data from
memory address in r4.
LDC p6,c4,[r2,#4]
Coprocessor number 6,
Coprocessor register c4 is loaded with data from
memory address in r2 +4.
STC
Store
coprocessor
register
STC p8,c8,[r2,#4]!
Coprocessor number 8,
Memory address is [r2] + 4
Store c8 in memory and then r2 =r2+4
STC p8,c9,[r2],#-16
Coprocessor number 8,
Memory address is [r2]
Store c9 in memory and then r2 =r2-16
N. Mathivanan
Thumb State Instruction Set
• 16-bit instructions (compressed form), executable in Thumb state.
• Instruction decoder decompresses to 32-bit ARM equivalent
• Features:
• Works on 32-bit values, produces 32-bit addr for mem access
• Access to low registers (r0-r7) similar to ARM state
• Restricted access to high registers (r8-r15), MOV, ADD, CMP can access
• Thumb state enabled by ‘T’ bit (if set) of CPSR.
• If enabled, fetches 16-bit code from HW aligned addresses, PC is
incremented by two bytes
• Instructions removed: MLA, RSB, RSC, MSR, MRS, SWP, SWPB and
coprocessor instructions;
• New Instructions: LSL, LSR, ASR, ROR (barrel shifter can’t be
combined with any instruction)
• Not conditionally executable (except ‘B’ branch instruction)
N. Mathivanan
• Data processing instructions
o 2-addr format, No conditional execution, No ‘S’ suffix (always ON)
o MOV, MVN, ADD, ADC, SUB, SBC, MUL, AND, ORR, EOR, BIC,
o NEG, LSL, LSR, ASR, ROR, CMP, CMN, TST
• Branch instructions
• Branch instruction (‘B’) is conditionally executable
• B{cond}, B, BL, BX, BLX
• Load-Store instructions
• Offset: register, immediate (0-124 words), relative to PC/SP
• LDR, STR, LDMIA, STMIA, PUSH, POP
• Software interrupt instructions
• Generates exception, Use just 8-bit interpreted value
• Handler enters in ARM mode
N. Mathivanan
• Thumb
decompressor
• Illustration: Thumb uses less memory space than ARM though more
instructions are used – Let r1, r2 have value and divisor. The program
produces quotient and remainder in r3 and r2.
MOV r3,#0
loop SUB r0,r0,r1
ADDGE r3,r3,#1
BGE loop
ADD r2,r0,r1
ARM code
Instructions: 5
Memory space: 20 bytes
MOV r3,#0
loop ADD r3,#1
SUB r0,r1
BGE loop
SUB r3,#1
ADD r2,r0,r1
Thumb code
Instructions: 6
Memory space: 12 bytesN. Mathivanan
Review Questions
1. What are the features of 32-bit ARM state instructions?
2. Illustrate the features of conditional execution of ARM instruction
with suitable examples.
3. List the classes of ARM state instructions.
4. Write down the syntax of data processing class of instructions and
explain.
5. Implement the multiplication of a register by 35 using ‘ADD’ and
‘RSB’ instructions.
6. What are the functions of ‘TST’ and ‘BIC’ instructions?
7. What is result of execution of ‘MOV r0, 0x55555555’ instruction?
Why?
N. Mathivanan
8. Write down the instructions providing ‘JUMP’ and ‘CALL’ functionalities.
9. What is the branching range of branch instructions?
10. Write down the syntax of single transfer Load-Store class of
instructions and explain.
11. Describe the addressing modes of Load-Store instructions.
12. Write down an instruction that transfers a word size data into ‘r0’
register from a memory location at an offset of 16 bytes from a word
aligned memory location whose address is in ‘r1’ register.
13. Explain the indexing methods supported by ARM7 Load-Store class of
instruction.
14. Write down the syntax of Load-Store Multiple instructions. Explain the
use of the instructions with examples.
15. What are the advantages & disadvantages of Load-Store Multiple
instructions?
N. Mathivanan
16. What is ‘FD’ stack? Explain with suitable schematics.
17. Write down the pair of load and store multiple instructions that is
used in ‘EA’ type stack.
18. An array of words with 25 elements is in memory and the address
of first element is in r1 register. Implement the following ‘C’
statement using ARM instructions. The value ‘const’ is in r2
register. array[10] = array[5] + const
19. Write an ARM7 ALP fragment that implements ‘block move’
functions assuming the elements of the block are words, the
starting address of source block is in ‘r9’ register, the destination
address is in ‘r10’ register and the size of the block is 8 words.
20. What is the basic task of ‘SWP’ instruction?
21. What for the PSR instructions are provided?N. Mathivanan
22. What is the purpose of ‘SWI’ instruction?
23. Write down ARM7 ALP fragments to enable IRQ and change to
IRQ mode while processor is running in a privileged mode.
24. What are coprocessors? Discuss the support for coprocessors in
ARM v4T ISA.
25. What are the features of 16-bit Thumb state instructions?
26. Illustrate with suitable example: Thumb code offers high code
density
N. Mathivanan

Weitere ähnliche Inhalte

Was ist angesagt?

Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction SetDr. Pankaj Zope
 
ARM CORTEX M3 PPT
ARM CORTEX M3 PPTARM CORTEX M3 PPT
ARM CORTEX M3 PPTGaurav Verma
 
ARM Architecture Instruction Set
ARM Architecture Instruction SetARM Architecture Instruction Set
ARM Architecture Instruction SetDwight Sabio
 
ARM architcture
ARM architcture ARM architcture
ARM architcture Hossam Adel
 
Counters &amp; time delay
Counters &amp; time delayCounters &amp; time delay
Counters &amp; time delayHemant Chetwani
 
Arm programmer's model
Arm programmer's modelArm programmer's model
Arm programmer's modelv Kalairajan
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor Mustapha Fatty
 
ARM Architecture
ARM ArchitectureARM Architecture
ARM ArchitectureDwight Sabio
 
LECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSLECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSDr.YNM
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051SARITHA REDDY
 
Digital signal processor architecture
Digital signal processor architectureDigital signal processor architecture
Digital signal processor architecturekomal mistry
 
ARM Exception and interrupts
ARM Exception and interrupts ARM Exception and interrupts
ARM Exception and interrupts NishmaNJ
 
Instruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInstruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInteX Research Lab
 
Introduction to arm processor
Introduction to arm processorIntroduction to arm processor
Introduction to arm processorRAMPRAKASHT1
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051hello_priti
 
Microprocessor 8085 complete
Microprocessor 8085 completeMicroprocessor 8085 complete
Microprocessor 8085 completeShubham Singh
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller NotesDr.YNM
 
8086 pin details
8086 pin details8086 pin details
8086 pin detailsAJAL A J
 

Was ist angesagt? (20)

Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction Set
 
ARM CORTEX M3 PPT
ARM CORTEX M3 PPTARM CORTEX M3 PPT
ARM CORTEX M3 PPT
 
Instruction formats-in-8086
Instruction formats-in-8086Instruction formats-in-8086
Instruction formats-in-8086
 
ARM Architecture Instruction Set
ARM Architecture Instruction SetARM Architecture Instruction Set
ARM Architecture Instruction Set
 
ARM architcture
ARM architcture ARM architcture
ARM architcture
 
Counters &amp; time delay
Counters &amp; time delayCounters &amp; time delay
Counters &amp; time delay
 
Arm programmer's model
Arm programmer's modelArm programmer's model
Arm programmer's model
 
Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor  Architecture of 8086 Microprocessor
Architecture of 8086 Microprocessor
 
ARM Architecture
ARM ArchitectureARM Architecture
ARM Architecture
 
LECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORSLECT 1: ARM PROCESSORS
LECT 1: ARM PROCESSORS
 
Addressing modes of 8051
Addressing modes of 8051Addressing modes of 8051
Addressing modes of 8051
 
Digital signal processor architecture
Digital signal processor architectureDigital signal processor architecture
Digital signal processor architecture
 
ARM Exception and interrupts
ARM Exception and interrupts ARM Exception and interrupts
ARM Exception and interrupts
 
Instruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInstruction pipeline: Computer Architecture
Instruction pipeline: Computer Architecture
 
Introduction to arm processor
Introduction to arm processorIntroduction to arm processor
Introduction to arm processor
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051
 
Microprocessor 8085 complete
Microprocessor 8085 completeMicroprocessor 8085 complete
Microprocessor 8085 complete
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller Notes
 
Unit vi (1)
Unit vi (1)Unit vi (1)
Unit vi (1)
 
8086 pin details
8086 pin details8086 pin details
8086 pin details
 

Ähnlich wie Arm instruction set

15CS44 MP & MC module 5
15CS44 MP & MC  module 515CS44 MP & MC  module 5
15CS44 MP & MC module 5RLJIT
 
ARM Fundamentals
ARM FundamentalsARM Fundamentals
ARM Fundamentalsguest56d1b781
 
arm-instructionset.pdf
arm-instructionset.pdfarm-instructionset.pdf
arm-instructionset.pdfRoopaPatil24
 
arm-instructionset.pdf
arm-instructionset.pdfarm-instructionset.pdf
arm-instructionset.pdfRoopaPatil24
 
ARM AAE - Intrustion Sets
ARM AAE - Intrustion SetsARM AAE - Intrustion Sets
ARM AAE - Intrustion SetsAnh Dung NGUYEN
 
MES_MODULE 2.pptx
MES_MODULE 2.pptxMES_MODULE 2.pptx
MES_MODULE 2.pptxShivakumar M
 
18CS44-MES-Module-2(Chapter 3).pptx
18CS44-MES-Module-2(Chapter 3).pptx18CS44-MES-Module-2(Chapter 3).pptx
18CS44-MES-Module-2(Chapter 3).pptxrakshitha481121
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051logesh waran
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching materialJohn Williams
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching materialNilesh Bhandare
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptManju Badiger
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction setKarthik Vivek
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction setKarthik Vivek
 
Microcontroller instruction set
Microcontroller instruction setMicrocontroller instruction set
Microcontroller instruction setShail Modi
 
microcontroller_instruction_set for ENGINEERING STUDENTS
microcontroller_instruction_set for  ENGINEERING STUDENTSmicrocontroller_instruction_set for  ENGINEERING STUDENTS
microcontroller_instruction_set for ENGINEERING STUDENTSssuser2b759d
 

Ähnlich wie Arm instruction set (20)

15CS44 MP & MC module 5
15CS44 MP & MC  module 515CS44 MP & MC  module 5
15CS44 MP & MC module 5
 
module 5.1.pptx
module 5.1.pptxmodule 5.1.pptx
module 5.1.pptx
 
module 5.pptx
module 5.pptxmodule 5.pptx
module 5.pptx
 
ARM Fundamentals
ARM FundamentalsARM Fundamentals
ARM Fundamentals
 
Unit vi
Unit viUnit vi
Unit vi
 
arm-instructionset.pdf
arm-instructionset.pdfarm-instructionset.pdf
arm-instructionset.pdf
 
arm-instructionset.pdf
arm-instructionset.pdfarm-instructionset.pdf
arm-instructionset.pdf
 
ARM AAE - Intrustion Sets
ARM AAE - Intrustion SetsARM AAE - Intrustion Sets
ARM AAE - Intrustion Sets
 
UNIT 2 ERTS.ppt
UNIT 2 ERTS.pptUNIT 2 ERTS.ppt
UNIT 2 ERTS.ppt
 
MES_MODULE 2.pptx
MES_MODULE 2.pptxMES_MODULE 2.pptx
MES_MODULE 2.pptx
 
18CS44-MES-Module-2(Chapter 3).pptx
18CS44-MES-Module-2(Chapter 3).pptx18CS44-MES-Module-2(Chapter 3).pptx
18CS44-MES-Module-2(Chapter 3).pptx
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.ppt
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
 
OptimizingARM
OptimizingARMOptimizingARM
OptimizingARM
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
 
Microcontroller instruction set
Microcontroller instruction setMicrocontroller instruction set
Microcontroller instruction set
 
microcontroller_instruction_set for ENGINEERING STUDENTS
microcontroller_instruction_set for  ENGINEERING STUDENTSmicrocontroller_instruction_set for  ENGINEERING STUDENTS
microcontroller_instruction_set for ENGINEERING STUDENTS
 

KĂźrzlich hochgeladen

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

KĂźrzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Arm instruction set

  • 1. ARM Instruction Set Dr. N. Mathivanan, Department of Instrumentation and Control Engineering Visiting Professor, National Institute of Technology, TRICHY, TAMIL NADU, INDIA
  • 2. Instruction Set Architecture • Describes how processor processes instructions • Makes available instructions, binary codes, syntax, addressing modes, data formats etc. • ARM defines two separate instruction sets o ARM state instruction set – 32-bit wide o Thumb state instruction set – 16-bit wide N. Mathivanan
  • 3. ARM State Instruction Set • Features o 3-address data processing instructions o Conditional execution of each instruction o Shift and ALU operations in single instruction o Load-Store and Load-Store multiple instructions o Single cycle execution of all instructions o Instruction set extension through coprocessor instructions N. Mathivanan
  • 4. • Classes of instructions o Data processing instructions o Branch instructions o Load-Store instructions o Software interrupt instructions o Program status register instructions o Coprocessor instructions N. Mathivanan
  • 5. Data Processing Instructions • Perform move, arithmetic, logical, compare and multiply operations • All operations except multiply instructions are carried out in ALU • Multiply instructions are carried out in multiplier block • Data processing instructions do not access memory • Instructions operate on two 32-bit operands, produce 32-bit result. • Instructions can pre-process one operand using barrel shifter • No. of basic instructions: 16 (excluding two basic multiply instrs.) Syntax: <opcode>{<cond>}{S} Rd, Rn, n ‘cond’- indicates flags to test, ‘S’ – set condition flags in CPSR ‘n’ may be ‘Rm’, ‘#const’ or ‘ Rs, <shift|rotate> N’ Rd – destination, Rn – 1st operand, Rn/Rm/Rs remains unchangedN. Mathivanan
  • 6. • Condition codes & flag states tested Mnemonic Extension Condition Tested Cond. Code Flags Tested Mnemonic Extension Condition Tested Cond. Code Flags Tested EQ Equal 0000 Z = 1 HI Unsigned higher 1000 C=1, Z=0 NE Not Equal 0001 Z = 0 LS Unsigned Lower or same 1001 C=0, Z=1 CS/HS Carry Set / unsigned higher or same 0010 C = 1 GE Signed Greater than or Equal 1010 N = V CC/LO Carry Clear / unsigned lower 0011 C = 0 LT Signed Less Than 1011 N  V MI Minus / Negative 0100 N = 1 GT Signed Greater Than 1100 Z = 0 & N = V PL Plus / Positive or Zero 0101 N = 0 LE Signed Less Than or Equal 1101 Z = 1 or N  V VS Overflow 0110 V = 1 AL Always 1110 --- VC No overflow 0111 V = 0 NV Never (Don’t use) 1111 --- N. Mathivanan
  • 7. • Examples of shift, rotate operations ‘Rm’ reg Rm, LSL #3 Rm, LSR #3 Rm, ASR #3 Rm, ROR #3 Rm, RRX N. Mathivanan
  • 8. • Binary encoding of data processing instructions N. Mathivanan
  • 9. • Immediate constants o Construction of 32-bit const. using 8-bit value and 4-bit rotation o Example: MOV r0,#0xFF000000 is MOV r0,#0xFF,8 MOV r0,#0xFFFFFFFF is MVN r0,#0x00 N. Mathivanan
  • 10. EXAMPLE: Write down the assembler assembled equivalent instructions for copying immediate constants with MOV and MVN assembly instructions given below. (verify using Keil mVision) MOV r0,#0x00 MOV r0,#0xFF000000 MOV r0,#0xFFFFFFFF MVN r1,#0x01 MOV r0,#0xFC000003 MOV r0,#0x55555555 Solution: (Demo: Prog01.s) Assembly Instruction Assembled equivalent MOV r0,#0x00 MOV r0,#0x00 MOV r0,#0xFF000000 MOV r0,#0xFF,8 MOV r0,#0xFFFFFFFF MVN r0,#00 MVN r1,#0x01 MVN r1,#0x01 MOV r0,#0xFC000003 MOV r0,#0xFF,6 MOV r0,#0x55555555 Error generated N. Mathivanan
  • 11. • Basic data processing instructions MOV Move a 32-bit value MOV Rd,n Rd = n MVN Move negated (logical NOT) 32-bit value MVN Rd,n Rd = n ADD Add two 32-bit values ADD Rd,Rn,n Rd = Rn+n ADC Add two 32-bit values and carry ADC Rd,Rn,n Rd = Rn+n+C SUB Subtract two 32-bit values SUB Rd,Rn,n Rd = Rn–n SBC Subtract with carry of two 32-bit values SBC Rd,Rn,n Rd = Rn–n+C–1 RSB Reverse subtract of two 32-bit values RSB Rd,Rn,n Rd = n–Rn RSC Reverse subtract with carry of two 32-bit values RSC Rd,Rn,n Rd = n–Rn+C–1 AND Bitwise AND of two 32-bit values AND Rd,Rn,n Rd = Rn AND n ORR Bitwise OR of two 32-bit values ORR Rd,Rn,n Rd = Rn OR n EOR Exclusive OR of two 32-bit values EOR Rd,Rn,n Rd = Rn XOR n BIC Bit clear. Every ‘1’ in second operand clears corresponding bit of first operand BIC Rd,Rn,n Rd = Rn AND (NOT n) CMP Compare CMP Rd,n Rd-n & change flags only CMN Compare Negative CMN Rd,n Rd+n & change flags only TST Test for a bit in a 32-bit value TST Rd,n Rd AND n, change flags TEQ Test for equality TEQ Rd,n Rd XOR n, change flags MUL Multiply two 32-bit values MUL Rd,Rm,Rs Rd = Rm*Rs MLA Multiple and accumulate MLA Rd,Rm,Rs,Rn Rd = (Rm*Rs)+Rn N. Mathivanan
  • 12. Data Processing Instructions - Examples 1. ADDS r0,r1,r2, LSL #3; r0=r1+(r2*8),flags change 2. CMP r0,#5 ; If r0 == 5, set Z flag ADDEQ r1,r2,r3 ; If Z=1, r1=r2+r3 else skip 3. AND r0,r0,#0x1 ; status of bottom bit of r0 4. BIC r0,r1,r2 ; 1 in r2 bits clears r1 bits 5. CMN r0,#6400 ; flags change on r0+6400,r0 is same 6. The following program fragment implements ‘is the value of ‘A’ 1 or 5 or 8?’ functionality. Let the value of ‘A’ be in register r0. TEQ r0,#1 ; if r0 == 0, then Z = 1 TEQNE r0,#5 ; if Z != 1 & if r0==5, then Z=1 TEQNE r0,#8 ; if Z != 1 & if r0==8, then Z=1 BNE error ; if Z != 1 branch to report error N. Mathivanan
  • 13. • Features of Conditional Execution instructions Improves execution speed and offers high code density Illustration: ‘C’ Program fragment ARM program using branching instructions ARM program using conditional instructions if (r0==0) { r1=r1+1; } else { r2=r2+1; } CMP r0,#0 BNE else ADD r1,r1,#1 B end else ADD r2,r2,#1 end --- Instructions – 5 Memory space – 20 bytes No. of cycles – 5 or 6 CMP r0,#0 ADDEQ r1,r1,#1 ADDNE r2,r2,#1 Instructions – 3 Memory space – 12 bytes No. of cycles – 3 N. Mathivanan
  • 14. Questions 1. What is the result of execution of the following? (i) ADD r9,r8,r8,LSL #2 RSB r10,r9,r9 LSL #3 (ii) MOVS r7,r7 RSBMI r7,r7,#00 2. Place two’s complement of -1 in r6. 3. Implement ARM assembly program for the ‘C’ loop: if((a==b) && (c==d)) e++; 3. Write an ARM instruction that converts ASCII codes of lower case alphabets to upper case. 4. Implement (if --- then ---else) functionality using ARM instructions for “Test whether a value in a register is positive or negative, if positive save +1 else save -1 in a register”. N. Mathivanan
  • 15. Branch instructions • Divert sequential execution / CALL a subroutine, • Range: +/- 32 MB from current position (i.e. PC-8), PC relative offset • Instruction has 24 bits allocated for specifying word offset • With 24-bit offset append ‘00’ at LSB, extend sign bit, place into PC • PC is set to point to new address • How is asm instruction ‘here B here’ encoded? – Ans. 0xEAFFFFFE o Hint: [31:28] = 1110, [27:24] = 1010, [23:0] = 24-bit offset B Branch B label PC = label, (unconditional branch) BL Branch and Link BL label LR = PC-4, PC = label, (CALL functionality) BX Branch and Exchange BX Rm PC = Rm, ‘T’ bit of CPSR = 1 (to ARM state) BLX Branch with Link Exchange BLX Rm LR = PC-4, PC = Rm, ‘T’ bit of CPSR = 1 BLX label LR = PC-4, ‘T’ bit of CPSR = 1, PC = label N. Mathivanan
  • 16. Branch Instructions - Examples 1. Example of using ‘B’ instruction: CMP r0,#0 ; check if r0 == 0 BNE r2inc ; if r0 !=0 branch to ‘r2inc’ ADD r1,r1,#1 ; r1 += 1 B next ; unconditional branch to ‘next’ r2inc ADD r2,r2,#1 ; r2 += 1 next ---- ; continue 2. Example of using ‘BL’ instruction BL funct1 ; save return addr. & subroutine CMP r0,#5 ; next instruction --- func1 ADD r0,r0,#1 ; subroutine --- ; codes MOV pc,lr ; return to programN. Mathivanan
  • 17. Subroutines • Called from main program using ‘BL’ instruction • The instruction places PC-4 in LR and addr of subroutine in PC • Last instruction in subroutine is MOV PC, LR or BX LR • If not a leaf routine (nested subroutine): o Store LR in stack using STMxx r13,{……,r14} at entry o Restore LR from stack using LDMxx r13,{…,r14} before exit • Passing parameters between procedures: Methods – o Using Registers, Parameter Block, Stack N. Mathivanan
  • 18. 3. Example of using ‘BX’ instruction ; ARM state codes CODE32 ; 32-bit instructions follow LDR r0,=tcode+1 ; address of tcode to r0, ; +1 to enter Thumb state MOV lr,pc ; save return address BX r0 ; branch to thumb code --- ; ARM code continues ; Thumb state codes CODE16 ; to begin Thumb code execution tcode ADD r0,#1 ; Thumb code halfword aligned --- --- BX lr ; return to ARM code & state 4. Example of using ‘BLX’ instruction In the above example replace ‘MOV lr,pc’ and ‘BX r0’ by ‘BLX r0’ Branch Instructions - Examples N. Mathivanan
  • 19. Load-Store Instructions • Single Transfer Instruction o Transfers boundary aligned Word/HW/Byte between mem & reg o LDR and STR instructions o Address of mem loc. is given by Base Addr. +/- Offset o Addressing modes: method of providing offset  Register addressing – A register contains offset  Immediate addressing – Immediate constant is offset  Scaled addressing – Offset in a reg is scaled using shift operation o Syntax: <opcode>{<condition>}{<type>}Rd,[Rn{,<offset>}]  <type> - H, HS, B, BS  Rd – source/destination register  Rn – Base address  <offset> - ‘Rm’ or #(0-4095) or ‘Rm,<shift>#n’ N. Mathivanan
  • 20. • Single register transfer instructions addressing modes - Examples 1. LDRB r3,[r8,#3] ; load at bottom byte of r3 from mem8[r8+3] 2. STRB r10,[r7,-r4] ; store bottom byte of r10 at mem8[r7-r4] 3. LDRH r1,[r0] ; load at bottom halfword of r1 from mem16[r0] 4. STRH r10,[r7,-r4] ; store bottom halfword of r10 at mem16[r7-r4] 5. LDR r0,[r1,r2] ; r0=mem32[r1+r2] Addressing mode Instruction Operation STR Register addressing STR Rd,[Rn,Rm] mem32[Rn+Rm]=Rd Immediate addressing (with offset zero) STR Rd,[Rn] mem32[Rn]=Rd Immediate addressing STR Rd,[Rn,#offset] mem32[Rn+offset]=Rd Scaled addressing STR Rd,[Rn,Rm LSL #n] mem32[Rn+(Rm<<n)]=Rd LDR Register addressing LDR Rd,[Rn,Rm] Rd=mem32[Rn+Rm] Immediate addressing (with offset zero) LDR Rd,[Rn] Rd=mem32[Rn] Immediate addressing LDR Rd,[Rn,#offset] Rd=mem32[Rn+offset] Scaled addressing LDR Rd,[Rn,Rm LSL #n] Rd=mem32[Rn+(Rm<<n)]N. Mathivanan
  • 21. • Indexing methods (base pointer update options) o Preindexed: <opcode>{<cond>}{<type>}Rd,[Rn{,<offset>] o Preindexed with write back (note the exclamation symbol) <opcode>{<cond>}{<type>}Rd,[Rn{,<offset>]! o Postindexed <opcode>{<cond>}Rd,[Rn],<offset> Indexing Instruction Operation Preindex LDR Rd,[Rn,n] Rd=[Rn+n], STR Rd,[Rn,n] [Rn+n]=Rd Preindex with write back LDR Rd,[Rn,n]! Rd=[Rn+n],Rn=Rn+n STR Rd,[Rn,n]! [Rn+n]=Rd, Rn=Rn+n Postindex LDR Rd,[Rn],n Rd=[Rn],Rn=Rn+n STR Rd,[Rn],n [Rn]=Rd,Rn=Rn+n N. Mathivanan
  • 22. • Indexing methods – Examples 1. LDR r0,[r1,#04]! ; preindex with write back, ; r0 = mem32[r1+04], r1 += 04 2. LDR r0,[r1,r2] ; preindex, ; r0 = mem32[r1+r2], r1 not updated 3. LDR r0,[r1],r2 LSR #04; postindex, ; r0 = mem32[r1], r1 += r2 >> 04 4. LDRB r7,[r6,#-1]! ; preindex with write back ; bottom byte of r7 = mem8[r6-1], ; then r6 = r6-1 5. STRH r0,[r1,r2]! ; preindex with write back, ; mem16[r1+r2] = bottom halfword of r0, ; r1 += r2 6. STRH r0,[r1],#04 ; postindex, ; mem16[r1] = r0, r1 += 04 N. Mathivanan
  • 23. Multiple Load-Store Instructions • Transfers data between multiple regs & mem in single instruction • Instructions: LDM and STM • Use: stack, block move, temporary store & restore • Advantages: small code size, single instruction fetch from memory • Disadvantages: can’t be interrupted, increases interrupt latency • Syntax: <opcode>{<cond>}<mode>Rn{!},<registers> • Rn – Base register, ‘!’ update base reg. after data transfer (option) <mode> Description Start address End address Rn! IA Increment After Rn Rn+N*4-4 Rn+N*4 IB Increment Before Rn+4 Rn+N*4 Rn+N*4 DA Decrement After Rn–N*4+4 Rn Rn-N*4 DB Decrement Before Rn-N*4 Rn-4 Rn-N*4N. Mathivanan
  • 24. • Examples STMxx r9, {r0-r2} LDMxx r9, {r0-r2} • Used in pairs for temp store/restore STMIA – LDMDB, STMIB – LDMDA STMDA – LDMIB, STMDB – LDMIA • Store & restore operation by STMIB & LDMDA pair (testprog2) Program R0 r1 r2 r3 [r0+0x04] [r0+0x08] [r0+0x0C] 0x00000100 0x00000011 0x00000022 0x00000033 0x00000000 0x00000000 0x00000000 STMIB r0!, {r1-r3} 0x0000010C 0x00000011 0x00000022 0x00000033 0x00000011 0x00000022 0x00000033 MOV r1,#00 0x0000010C 0x00000000 0x00000022 0x00000033 0x00000011 0x00000022 0x00000033 MOV r2,#00 0x0000010C 0x00000000 0x00000000 0x00000033 0x00000011 0x00000022 0x00000033 MOV r3,#00 0x0000010C 0x00000000 0x00000000 0x00000000 0x00000011 0x00000022 0x00000033 LDMDA r0!, {r1-r3} 0x00000100 0x00000011 0x00000022 0x00000033 0x00000011 0x00000022 0x00000033 N. Mathivanan
  • 25. • Stack operations o Alternative suffixes to IA, IB, DA and DB o Full/Empty, Ascending/Descending (FD, FA, ED, EA) (8085 stack–FD) o E.g.: STMFD r13, {r2, r0, r3-r8, r1} • Swap instructions (also known as semaphore instructions) Stack type Store multiple instruction (Push operation) Load multiple instruction (Pop operation) Full Descending STMFD (STMDB) LDMFD (LDMIA) Full Ascending STMFA (STMIB) LDMFA (LDMDA) Empty Descending STMED (STMDA) LDMED (LDMIB) Empty Ascending STMEA (STMIA) LDMEA (LDMDB) SWP Swap a word between register and memory SWP Rd,Rm,[Rn] temp = mem32[Rn] mem32[Rn] = Rm Rd = temp SWPB Swap a byte between register and memory SWPB Rd,Rm,[Rn] temp = mem8[Rn] mem8[Rn] = Rm Rd = temp N. Mathivanan
  • 26. Software Interrupt Instructions • Use: User mode applications to execute OS routines • When executed, mode changes to supervisor mode • Syntax: SWI{cond} SWI_number • Example: SWI 0x123456 • Return instruction from SWI routine: MOVS PC, r14 • Examples – Semihosting o Mechanism to communicate & use I/O facilities on host computer running debugger MOV r0,#0x18 ; program termination LDR r1,=0x20026 ; SVC #0x123456 ; semihosting CALL • Distinguish subroutine call and SWI instruction execution N. Mathivanan
  • 28. Program Status Register Instructions • Instructions to read/write from/to CPSR or SPSR • Instructions: MRS, MSR • Syntaxes: MRS{<cond>} Rd,<CPSR|SPSR> MSR{<cond>} <CPSR|SPSR>,Rm MSR{<cond>} <CPSR|SPSR>_<fields>,Rm MSR{<cond>} <CPSR|SPSR>_<fields>,#immediate • Modifying CPSR, SPSR: Read, Modify and Write back technique o Read CPSR/SPSR using MRS o Modify relevant bits o Transfer to CPSR/SPSR using MSR • Note: • In user mode all fields can be read, but flags alone can be modified N. Mathivanan
  • 29. • Examples: o Program to enable FIQ (executed in svc mode) MRS r1,cpsr ; copies CPSR into r1 BIC r1,#0x40 ; clears B6, i.e. FIQ interrupt mask bit MSR cpsr,r1 ; copies r1 into CPSR o Program to change mode (from svc mode to fiq mode) MRS r0,cpsr ; get CPSR into r0 BIC r0,r0,0x1F ; clear the mode bits, i.e. 5 LSB bits - B[4:0] ORR r0,r0,0x11 ; set to FIQ mode MSR cpsr,r0 ; write r0 into CPSR N. Mathivanan
  • 30. Coprocessor Instructions • ARM supports 16 coprocessors • Coprocessor implemented in hardware, software or both • Coprocessor contains instruction pipeline, instruction decoding logic, handshake logic, register bank, special processing logic with its own data path. • It is also connected to data bus like ARM core processor • Instructions in program memory are available for coprocessors also. • Works in conjunction with ARM core and process same instruction stream as ARM, but executes only instructions meant for coprocessor and ignores ARM and other coprocessor’s instructions • 3 types of instructions: data processing, register transfer, memory transfer N. Mathivanan
  • 31. • Coprocessor instructions CDP Coprocessor data processing CDP p5,2,c12,c10,c3,4 Coprocessor number 5, opcode1 – 2, opcode2 – 4, Coprocessor destination register – 12, Coprocessor source registers – 10 & 3 MCR Move to coprocessor from ARM register MCR p14,1,r7,c7,c12,6 Coprocessor number 14, opcode1 – 2, opcode2 – 4, ARM source register – r7, Coprocessor destination registers – 10 & 3 MRC Move to ARM register from coprocessor MRC p15,5,r4,c0,c2,3 Coprocessor number 15, opcode1 – 5, opcode2 – 3, ARM destination register – r4, Coprocessor source registers – 0 & 2 MCRR Move to coprocessor from two ARM registers MCRR p10,3,r4,r5,c2 Coprocessor number 10, opcode1 – 3, ARM source registers – r4, r5 Coprocessor destination register – 2 MRRC Move to two ARM registers from coprocessor MRCC p8,4,r2,r3,c3 Coprocessor number 8, opcode1 – 4, ARM destination registers – r2, r3 Coprocessor source register – 3 N. Mathivanan
  • 32. • Coprocessor instructions continued…… LDC Load coprocessor register LDC p6,c1,[r4] Coprocessor number 6, Coprocessor register c1 is loaded with data from memory address in r4. LDC p6,c4,[r2,#4] Coprocessor number 6, Coprocessor register c4 is loaded with data from memory address in r2 +4. STC Store coprocessor register STC p8,c8,[r2,#4]! Coprocessor number 8, Memory address is [r2] + 4 Store c8 in memory and then r2 =r2+4 STC p8,c9,[r2],#-16 Coprocessor number 8, Memory address is [r2] Store c9 in memory and then r2 =r2-16 N. Mathivanan
  • 33. Thumb State Instruction Set • 16-bit instructions (compressed form), executable in Thumb state. • Instruction decoder decompresses to 32-bit ARM equivalent • Features: • Works on 32-bit values, produces 32-bit addr for mem access • Access to low registers (r0-r7) similar to ARM state • Restricted access to high registers (r8-r15), MOV, ADD, CMP can access • Thumb state enabled by ‘T’ bit (if set) of CPSR. • If enabled, fetches 16-bit code from HW aligned addresses, PC is incremented by two bytes • Instructions removed: MLA, RSB, RSC, MSR, MRS, SWP, SWPB and coprocessor instructions; • New Instructions: LSL, LSR, ASR, ROR (barrel shifter can’t be combined with any instruction) • Not conditionally executable (except ‘B’ branch instruction) N. Mathivanan
  • 34. • Data processing instructions o 2-addr format, No conditional execution, No ‘S’ suffix (always ON) o MOV, MVN, ADD, ADC, SUB, SBC, MUL, AND, ORR, EOR, BIC, o NEG, LSL, LSR, ASR, ROR, CMP, CMN, TST • Branch instructions • Branch instruction (‘B’) is conditionally executable • B{cond}, B, BL, BX, BLX • Load-Store instructions • Offset: register, immediate (0-124 words), relative to PC/SP • LDR, STR, LDMIA, STMIA, PUSH, POP • Software interrupt instructions • Generates exception, Use just 8-bit interpreted value • Handler enters in ARM mode N. Mathivanan
  • 35. • Thumb decompressor • Illustration: Thumb uses less memory space than ARM though more instructions are used – Let r1, r2 have value and divisor. The program produces quotient and remainder in r3 and r2. MOV r3,#0 loop SUB r0,r0,r1 ADDGE r3,r3,#1 BGE loop ADD r2,r0,r1 ARM code Instructions: 5 Memory space: 20 bytes MOV r3,#0 loop ADD r3,#1 SUB r0,r1 BGE loop SUB r3,#1 ADD r2,r0,r1 Thumb code Instructions: 6 Memory space: 12 bytesN. Mathivanan
  • 36. Review Questions 1. What are the features of 32-bit ARM state instructions? 2. Illustrate the features of conditional execution of ARM instruction with suitable examples. 3. List the classes of ARM state instructions. 4. Write down the syntax of data processing class of instructions and explain. 5. Implement the multiplication of a register by 35 using ‘ADD’ and ‘RSB’ instructions. 6. What are the functions of ‘TST’ and ‘BIC’ instructions? 7. What is result of execution of ‘MOV r0, 0x55555555’ instruction? Why? N. Mathivanan
  • 37. 8. Write down the instructions providing ‘JUMP’ and ‘CALL’ functionalities. 9. What is the branching range of branch instructions? 10. Write down the syntax of single transfer Load-Store class of instructions and explain. 11. Describe the addressing modes of Load-Store instructions. 12. Write down an instruction that transfers a word size data into ‘r0’ register from a memory location at an offset of 16 bytes from a word aligned memory location whose address is in ‘r1’ register. 13. Explain the indexing methods supported by ARM7 Load-Store class of instruction. 14. Write down the syntax of Load-Store Multiple instructions. Explain the use of the instructions with examples. 15. What are the advantages & disadvantages of Load-Store Multiple instructions? N. Mathivanan
  • 38. 16. What is ‘FD’ stack? Explain with suitable schematics. 17. Write down the pair of load and store multiple instructions that is used in ‘EA’ type stack. 18. An array of words with 25 elements is in memory and the address of first element is in r1 register. Implement the following ‘C’ statement using ARM instructions. The value ‘const’ is in r2 register. array[10] = array[5] + const 19. Write an ARM7 ALP fragment that implements ‘block move’ functions assuming the elements of the block are words, the starting address of source block is in ‘r9’ register, the destination address is in ‘r10’ register and the size of the block is 8 words. 20. What is the basic task of ‘SWP’ instruction? 21. What for the PSR instructions are provided?N. Mathivanan
  • 39. 22. What is the purpose of ‘SWI’ instruction? 23. Write down ARM7 ALP fragments to enable IRQ and change to IRQ mode while processor is running in a privileged mode. 24. What are coprocessors? Discuss the support for coprocessors in ARM v4T ISA. 25. What are the features of 16-bit Thumb state instructions? 26. Illustrate with suitable example: Thumb code offers high code density N. Mathivanan