14 - Instruction Encoding
14 - Instruction Encoding
1
Readings and Exercises
• P & H: Sections 2.5, 2.10
• ARM Architecture Reference Manual: Chapter
C4
2
Objective
At the end of this section, you will understand
1. How ARM instructions are encoded
3
Introduction
• All ARMv8 instructions are 32 bits in size
▪ Encodes things such as:
• The opcode
▪ Eg: add, ldr
• The destination and source registers
▪ 1 bit: determines whether 32-bit or 64-bit registers
▪ 5 bits for each register: determines register number
• Remember: 25 = 32
• An immediate value (if used)
• An address (if used)
4
Introduction (cont’d)
• The ARMv8 has several different instruction
formats
▪ Each uses particular fields to encode the needed
information
▪ Some fields are further divided into subfields
5
R-Type Format
• Form:
opcode Rm imm6 Rn Rd
11 bits 5 bits 6 bits 5 bits 5 bits
7
R-Type Format (cont’d)
▪ The left-most bit in the opcode is the size format (sf)
subfield
• 0 indicates 32-bit registers
• 1 indicates 64-bit registers
• Eg: add w19, w0, w1, LSL 3
▪ Machine instruction: 0x0b010c13
00001011000 00001 000011 00000 10011
11 bits 5 bits 6 bits 5 bits 5 bits
8
I-Type Format
• Form:
opcode imm12 Rn Rd
10 bits 12 bits 5 bits 5 bits
9
I-Type Format (cont’d)
• Eg: add w19, w0, 4095
▪ Machine instruction: 0x113ffc13
0001000100 111111111111 00000 10011
10 bits 12 bits 5 bits 5 bits
10
D-Type Format
• Form:
opcode imm9 op2 Rn Rt
11 bits 9 bits 2 bits 5 bits 5 bits
12
B-Type
• Form:
opcode imm26
6 bits 26 bits
14
B-Type (cont’d)
▪ Machine instruction for b top: 0x17fffffd
000101 11 1111 1111 1111 1111 1111 1101
6 bits 26 bits
15
CBI-Type
• Form:
opcode imm19 0 cond
8 bits 19 bits 1 4 bits
18