13.4 x86 and ARM Instruction Formats
COS2621 - Computer Organisation · 13. Instruction Sets: Addressing Modes and Formats
x86 and ARM Instruction Formats
Instruction Formats Overview
An instruction format defines how the bits in an instruction are arranged. This arrangement includes the opcode, which specifies the operation to be performed, and the operands, which specify the data to be used. Different architectures, like x86 and ARM, have distinct instruction formats.
x86 Instruction Format
x86 instructions can vary in length from 1 to 15 bytes. The format generally includes:
- Opcode: Specifies the operation to be performed.
- ModR/M byte: Specifies the addressing mode and the registers involved.
- Displacement: Provides an offset for memory addressing.
- Immediate data: The actual data that may be used in the operation.
For example, consider the instruction mov eax, [ebx + 4]. The breakdown is as follows:
- Opcode: The opcode for the
movinstruction. - ModR/M byte: Indicates that a memory operand is being used (register
ebxwith an offset of 4). - Displacement: The value 4 is the offset added to the base address in
ebx.
ARM Instruction Format
ARM instructions typically have a fixed length of 32 bits. The format includes:
- Opcode: The operation code.
- Condition code: Specifies when the instruction should be executed.
- Registers: Specifies the source and destination registers.
- Immediate value or offset: This can be directly included in the instruction.
For example, the instruction ADD R1, R2, #5 adds the immediate value 5 to the contents of register R2 and stores the result in R1. The components are:
- Opcode: The
ADDoperation. - Registers:
R1andR2. - Immediate value: The value 5.
Comparison of x86 and ARM Formats
x86 supports variable-length instructions, while ARM uses a fixed instruction length. This difference affects the complexity of instruction decoding:
- x86's variable-length instructions require more complex decoding logic.
- ARM's fixed-length instructions simplify the decoding process and improve performance.
Tip: Familiarise yourself with the specific opcode mnemonics for both x86 and ARM to ease your understanding of instruction formats.
Worked Examples
Consider the following assembly language program fragment:
org 0x100
label1: dw 0x76EF
nop
mov ax, ax
nopThis program defines a word at memory location 0x100. The instruction dw 0x76EF reserves 2 bytes in memory. The byte 76h will be stored at position 100h, and EFh at position 101h.
Watch out: In x86 assembly, the lower byte of a word is stored at the lower memory address. Thus, 76h is stored at 100h and EFh at 101h.
Using pseudo-ops, consider:
org 0x100
db 'Q'
dw 213h
db 15In this case, 'Q' is stored at 0000h, 213h at 0001h, and 15 at 0003h. Thus, the relative memory locations are:
- (i)
51hat0000h - (ii)
(15)10at0003h
Summary
- x86 instructions can vary in length and include components such as opcode, ModR/M byte, displacement, and immediate data.
- ARM instructions are fixed at 32 bits and include opcode, condition codes, registers, and immediate values.
- Understanding the differences in instruction formats is crucial for assembly language programming.
Check your understanding
- What are the main components of an x86 instruction format?
- How does the ARM instruction format differ from the x86 format?
- Why might a fixed instruction length be beneficial for performance?
- Give an example of an ARM instruction and explain its components.
Test yourself
5 quick questions on this lesson. Pick an answer to see if you're right.
1. In x86 instruction formats, what does the ModR/M byte indicate?
2. Consider the following pseudo-ops (use NASM): org 0x100 db 'Q' dw 213h db 15 In which relative memory location will (i) 51h and (ii) (15)10 respectively be stored?
3. What is a key advantage of ARM's fixed instruction length compared to x86's variable length?
4. What is the maximum length of an x86 instruction?
5. Consider the following assembly language program fragment: org 0x100 label1: dw 0x76EF nop mov ax,ax nop Which one of the following statements is true?