COMPUTER ORGANIZATION AND DESIGN ARM
Edition
The Hardware/Software Interface
Chapter 2
Instructions: Language
of the Computer
Lecture 3: ECE4206 Intro to Microprocessors
§2.1 Introduction
Instruction Set
◼ The language of the computer is the instruction, and the
vocabulary is the instruction set.
◼ The repertoire of instructions of a computer
◼ Different computers have different instruction sets
◼ But with many aspects in common
◼ Early computers had very simple instruction sets
◼ Simplified implementation
◼ Many modern computers also have simple instruction
sets
Chapter 2 — Instructions: Language of the Computer — 2
The ARMv8 Instruction Set
◼ A subset, called LEGv8, used as the example
throughout the book
◼ Commercialized by ARM Holdings
(www.arm.com)
◼ Large share of embedded core market
◼ Applications in consumer electronics, network/storage
equipment, cameras, printers, …
◼ Typical of many modern ISAs
◼ See ARM Reference Data tear-out card
Chapter 2 — Instructions: Language of the Computer — 3
§2.2 Operations of the Computer Hardware
Arithmetic Operations
◼ Add and subtract, three operands
◼ Two sources and one destination
ADD a, b, c // a gets b + c
◼ All arithmetic operations have this form
◼ Design Principle 1: Simplicity favours
regularity
◼ Regularity makes implementation simpler
◼ Simplicity enables higher performance at
lower cost
Chapter 2 — Instructions: Language of the Computer — 4
Arithmetic Example
◼ C code:
f = (g + h) - (i + j);
◼ Compiled LEGv8 code:
ADD t0, g, h // temp t0 = g + h
ADD t1, i, j // temp t1 = i + j
SUB f, t0, t1 // f = t0 - t1
Chapter 2 — Instructions: Language of the Computer — 5
§2.3 Operands of the Computer Hardware
Register Operands
◼ Arithmetic instructions use register operands.
◼ LEGv8 has a 32 × 64-bit register file
◼ Use for frequently accessed data
◼ 64-bit data is called a “doubleword”
◼ 31 x 64-bit general purpose registers X0 to X30
◼ 32-bit data called a “word”
◼ 31 x 32-bit general purpose sub-registers W0 to W30
◼ Design Principle 2: Smaller is faster
◼ c.f. main memory: millions of locations
Chapter 2 — Instructions: Language of the Computer — 6
LEGv8 Registers
◼ X0 – X7: procedure arguments/results
◼ X8: indirect result location register
◼ X9 – X15: temporaries
◼ X16 – X17 (IP0 – IP1): may be used by linker as a
scratch register, other times as temporary register
◼ X18: platform register for platform independent code;
otherwise a temporary register
◼ X19 – X27: saved
◼ X28 (SP): stack pointer
◼ X29 (FP): frame pointer
◼ X30 (LR): link register (return address)
◼ XZR (register 31): the constant value 0
Chapter 2 — Instructions: Language of the Computer — 7
Register Operand Example
◼ C code:
f = (g + h) - (i + j);
◼ f, …, j in X19, X20, …, X23
◼ Compiled LEGv8 code:
ADD X9, X20, X21
ADD X10, X22, X23
SUB X19, X9, X10
Chapter 2 — Instructions: Language of the Computer — 8
Memory Operands
◼ Main memory used for composite data
◼ Arrays, structures, dynamic data
◼ To apply arithmetic operations
◼ Load values from memory into registers using data
transfer instruction
◼ Store results from register to memory
◼ Memory is byte addressed
◼ Each address identifies an 8-bit byte
◼ LEGv8 does not require words to be aligned in
memory, except for instructions and the stack
Chapter 2 — Instructions: Language of the Computer — 9
Memory Operands
• To access a word or doubleword in memory,
the instruction must supply the memory
address.
• Memory is just a large, single-dimensional
array, with the address acting as the index
to that array, starting at 0.
• The address of the third data element is 2,
and the value of memory [2] is 10.
Actual LEGv8 memory addresses & contents of memory
for those doublewords.
Chapter 2 — Instructions: Language of the Computer — 10
Memory Operand Example
Chapter 2 — Instructions: Language of the Computer — 11
Memory Operand Example
◼ C code:
A[12] = h + A[8];
◼ h in X21, base address of A in X22
◼ Compiled LEGv8 code:
◼ Index 8 requires offset of 64
LDUR X9,[X22,#64] // U for “unscaled”
ADD X9,X21,X9
STUR X9,[X22,#96]
Chapter 2 — Instructions: Language of the Computer — 12
Registers vs. Memory
◼ Registers are faster to access than
memory
◼ Operating on memory data requires loads
and stores
◼ More instructions to be executed
◼ Compiler must use registers for variables
as much as possible
◼ Only spill to memory for less frequently used
variables (spilling registers process)
◼ Register optimization is important!
Chapter 2 — Instructions: Language of the Computer — 13
Immediate Operands
◼ Constant data specified in an instruction
ADDI X22, X22, #4
◼ Design Principle 3: Make the common
case fast
◼ Small constants are common
◼ Immediate operand avoids a load instruction
Chapter 2 — Instructions: Language of the Computer — 14