Quiz 0
Lecture 2: The Instruction Set Architecture
COS / ELE 375
Computer Architecture and Organization
Princeton University
Fall 2015
Prof. David August
- 1
- 2
Quiz 0
CD
3 Miles of Music
- 3
- 4
- Pits and Lands
- Interpretation
- 0
- 1
- 1
- 1
- 0
- 1
- 0
- 1
As Music:
011101012 = 117/256 position of speaker
As Number:
Transition represents a bit state (1/on/red/female/heads)
No change represents other state (0/off/white/male/tails)
011101012 = 1 + 4 + 16 + 32 + 64 = 11710 = 7516 (Get comfortable with base 2, 8, 10, and 16.)
As Text:
011101012 = 117th character in the ASCII codes = “u”
- 5
- 6
- Interpretation – ASCII
- Princeton Computer Science Building West Wall
- 7
- 8
Interpretation
Binary Code and Data (Hello World!)
•ꢀ Programs consist of Code and Data •ꢀ Code and Data are Encoded in Bits
IA-64 Binary (objdump)
As Music:
011101012 = 117/256 position of speaker
As Number:
011101012 = 1 + 4 + 16 + 32 + 64 = 11710 = 7516
As Text:
011101012 = 117th character in the ASCII codes = “u”
CAN ALSO BE INTERPRETED AS MACHINE INSTRUCTION!
9
- Interfaces in Computer Systems
- Instructions
Sequential Circuit!!
Software: Produce Bits Instructing Machine to Manipulate State or Produce I/O
State
Computers process information
•ꢀ Input/Output (I/O)
Applications
•ꢀ State (memory)
Operating System
•ꢀ Computation (processor)
Compiler
Firmware
Instruction Set Architecture
- Output
- Input
- Instruction Set Processor
- I/O System
Datapath & Control Digital Design Circuit Design
Layout
Computation
•ꢀ Instructions instruct processor to manipulate state •ꢀ Instructions instruct processor to produce I/O in the same way
Hardware: Read and Obey Instruction Bits
12
State
State – Main Memory
Typical modern machine has this architectural state: 1.ꢀ Main Memory
Main Memory (AKA: RAM – Random Access Memory) •ꢀ Data can be accessed by address (like a big array)
- •ꢀ Large but relatively slow
- 2.ꢀ Registers
- 3.ꢀ Program Counter
- •ꢀ Decent desktop machine: 1 Gigabyte, 800MHz
Address
0000 0001 0002 0003
…
Data
010110012
F516
Architectural – Part of the assembly programmer’s interface (Implementation has additional microarchitectural state)
7816 3A16
…
- FFFF
- 000000002
Byte Addressable
- 13
- 14
- State – Main Memory
- State – Main Memory
Address
0000 0001 0002 0003
…
Data
010110012
F516
Address
0000 0001 0002 0003
…
Data
010110012
F516
- Read:
- Write:
1.ꢀ Indicate WRITE 2.ꢀ Give Address and Data
1.ꢀ Indicate READ 2.ꢀ Give Address 3.ꢀ Get Data
- 7816
- 7816
3A16
3A
121166
- …
- …
- FFFF
- 000000002
- FFFF
- 000000002
- Read/Write
- Read/Write
- WRITE
- READ
0002
Address
Data
Address
0003
Data
1216
7816
- 15
- 16
State – Registers
State – Program Counter
Registers (AKA: Register File)
Program Counter (AKA: PC, Instruction Pointer, IP) •ꢀ Instructions change state, but which instruction now?
•ꢀ Data can be accessed by register number (address) •ꢀ Small but relatively fast (typically on processor chip) •ꢀ Decent desktop machine: 8 32-bit registers, 3 GHz
•ꢀ PC holds memory address of currently executing instruction
- Register
- Data in Reg
0000000016 F629D9B516 7B2D9D0816 0000000116
…
Address
0000 0001 0002 0003
…
Data in Memory
010110012
F516
01
Program Counter
0002
2
ADDinst
3
SUBTRACTinst
…
…
- 8
- DEADBEEF16
- FFFF
- 000000002
- 17
- 18
State – Program Counter
State – Summary
Program Counter (AKA: PC, Instruction Pointer, IP) •ꢀ Instructions change state, but which instruction now? •ꢀ PC holds address of currently executing instruction
•ꢀ PC is updated after each instruction
Typical modern machine has this architectural state: 1.ꢀ Main Memory – Big, Slow 2.ꢀ Registers – Small, Fast (always on processor chip) 3.ꢀ Program Counter – Address of executing instruction
Address
0000 0001 0002 0003
…
Data in Memory
010110012
F516
Architectural – Part of the assembly programmer’s
Program Counter
0003
interface
(implementation has additional microarchitectural state)
ADDinst
SUBTRACTinst
…
- FFFF
- 000000002
- 19
- 20
- An Aside: State and The Core Dump
- Interfaces in Computer Systems
Software: Produce Bits Instructing Machine to Manipulate State or Produce I/O
•ꢀ Core Dump: the state of the machine at a given time
•ꢀ Typically at program failure
Applications
Registers
Operating System
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
0000 0788 B700 0010 0401 0002 0003 00A0
•ꢀ Core dump contains:
•ꢀ Register Contents •ꢀ Memory Contents •ꢀ PC Value
PC
10
- 8
- 9
- A
- B
- C
- D
- E
- F
Compiler
Firmware
0000 0788 B700 0010 0401 0002 0003 00A0
Instruction Set Architecture
Main Memory
- Instruction Set Processor
- I/O System
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 9222 9120 1121 A120 1121 A121 7211 0000 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 000A 000B 000C 000D 000E 000F 0000 0000 0000 FE10 FACE CAFE ACED CEDE
00:
08: 10: 18: 20: 28:
.
Datapath & Control Digital Design Circuit Design
Layout
.
1234 5678 9ABC DEF0 0000 0000 F00D 0000 0000 0000 EEEE 1111 EEEE 1111 0000 0000 B1B2 F1F5 0000 0000 0000 0000 0000 0000
E8: F0: F8:
Hardware: Read and Obey Instruction Bits
21
Instructions
Instructions
- Register
- Data
0
- An ADD Instruction:
- Instructions:
“The vocabulary of commands” Specify how to operate on state
01add r1 = r2 + r3 (assembly)
15
- 1
- 2
- 3
- 2
- Opcode
- Operands
…
…0
Example:
31
40: add r1 = r2 + r3
44: sub r3 = r1 - r0 48: store M[ r3 ] = r1 52: load r2 = M[ 2 ]
Parts of the Instruction:
- Address
- Data
0
•ꢀ Opcode (verb) – what operation to perform •ꢀ Operands (noun) – what to operate upon •ꢀ Source Operands – where values come from •ꢀ Destination Operand – where to deposit data values
0
- 1
- 25
- 5
- 2
Program Counter
40
- 3
- 9
…
…
- 0
- FFFFFFFF
- Instructions
- Instructions
- Register
- Data
0
- Register
- Data
Instructions:
01
01
0
3
15
“The vocabulary of commands” Specify how to operate on state
1
- 1
- 2
- 2
- 1
2
- 2
- 3
- 3
- 2
…
…0
…
…0
- Example:
- Example:
- 31
- 31
- 40: add r1 = r2 + r3
- 40: add r1 = r2 + r3
3
44: sub r3 = r1 - r0 48: store M[ r3 ] = r1 52: load r2 = M[ 2 ]
44: sub r3 = r1 - r0 48: store M[ r3 ] = r1 52: load r2 = M[ 2 ]
- Address
- Data
0
- Address
- Data
- 0
- 0
1
0
- 1
- 25
5
25
- 5
- 2
- 2
Program Counter
40
Program Counter
40
- 3
- 9
- 3
- 9
- …
- …
…0
…
- 0
- FFFFFFFF
- FFFFFFFF
Instructions
Instructions
- Register
- Data
- Register
- Data
0
Instructions: “The vocabulary of commands” Specify how to operate on state
Instructions: “The vocabulary of commands” Specify how to operate on state
01
03
01
3
3
- 2
- 1
- 2
- 1
3
- 3
- 3
- 2
- 3
- …
- …
…0
…0
- Example:
- Example:
- 31
- 31
- 40: add r1 = r2 + r3
- 40: add r1 = r2 + r3
3
44: sub r3 = r1 - r0
44: sub r3 = r1 - r0
48: store M[ r3 ] = r1
52: load r2 = M[ 2 ]
- Address
- Data
0
- Address
- Data
0
48: store M[ r3 ] = r1 52: load r2 = M[ 2 ]
3
01
0
- 1
- 25
5
25
- 5
- 2
- 2
Program Counter
44
Program Counter
48
- 3
- 9
- 3
- 9
- …
- …
…0
…
- 0
- FFFFFFFF
- FFFFFFFF
- Instructions
- Instructions
- Register
- Data
- Register
- Data
Instructions: “The vocabulary of commands” Specify how to operate on state
Instructions: “The vocabulary of commands” Specify how to operate on state
01
03
01
03
- 2
- 1
- 2
- 5
- 3
- 3
- 3
- 3
- …
- …
…0
…0
- Example:
- Example:
- 31
- 31
40: add r1 = r2 + r3
44: sub r3 = r1 - r0 48: store M[ r3 ] = r1
40: add r1 = r2 + r3 44: sub r3 = r1 - r0 48: store M[ r3 ] = r1 52: load r2 = M[ 2 ]
- Address
- Data
0
- Address
- Data
- 0
- 0
1
01
52: load r2 = M[ 2 ]
5
25
5
25
- 5
- 2
- 2
Program Counter
52
Program Counter
52
- 3
- 3
- 3
- 3
- …
- …
…0
…
- 0
- FFFFFFFF
- FFFFFFFF
- Instructions
- Assembly Instructions and C
- Register
- Data
main() {
Note:
01
03
int a = 15, b = 1, c = 2; a = b + c; /* a gets 3 */ c = a; /* c gets 3 */
1.ꢀ Insts Executed in Order 2.ꢀ Addressing Modes
- 2
- 5
add r1 = r2 + r3 sub r3 = r1 - r0 store M[ r3 ] = r1
- 3
- 3
…
…0
Example:
31
40: add r1 = r2 + r3
44: sub r3 = r1 - r0 48: store M[ r3 ] = r1 52: load r2 = M[ 2 ]
*(int *)c = a;
/* M[c] = a */
- Address
- Data
- 0
- 0
- 1
- 25
5
- load r2 = M[ 2 ]
- b = *(int *)(2);
/* b gets M[2] */
2
Program Counter
52
- 3
- 3
}
…
…
- 0
- FFFFFFFF
Branching
Suppose we could only execute instructions in sequence. Recall from our example:
40: add r1 = r2 + r3 44: sub r3 = r1 - r0 48: store M[ r3 ] = r1 52: load r2 = M[ 2 ]
•ꢀ In a decent desktop machine, how long would the longest program stored in main memory take?
•ꢀ Assume:
•ꢀ 1 instruction per cycle •ꢀ An instruction is encoded in 4 bytes (32 bits)
- 33
- 34
Therefore…
Unconditional Branches
- •ꢀ Some instructions must execute more than once
- •ꢀ Unconditional branches always update the PC
- •ꢀ PC must be updated
- •ꢀ AKA: Jump instructions
- Example:
- Example:
40: add r1 = r2 + r3 44: sub r3 = r1 - r0 48: store M[ r3 ] = r1 52: load r2 = M[ 2 ] 56: PC = 40
40: add r1 = r2 + r3 44: sub r3 = r1 - r0 48: store M[ r3 ] = r1 52: load r2 = M[ 2 ] 56: jump 40
•ꢀ How long with the program take?
- 35
- 36
- Conditional Branch
- Conditional Branch
•ꢀ What does this look like in C?
•ꢀ Conditional Branch sometimes updates PC