Professional Documents
Culture Documents
Instruction Set Architecture
Instruction Set Architecture
and Architecture
ITT 303
Instruction Set Architecture: Registers, Instructions,
Addressing Modes, Condition Codes
https://www.janibbashir.com/coa-autumn2023
ISA vs Microarchitecture
2
What is a computer?
3
Working
Three key components
• Computation
Information • Communication
Program • Storage (memory)
store
Computer
results
6
ISA Components
■ Instructions
❑ Opcodes, Addressing Modes, Data Types
❑ Instruction Types and Formats
❑ Registers, Condition Codes
■ Memory
❑ Address space, Addressability, Alignment
❑ Virtual memory management
■ Call, Interrupt/Exception Handling
■ Access Control, Priority/Privilege
■ I/O: memory-mapped vs. instr.
■ Task/thread Management
■ Power and Thermal Management
■ Multi-threading support, Multiprocessor support
7
Microarchitecture
■ Implementation of the ISA under specific design constraints and goals
■ Anything done in hardware without exposure to software
❑ Pipelining
❑ In-order versus out-of-order instruction execution
❑ Memory access scheduling policy
❑ Speculative execution
❑ Superscalar processing (multiple instruction issue?)
❑ Clock gating
❑ Caching? Levels, size, associativity, replacement policy
❑ Prefetching?
❑ Voltage/frequency scaling?
❑ Error correction?
8
Memory
View of Memory
❑ One large array of memory cells. Each cell can store a single bit 0 or 1.
❑ A group of bits can be stored or retrieved in a single operation - word, wordlength
❑ Address space: How many uniquely identifiable locations in memory.
❑ Addressability: How much data does each uniquely identifiable location store
❑ Byte addressable: most ISAs, characters are 8 bits - Each byte has an address
❑ Bit addressable: Burroughs 1700. Why?
❑ 64-bit addressable: Some supercomputers. Why?
❑ 32-bit addressable: First Alpha
❑ Food for thought
❑ How do you add 2 32-bit numbers with only byte addressability?
❑ How do you add 2 8-bit numbers with only 32-bit addressability?
9
Memory
Storage of Data in Memory
■ Data Types
❑ char (1 byte), short (2 bytes), int (4 bytes), long int (8 bytes)
10
Memory
Little Endian vs Big Endian
Big endian
87 65 43 21
0 1 2 3
0x87654321
Little endian
21 43 65 87
0 1 2 3
11
Memory
Storage of Arrays in Memory
■ Single dimensional arrays. Consider an array of integers : a[100]
12
Memory
Row Major vs Column Major
■ Row Major (C, Python)
❑ Store the first row as an 1D array
❑ Then store the second row, and so on...
■ Column Major (Fortran, Matlab)
❑ Store the first column as an 1D array
❑ Then store the second column, and so on
■ Multidimensional arrays
❑ Store the entire array as a sequence of 1D arrays
13
The Von Neumann Model/Architecture
■ Also called stored program computer (instructions in memory). Two
key properties:
❑ Stored program
■ Instructions stored in a linear memory array
■ Memory is unified between instructions and data
❑ The interpretation of a stored value depends on the control signals
When is a value interpreted as an instruction?
❑ Sequential instruction processing
■ One instruction processed (fetched, executed, and completed) at a time
■ Program counter (instruction pointer) identifies the current instr.
■ Program counter is advanced sequentially except for control transfer instructions
14
Instruction set
Instruction Set
The semantics of all the instructions supported by a processor is known as its instruction set
architecture (ISA). This includes the semantics of the instructions themselves, along with their
operands, and interfaces with peripheral devices.
❑ Registers
❑ Instructions
❑ Instruction Sequencing
❑ Addressing Modes
❑ Condition Codes
15
Instruction set
View of Registers
■ Registers → named storage locations
❑ in ARM : r0, r1, … r15
❑ in x86 : eax, ebx, ecx, edx, esi, edi
■ Machine specific registers (MSR)
❑ Examples : Control the machine such as the speed of fans, power control
settings
❑ Read the on-chip temperature.
■ Registers with special functions :
❑ stack pointer
❑ program counter
❑ return address
16
Instruction set
Why Registers?
■ Registers
❑ How many
❑ Size of each register
17
Instruction set
Programmer Visible (Architectural) State
M[0]
M[1]
M[2]
M[3] Registers
M[4] - given special names in the ISA
(as opposed to addresses)
- general vs. special purpose
M[N-1]
Memory Program Counter
array of storage locations
indexed by an address memory address
of the current instruction
Instructions (and programs) specify how to transform
the values of programmer visible state
18
Instruction set
Aside: Programmer Invisible State
■ Microarchitectural state
■ Programmer cannot access this directly
19
Instruction set
Evolution of Register Architecture
■ Accumulator
❑ a legacy from the “adding” machine days
20
Instruction set
Instructions and Instruction Sequencing
❑ A computer must have instructions capable of performing four types of operations:
❑ Data transfers between the memory and the processor registers
❑ Arithmetic and logic operations on data
❑ Program sequencing and control
❑ I/O transfers operand 1 operand n
Instruction operand 2
■ instruction or opcode
❑ textual identifier of a machine instruction
■ operand
❑ constant (also known as an immediate)
❑ register
❑ memory location
■ To facilitate the discussion let us first discuss two important notations - Register Transfer Notation and
Assembly Language Notation
21
Dataflow Model (of a Computer)
■ Von Neumann model: An instruction is fetched and executed in control flow
order
❑ As specified by the instruction pointer
❑ Sequential unless explicit control flow instruction
22
Instruction set
Register Transfer Notation
■ This notation allows us to specify the semantics of instructions
■ r1 ← [r2]
❑ transfer the contents of register r2 to register r1
■ r1 ← [r2] + 4
❑ add 4 to the contents of register r2, and transfer the contents to register r1
■ r1 ← [[r2]]
❑ access the memory location that matches the contents of r2, and store the data in register r1
23
Instruction set
What is Assembly Language
* A low level programming language uses simple statements that correspond to typically
just one machine instruction. These languages are specific to the ISA.
* The term “assembly language” refers to a family of low-level programming languages that
are specific to an ISA. They have a generic structure that consists of a sequence of
assembly statements.
* Typically, each assembly statement has two parts: (1) an instruction code that is a
mnemonic for a basic machine instruction, and (2) and a list of operands.
24
Instruction set
Why learn Assembly Language ?
25
Instruction set
Assemblers
26
Instruction set
Hardware Designers Perspective
27
Instruction set
Examples of Instructions
28
Instruction set
Features of an ISA
* Complete
* It should be able to implement all the programs that users may write.
* Concise
* The instruction set should have a limited size. Typically an ISA contains 32-1000
instructions.
* Generic
* Instructions should not be too specialized, e.g. add14 (adds a number with 14)
instruction is too specialized
* Simple
* Should not be very complicated.
29
Instruction set
Designing an ISA
* Important questions that need to be answered :
* How many instructions should we have ?
* What should they do ?
* How complicated should they be ?
30
Instruction set
RISC vs CISC - I
31
Instruction set
RISC vs CISC - II
■ RISC machines follow load/store architecture whereas CISC follow
memory/memory architecture.
■ Load/store vs. memory/memory architectures
❑ Load/store architecture: operate instructions operate only on registers and they use
load and store instructions to access the memory.
■ E.g., MIPS, ARM and many RISC ISAs
32
Instruction sequencing
Instruction Sequencing - I
■ All the instructions are initially placed in the computer memory - stored
program execution.
■ Instructions are fetched and executed in control flow order
❑ As specified by the instruction pointer or program counter (stores address of the
next instruction to be executed).
❑ The instrucion fetched from memory is placed in register called Instruction
Register.
❑ Sequential or straight line execution unless explicit control flow instruction
(branch instructions).
❑ Branch instruction may load a new address in the PC (branch target address).
❑ Conditional Branch and Unconditional Branch.
33
Instruction sequencing
Instruction Sequencing - II
❑ Or an instruction is fetched and executed in data flow order
❑ i.e., when its operands are ready
❑ i.e., there is no instruction pointer
❑ Instruction ordering specified by data flow dependence
■ Each instruction specifies “who” should receive the result
■ An instruction can “fire” whenever all operands are received
❑ Potentially many instructions can execute at the same time
■ Inherently more parallel
34
Instruction sequencing
Instruction Processing Style
❑ Specifies the number of “operands” an instruction “operates” on and how it does
so
❑ 0, 1, 2, 3 address machines
■ 0-address: stack machine (push A, pop A, op)
■ 1-address: accumulator machine (ld A, st A, op A)
■ 2-address: 2-operand machine (one is both source and dest)
■ 3-address: 3-operand machine (source and dest are separate).
■ Specify the operands to an instruction - Addressing modes
❑ Helps to locate the operands.
❑ Determines the access mechanism.
35
Addressing Modes
Addressing Modes
■ The different ways for specifying the locations of instruction operands are known as addressing modes.
■ Let V be the value of an operand, and let r1, r2 specify registers
■ Immediate addressing mode
❑ V ← imm , e.g. 4, 8, 0x13, -3
■ Register indirect
❑ V ← [r1]
36
Addressing Modes
Register Indirect Mode
■ V ← [r1]
r1
value
register file
memory
37
Addressing Modes
Base-offset Addressing Mode
■ V ← [r1+offset]
r1
offset
value
register file
memory
38
Addressing Modes
Addressing Modes - II
■ Base-index-offset
❑ V ← [r1 + r2 + offset]
❑ example: 100[r1,r2] (V ← [r1 + r2 + 100])
■ Memory Direct
❑ V ← [addr]
❑ example : [0x12ABCD03]
■ PC Relative
❑ V ← [pc + offset]
❑ example: 100[pc] (V ← [pc + 100])
39
Addressing Modes
Base-Index-Offset Addressing Mode
■ V ← [r1+r2 +offset]
r1
offset
r2
value
register file
memory
40
Addressing Modes
Benefits of Different Addressing Modes
■ Another example of programmer vs. microarchitect tradeoff
■ Disadvantage:
❑ More work for the compiler
❑ More work for the microarchitect
41
Addressing Modes
ISA Orthogonality
■ Orthogonal ISA:
❑ All addressing modes can be used with all instruction types
❑ Example: VAX
■ (~13 addressing modes) x (>300 opcodes) x (integer and FP formats)
42
Condition Codes
Condition Codes
■ Processor needs to store the status of the different operations.
■ This information is required subsequently by the branch instructions.
■ This is accomplished by recording the required information in individual bits,
often called condition code flags.
■ These flags are usually grouped together in a special processor register called
the condition code register or status register.
■ N (negative)
■ Z (zero)
■ V (overflow)
■ C (carry)
43
Many Different ISAs Over Decades
■ x86
■ PDP-x: Programmed Data Processor (PDP-11)
■ VAX
■ IBM 360
■ CDC 6600
■ SIMD ISAs: CRAY-1, Connection Machine
■ VLIW ISAs: Multiflow, Cydrome, IA-64 (EPIC)
■ PowerPC, POWER
■ RISC ISAs: Alpha, MIPS, SPARC, ARM
■ What are the fundamental differences?
❑ E.g., how instructions are specified and what they do
❑ E.g., how complex are the instructions
44
END
45