Module 2 (Part 1)
Module 2 (Part 1)
Module 2 (Part 1)
Dr. Suchitra M
Professor
Dept. of ECE, VVCE, Mysuru
07/10/2021 1
Instruction sets
• An instruction is a binary
pattern designed inside a
processor to perform a
specific function.
• Machine instructions are
represented by 0s and 1s
• We use mnemonics such as
mov, dec, branch, add etc
• A complete set of mnemonics
and rules constitute Assembly
language
• Assembler
Assembly language (source
program) to machine
instructions (object
program)
ARM has multiple instruction sets
• Performance is high
Thumb instruction (16 bit)
Cortex-M3, is always in Thumb state and does not support ARM state
Unified Assembler Language (UAL)
MOV R5, R3
The MOV instruction copies the value of R3 into R5
Prior
R5=0x98765431
R3= 0x AABBCCDD
After
R5=0x AABBCCDD
R3= 0x AABBCCDD
Contd.
MVN R0, R2
Prior
R2=0xFFFFFFF0
R0= 0x AABBcd09
After
R2=0xFFFFFFF0
R0=0x0000000F
Moving data between special register and register
MSR and MRS: Move to special register from general-purpose register and move
special register to general-purpose register
Moving an immediate data value into a register
Now ; R0=0x3456789A
Contd.
Alternate, LDR (a pseudo-instruction provided in ARM
assembler).
For example, LDR R0, =0x3456789A
For ADR, you can load the address value of a program code into
a register without setting the LSB automatically.
After execution
STR R3,[R1]
After execution
Contd.
LDRD loads a 64-bit value from memory to register
R2=0x00001000 0x00001004 AADDCCEE
0x00001000 44567832
LDRD.W R0, R1, [R2] ;
0x00001024 0000CCDD
STRD.W R0, R1, [R2] ;
0x00001020 0000AABB
• Pre index
• Post index
Pre index
Pre index with
write back
Post index
Contd.
Address Data
0x10001020 50
R0=0x10001010 0x1000101C 40
0x10001018 30
R1=10
R2=20
0x10001014 20
R3=30
0x10001010 10
R0=0x10001010
------------
With updating R0
Address Data
R0=0x10001010
0x10001020 50
R1=10
0x1000101C 40
R2=20
R3=30 0x10001018 30
R0=0x1000101C 0x10001014 20
0x10001010 10
------------
Example of four different memory address
modes for LDM
Example of four different memory address
modes for STM
STMDB same as PUSH operation
07/10/2021 41
Data processing instructions
For example,
MOV R1,#5
LDR R0,=0x1234FFFF
BFC.W R0, #4, #8 ;
31 - - - 13 12 11 10 9 8 7 6 5 44 3 2 1 0
0 00 1 0 0 1 0 0 0 1 1 01 001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
31 - - 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 00 1 0 0 1 0 0 0 1 1 01 001 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1
LDR R0,=0x1234FFFF
BFC.W R0, #8, #8 ;
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
0 00 1 0 01 0 0011 0100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
31 1 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
5 3
0 00 1 0 010 0 011 0 10 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
8+8-1 8
This will give R0 = 0x123400FF
Bit field insert (BFI): Insert bit field to a register
R0
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
0 00 10 0 1 0 00 1 1 0 100 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0
31 23 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 1 1 0 0 1 1 00 11 00 1 0 1 10 10 01 10 1 10 1 0 10 00 1 1 0 0 1 1 0 0
R1
16+8-1 8
LDR R4,=0x12333378,
LDR R0,=0x3355AACC
R4
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
0 00 10 0 1 0 00 1 1 0 011 0 0 1 1 0 0 1 1 0 1 1 1 1 0 0 0
31 23 2 2 1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
21 6
0 0 1 1 0 0 1 1 0 1 10 11 10 01 0 01 1 0 1 0 1 0 1 0 1 1 0 0 1 1 0 0
R0
16+6-1 16 This will give R0 = 0x3338AACC
Bit field extract (BFX) Extract from Rn and
write in Rd
R0
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
0 10 10 1 1 0 01 1 1 1 000 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1
1 0 1 1 1 1 0 0
R1
31 23 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
00 00 10 10 00 00 10 10 00 10 00 10 0 10 0 10 10 0 10 0 10 0 10 01 10 1 1 0 10 1 11 00 00
R0
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
0 10 10 1 1 0 01 1 1 1 000 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1
1 0 1 1 1 1 0 0
R1
31 23 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
10 10 1 1 01 01 1 1 01 1 01 1 01 1 01 1 1 01 1 01 1 01 1 01 10 1 1 0 10 1 11 00 00
R11
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
0 10 10 1 1 0 01 1 1 1 000 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1
0 00 1 0 1 0 1 0 1
R1
31 23 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 01 10 011 0 10 10 101 1 0 1 0 1 0 1 0 1 1 0 0 1 1 0 0
0 0 0 00 000 0 00 00 000 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1
R11
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
0 10 10 1 1 0 01 1 1 1 000 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1
R8
31 23 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 01 10 011 0 10 10 101 1 0 1 0 1 0 1 0 1 1 0 0 1 1 0 0
1 11 11 111 1 11 11 111 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1
For example,
if R1 is 0xB4E10C23
1011_0100_1110_0001_0000_1100_0010_0011
RBIT.W R0, R1
1100_0100_0011_0000_1000_0111_0010_1101
R0 = 0xC430872D
REV
Reverses the byte order in a data word
For example,
if R0 is 0x12345678
REV R2, R0
R0
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
0 00 10 0 1 0 00 1 1 0 100 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0
0 00 10 0 1 000 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0
0 1 1 1 1 0 000 1 0 1 0 1 1 0 00 1 1 0 1 0 0 0 00 10 0 1 0
R2= 0x 78563412
REVH
Reverses the byte order inside a half word.
For example,
if R0 is 0x12345678
REVH R2, R0
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
0 00 10 0 1 0 00 11 0 100 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0
0 00 10 0 1 0 00 1 1 0 100 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0
0 00 10 0 1 000 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 00
00 1 1 0 1 0 00 00 10 0 1 0 0 1 1 1 1 0 0 0 0 1 0 1 0 1 1 0
R2= 0x34127856
REVSH
Processes the lower half word, and then it sign extends the
result word.
For example,
if R0 is 0x33448899,
REVSH R1, R0
R0
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
0 01 10 0 1 1 01 00 0 100 1 0 03 0 1 0 0 0 1 0 0 1 1 0 0 1
0 01 10 0 1 1 01 0 0 0 100 1 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1
1 0 0 0 1 0 0 0 1 0 0 1 1 0 01
1 11 11 1 1 1 11 11 1 111 1 0 0 1 1 0 0 1 1 0 0 0 1 0 0 0
R1= 0xFFFF9988
SXTB, SXTH, UXTB, and UXTH
The four instructions are used to extend a byte or half word data into a word.
00 01 00 01 00 01 00 01 01 00 01 00 01 00 01 00 01 00 00 00 00 01 01 01 00 11 11 00 00 11 00 11
R1 = 0x00000065
10 11 10 11 10 11 10 11 11 10 11 10 11 10 11 10 11 00 00 00 00 11 11 11 00 11 11 00 00 11 00 11
R1 = 0xFFFF8765
Contd.
UXTB R1, R0
if R0 is 0x55AA8765
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
0 10 10 1 0 1 10 1 0 1 010 1 0 0 0 0 1 1 1 0 1 1 0 0 1 0 1
0 00 00 0 0 0 00 0 0 0 000 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 1
R1 = 0x00000065
UXTH R1, R0;
31 - 15 14 1 12 11 10 9 8 7 6 5 4 3 2 1 0
3
00 01 00 01 00 01 00 01 01 00 01 00 01 00 01 00 11 00 00 00 00 11 11 11 00 11 11 00 00 11 00 11
R1 = 0x00008765
Shift and Rotate Instructions
Logical shift left
0 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1
1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 0
1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 0 0
ASR R1, R0, #0x3
1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 0
1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1
1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1
1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0
ASR R1, R0, #0x3
0 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 0
0 0 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1
0 0 0 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1
0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0
Rotate right without carry
1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 0
1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1
1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1
0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0
RRX R1, R0, #0x2
1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1 0
0 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 1
1 0 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1
HAPPY LEARNING
07/10/2021 76