Y86 encoding / SEQ part 1 1 last time instruction set (interface) - - PowerPoint PPT Presentation

y86 encoding seq part 1
SMART_READER_LITE
LIVE PREVIEW

Y86 encoding / SEQ part 1 1 last time instruction set (interface) - - PowerPoint PPT Presentation

Y86 encoding / SEQ part 1 1 last time instruction set (interface) v microarchitecture (implementation) RISC (simpler HW) v CISC (more fmexible ASM) Y86-64 ISA started Y86 encoding 3 Y86-64 instruction formats 9 0 rA rB OP q rA, rB 6 fn rA


slide-1
SLIDE 1

Y86 encoding / SEQ part 1

1

slide-2
SLIDE 2

last time

instruction set (interface) v microarchitecture (implementation) RISC (simpler HW) v CISC (more fmexible ASM) Y86-64 ISA started Y86 encoding

3

slide-3
SLIDE 3

Y86-64 instruction formats

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

4

slide-4
SLIDE 4

Secondary opcodes: cmovcc/jcc

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest 0 always (jmp/rrmovq) 1 le 2 l 3 e 4 ne 5 ge 6 g

5

slide-5
SLIDE 5

Secondary opcodes: OPq

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

add

1

sub

2

and

3

xor

6

slide-6
SLIDE 6

Registers: rA, rB

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

%rax

8

%r8

1

%rcx

9

%r9

2

%rdx

A

%r10

3

%rbx

B

%r11

4

%rsp

C

%r12

5

%rbp

D

%r13

6

%rsi

E

%r14

7

%rdi

F

none

7

slide-7
SLIDE 7

Immediates: V, D, Dest

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

8

slide-8
SLIDE 8

Immediates: V, D, Dest

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

8

slide-9
SLIDE 9

Y86-64 encoding (1)

long addOne(long x) { return x + 1; } x86-64: movq %rdi, %rax addq $1, %rax ret Y86-64: irmovq $1, %rax addq %rdi, %rax ret

9

slide-10
SLIDE 10

Y86-64 encoding (1)

long addOne(long x) { return x + 1; } x86-64: movq %rdi, %rax addq $1, %rax ret Y86-64: irmovq $1, %rax addq %rdi, %rax ret

9

slide-11
SLIDE 11

Y86-64 encoding (2)

addOne: irmovq $1, %rax addq %rdi, %rax ret ⋆

3 F %rax 01 00 00 00 00 00 00 00

30 F0 01 00 00 00 00 00 00 00 60 70 90

10

slide-12
SLIDE 12

Y86-64 encoding (2)

addOne: irmovq $1, %rax addq %rdi, %rax ret ⋆

3 F 01 00 00 00 00 00 00 00

30 F0 01 00 00 00 00 00 00 00 60 70 90

10

slide-13
SLIDE 13

Y86-64 encoding (2)

addOne: irmovq $1, %rax addq %rdi, %rax ret

3 F 01 00 00 00 00 00 00 00

6 add %rdi %rax

30 F0 01 00 00 00 00 00 00 00 60 70 90

10

slide-14
SLIDE 14

Y86-64 encoding (2)

addOne: irmovq $1, %rax addq %rdi, %rax ret

3 F 01 00 00 00 00 00 00 00

6 7

30 F0 01 00 00 00 00 00 00 00 60 70 90

10

slide-15
SLIDE 15

Y86-64 encoding (2)

addOne: irmovq $1, %rax addq %rdi, %rax ret

3 F 01 00 00 00 00 00 00 00 6 7

9

30 F0 01 00 00 00 00 00 00 00 60 70 90

10

slide-16
SLIDE 16

Y86-64 encoding (2)

addOne: irmovq $1, %rax addq %rdi, %rax ret

3 F 01 00 00 00 00 00 00 00 6 7 9

30 F0 01 00 00 00 00 00 00 00 60 70 90

10

slide-17
SLIDE 17

Y86-64 encoding (3)

doubleTillNegative: /* suppose at address 0x123 */ addq %rax, %rax jge doubleTillNegative

6 add %rax %rax

11

slide-18
SLIDE 18

Y86-64 encoding (3)

doubleTillNegative: /* suppose at address 0x123 */ addq %rax, %rax jge doubleTillNegative ⋆

6 add %rax %rax

11

slide-19
SLIDE 19

Y86-64 encoding (3)

doubleTillNegative: /* suppose at address 0x123 */ addq %rax, %rax jge doubleTillNegative ⋆

6

11

slide-20
SLIDE 20

Y86-64 encoding (3)

doubleTillNegative: /* suppose at address 0x123 */ addq %rax, %rax jge doubleTillNegative

6 7 5 23 01 00 00 00 00 00 00

11

slide-21
SLIDE 21

Y86-64 encoding (3)

doubleTillNegative: /* suppose at address 0x123 */ addq %rax, %rax jge doubleTillNegative

6

7 5 23 01 00 00 00 00 00 00

11

slide-22
SLIDE 22

Y86-64 encoding (3)

doubleTillNegative: /* suppose at address 0x123 */ addq %rax, %rax jge doubleTillNegative

6 7 5 23 01 00 00 00 00 00 00

11

slide-23
SLIDE 23

Y86-64 decoding

20 10 60 20 61 37 72 84 00 00 00 00 00 00 00 20 12 20 01 70 68 00 00 00 00 00 00 00 rrmovq %rcx, %rax addq %rdx, %rax subq %rbx, %rdi jl 0x84 rrmovq %rcx, %rdx rrmovq %rax, %rcx jmp 0x68

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

12

slide-24
SLIDE 24

Y86-64 decoding

20 10 60 20 61 37 72 84 00 00 00 00 00 00 00 20 12 20 01 70 68 00 00 00 00 00 00 00 rrmovq %rcx, %rax addq %rdx, %rax subq %rbx, %rdi jl 0x84 rrmovq %rcx, %rdx rrmovq %rax, %rcx jmp 0x68

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

12

slide-25
SLIDE 25

Y86-64 decoding

20 10 60 20 61 37 72 84 00 00 00 00 00 00 00 20 12 20 01 70 68 00 00 00 00 00 00 00 rrmovq %rcx, %rax

◮ 0 as cc: always ◮ 1 as reg: %rcx ◮ 0 as reg: %rax

addq %rdx, %rax subq %rbx, %rdi jl 0x84 rrmovq %rcx, %rdx rrmovq %rax, %rcx jmp 0x68

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

12

slide-26
SLIDE 26

Y86-64 decoding

20 10 60 20 61 37 72 84 00 00 00 00 00 00 00 20 12 20 01 70 68 00 00 00 00 00 00 00 rrmovq %rcx, %rax addq %rdx, %rax subq %rbx, %rdi

◮ 0 as fn: add ◮ 1 as fn: sub

jl 0x84 rrmovq %rcx, %rdx rrmovq %rax, %rcx jmp 0x68

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

12

slide-27
SLIDE 27

Y86-64 decoding

20 10 60 20 61 37 72 84 00 00 00 00 00 00 00 20 12 20 01 70 68 00 00 00 00 00 00 00 rrmovq %rcx, %rax addq %rdx, %rax subq %rbx, %rdi jl 0x84

◮ 2 as cc: l (less than) ◮ hex 84 00… as little endian Dest: 0x84

rrmovq %rcx, %rdx rrmovq %rax, %rcx jmp 0x68

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

12

slide-28
SLIDE 28

Y86-64 decoding

20 10 60 20 61 37 72 84 00 00 00 00 00 00 00 20 12 20 01 70 68 00 00 00 00 00 00 00 rrmovq %rcx, %rax addq %rdx, %rax subq %rbx, %rdi jl 0x84 rrmovq %rcx, %rdx rrmovq %rax, %rcx jmp 0x68

byte: 1 2 3 4 5 6 7 8 9 halt nop 1 rrmovq/cmovCC rA, rB 2 cc rA rB irmovq V, rB 3 F rB rmmovq rA, D(rB) 4 0 rA rB mrmovq D(rB), rA 5 0 rA rB OPq rA, rB 6 fn rA rB jCC Dest 7 cc call Dest 8 ret 9 pushq rA A 0 rA F popq rA B 0 rA F V D D Dest Dest

12

slide-29
SLIDE 29

circuits: wires

1 1 1 1 1 1 binary value — actually voltage value propagates to rest of wire (small delay)

13

slide-30
SLIDE 30

circuits: wires

1 1 1 1 1 1 binary value — actually voltage value propagates to rest of wire (small delay)

13

slide-31
SLIDE 31

circuits: wires

1 1 1 1 1 1 binary value — actually voltage value propagates to rest of wire (small delay)

13

slide-32
SLIDE 32

circuits: wire bundles

1 1 1 1 1 1 11010 = 26 same as 26 26 same as 26 26

14

slide-33
SLIDE 33

circuits: wire bundles

1 1 1 1 1 1 11010 = 26 same as 26 26 same as 26 26

14

slide-34
SLIDE 34

circuits: wire bundles

1 1 1 1 1 1 11010 = 26 same as 26 26 same as 26 26

14

slide-35
SLIDE 35

circuits: gates

1 1 1 1 1 1

15

slide-36
SLIDE 36

circuits: logic

want to do calculations? generalize gates:

  • utput wires contain result of function on input

changes as input changes (with delay)

need not be same width as output

“logic” 12 function(12) = ??

16

slide-37
SLIDE 37

circuits: logic

want to do calculations? generalize gates:

  • utput wires contain result of function on input

changes as input changes (with delay)

need not be same width as output

“logic” 12 function(12) = ??

16

slide-38
SLIDE 38

circuits: logic

want to do calculations? generalize gates:

  • utput wires contain result of function on input

changes as input changes (with delay)

need not be same width as output

“logic” 12 function(12) = ??

16

slide-39
SLIDE 39

example: (broken) counter circuit

add 1 time 0: 000 in between value???

time 1 time 2

1 1 briefmy 011??? halfway voltages??? how will add 1 circuit act??? circuit is not stable transient values during changes hard to predict behavior

17

slide-40
SLIDE 40

example: (broken) counter circuit

add 1 time 0: 000 in between value???

time 1 time 2

1 1 briefmy 011??? halfway voltages??? how will add 1 circuit act??? circuit is not stable transient values during changes hard to predict behavior

17

slide-41
SLIDE 41

example: (broken) counter circuit

add 1 time 0: 000 time 1: 001? time 2: 010? time 3: 011? in between value???

time 1 time 2

1 1 briefmy 011??? halfway voltages??? how will add 1 circuit act??? circuit is not stable transient values during changes hard to predict behavior

17

slide-42
SLIDE 42

example: (broken) counter circuit

add 1 time 0: 000 time 1: 001? time 2: 010? time 3: 011? in between value???

time 1 time 2

1 1 briefmy 011??? halfway voltages??? how will add 1 circuit act??? circuit is not stable transient values during changes hard to predict behavior

17

slide-43
SLIDE 43

example: (broken) counter circuit

add 1 time 0: 000 time 1: 001? time 2: 010? time 3: 011? in between value???

time 1 time 2

1 1 briefmy 011??? halfway voltages??? how will add 1 circuit act??? circuit is not stable transient values during changes hard to predict behavior

17

slide-44
SLIDE 44

example: (broken) counter circuit

add 1 time 0: 000 time 1: 001? time 2: 010? time 3: 011? in between value???

time 1 time 2

1 1 briefmy 011??? halfway voltages??? how will add 1 circuit act??? circuit is not stable transient values during changes hard to predict behavior

17

slide-45
SLIDE 45

circuits: state

logic performs calculations all the time never stores values! need extra elements to store values

registers, memory

19

slide-46
SLIDE 46

example: counter circuit (corrected)

add 1

count

time 0: 000 time 1: 001 time 2: 010 time 3: 011 add register to store current count updates based on “clock signal” (not shown) avoids intermediate updates

20

slide-47
SLIDE 47

example: counter circuit (corrected)

add 1

count

time 0: 000 time 1: 001 time 2: 010 time 3: 011 add register to store current count updates based on “clock signal” (not shown) avoids intermediate updates

20

slide-48
SLIDE 48

example: counter circuit (corrected)

add 1

count

time 0: 000 time 1: 001 time 2: 010 time 3: 011 add register to store current count updates based on “clock signal” (not shown) avoids intermediate updates

20

slide-49
SLIDE 49

registers

PC

updates every clock cycle

register output register input

21

slide-50
SLIDE 50

state in Y86-64

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

logic logic (with ALU) l

  • g

i c

to reg

l

  • g

i c

to PC

22

slide-51
SLIDE 51

state in Y86-64

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

logic logic (with ALU) l

  • g

i c

to reg

l

  • g

i c

to PC

22

slide-52
SLIDE 52

state in Y86-64

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

logic logic (with ALU) l

  • g

i c

to reg

l

  • g

i c

to PC

22

slide-53
SLIDE 53

state in Y86-64

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

logic logic (with ALU) l

  • g

i c

to reg

l

  • g

i c

to PC

22

slide-54
SLIDE 54

state in Y86-64

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

logic logic (with ALU) l

  • g

i c

to reg

l

  • g

i c

to PC

22

slide-55
SLIDE 55

memories

Instr. Mem. data address Data Mem. data output address input to write write enable? read enable? address input data output

time

address input input to write value in memory

23

slide-56
SLIDE 56

memories

Instr. Mem. data address Data Mem. data output address input to write write enable? read enable? address input data output

time

address input input to write value in memory

23

slide-57
SLIDE 57

memories

Instr. Mem. data address Data Mem. data output address input to write write enable? read enable? address input data output

time

address input input to write value in memory

23

slide-58
SLIDE 58

register fjle

register fjle

%rax, %rdx, … reg values read reg #s write reg #s data to write

register number input register value output

time

register number input data input value in register

write register #15: write is ignored read register #15: value is always 0

24

slide-59
SLIDE 59

register fjle

register fjle

%rax, %rdx, … reg values read reg #s write reg #s data to write

register number input register value output

time

register number input data input value in register

write register #15: write is ignored read register #15: value is always 0

24

slide-60
SLIDE 60

register fjle

register fjle

%rax, %rdx, … reg values read reg #s write reg #s data to write

register number input register value output

time

register number input data input value in register

write register #15: write is ignored read register #15: value is always 0

24

slide-61
SLIDE 61

register fjle

register fjle

%rax, %rdx, … reg values read reg #s write reg #s data to write

register number input register value output

time

register number input data input value in register

write register #15: write is ignored read register #15: value is always 0

24

slide-62
SLIDE 62

ALUs

ALU A OP B A B

  • peration select

Operations needed: add — addq, addresses sub — subq xor — xorq and — andq more?

25

slide-63
SLIDE 63

simple ISA 1: addq

addq %rXX, %rYY encoding:

%rXX %rYY (two 4-bit register #s)

1 byte instructions, no opcode

no other instructions

26

slide-64
SLIDE 64

addq CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

%rXX %rYY

split add

(contains ALU)

0 (=%rax) 2 (=%rdx) 2 (=%rdx) 10 (value of RAX) 30 (value of RDX)

/* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = ????, rax = ??, rbx = ??, rdx = ?? plus one /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = 0x01, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = 0x02, rax = 10, rbx = 20, rdx = 60

27

slide-65
SLIDE 65

addq CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

%rXX %rYY

split add

(contains ALU)

0 (=%rax) 2 (=%rdx) 2 (=%rdx) 10 (value of RAX) 30 (value of RDX)

/* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = ????, rax = ??, rbx = ??, rdx = ?? plus one /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = 0x01, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = 0x02, rax = 10, rbx = 20, rdx = 60

27

slide-66
SLIDE 66

addq CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

%rXX %rYY

split add

(contains ALU)

0 (=%rax) 2 (=%rdx) 2 (=%rdx) 10 (value of RAX) 30 (value of RDX)

/* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = ????, rax = ??, rbx = ??, rdx = ?? plus one /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = 0x01, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = 0x02, rax = 10, rbx = 20, rdx = 60

27

slide-67
SLIDE 67

addq CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

%rXX %rYY

split add

(contains ALU)

0 (=%rax) 2 (=%rdx) 2 (=%rdx) 10 (value of RAX) 30 (value of RDX)

/* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = ????, rax = ??, rbx = ??, rdx = ?? plus one /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = 0x01, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = 0x02, rax = 10, rbx = 20, rdx = 60

27

slide-68
SLIDE 68

addq CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

%rXX %rYY

split add

(contains ALU)

0 (=%rax) 2 (=%rdx) 2 (=%rdx) 10 (value of RAX) 30 (value of RDX)

/* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = ????, rax = ??, rbx = ??, rdx = ?? plus one /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = 0x01, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = 0x02, rax = 10, rbx = 20, rdx = 60

27

slide-69
SLIDE 69

addq CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

%rXX %rYY

split add

(contains ALU)

0 (=%rax) 2 (=%rdx) 2 (=%rdx) 10 (value of RAX) 30 (value of RDX)

/* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = ????, rax = ??, rbx = ??, rdx = ?? plus one /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = 0x01, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = 0x02, rax = 10, rbx = 20, rdx = 60

27

slide-70
SLIDE 70

addq CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

%rXX %rYY

split add

(contains ALU)

0 (=%rax) 2 (=%rdx) 2 (=%rdx) 10 (value of RAX) 30 (value of RDX)

/* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = ????, rax = ??, rbx = ??, rdx = ?? plus one /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = 0x01, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = 0x02, rax = 10, rbx = 20, rdx = 60

27

slide-71
SLIDE 71

addq CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

%rXX %rYY

split add

(contains ALU)

0 (=%rax) 2 (=%rdx) 2 (=%rdx) 10 (value of RAX) 30 (value of RDX)

/* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = ????, rax = ??, rbx = ??, rdx = ?? plus one /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = 0x01, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = 0x02, rax = 10, rbx = 20, rdx = 60

27

slide-72
SLIDE 72

addq CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

%rXX %rYY

split add

(contains ALU)

0 (=%rax) 2 (=%rdx) 2 (=%rdx) 10 (value of RAX) 30 (value of RDX)

/* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = ????, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = ????, rax = ??, rbx = ??, rdx = ?? plus one /* 0x00: */ addq %rax, %rdx /* 0x01: */ addq %rbx, %rdx initially: PC = 0x00, rax = 10, rbx = 20, rdx = 30 after cycle 1: PC = 0x01, rax = 10, rbx = 20, rdx = 40 after cycle 2: PC = 0x02, rax = 10, rbx = 20, rdx = 60

27

slide-73
SLIDE 73

Simple ISA 2: jmp

jmp label encoding: 8-byte little-endian address

8 byte instructions, no opcode

28

slide-74
SLIDE 74

jmp CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF /* 0x00: */ jmp 0x10 /* 0x08: */ jmp 0x00 /* 0x10: */ jmp 0x08 initially: PC = 0x00 after cycle 1: PC = 0x10 after cycle 2: PC = 0x08 after cycle 3: PC = 0x00

29

slide-75
SLIDE 75

jmp CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF /* 0x00: */ jmp 0x10 /* 0x08: */ jmp 0x00 /* 0x10: */ jmp 0x08 initially: PC = 0x00 after cycle 1: PC = 0x10 after cycle 2: PC = 0x08 after cycle 3: PC = 0x00

29

slide-76
SLIDE 76

jmp CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF /* 0x00: */ jmp 0x10 /* 0x08: */ jmp 0x00 /* 0x10: */ jmp 0x08 initially: PC = 0x00 after cycle 1: PC = 0x10 after cycle 2: PC = 0x08 after cycle 3: PC = 0x00

29

slide-77
SLIDE 77

multiplexers

MUX a b c d

  • utput

select = 0 or 1 or 2 or 3 = a or b or c or d truth table: select bit 1 select bit 0

  • utput (many bits)

a 1 b 1 c 1 1 d

30

slide-78
SLIDE 78

multiplexers

MUX a b c d

  • utput

select = 0 or 1 or 2 or 3 = a or b or c or d truth table: select bit 1 select bit 0

  • utput (many bits)

a 1 b 1 c 1 1 d

30

slide-79
SLIDE 79

multiplexers

MUX a b c d

  • utput

select = 0 or 1 or 2 or 3 = a or b or c or d truth table: select bit 1 select bit 0

  • utput (many bits)

a 1 b 1 c 1 1 d

30

slide-80
SLIDE 80

Simple ISA 3: Jmp or No-Op

actual subset of Y86-64 jmp LABEL — encoded as 0x70 + address nop — encoded as 0x10

31

slide-81
SLIDE 81

jmp+nop CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

split

MUX

1 if jmp 0 if nop

  • pcode

dest

+ 1 (nop size)

nop 1 jmp Dest 7 Dest

nop jmp dest 1 icode valC valP PC not in listing

32

slide-82
SLIDE 82

jmp+nop CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

split

MUX

1 if jmp 0 if nop

  • pcode

dest

+ 1 (nop size)

nop 1 jmp Dest 7 Dest

nop jmp dest 1 icode valC valP PC not in listing

32

slide-83
SLIDE 83

jmp+nop CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

split

MUX

1 if jmp 0 if nop

  • pcode

dest

+ 1 (nop size)

nop 1 jmp Dest 7 Dest

nop jmp dest 1 icode valC valP PC not in listing

32

slide-84
SLIDE 84

jmp+nop CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

split

MUX

1 if jmp 0 if nop

  • pcode

dest

+ 1 (nop size)

nop 1 jmp Dest 7 Dest

nop jmp dest 1 icode valC valP PC not in listing

32

slide-85
SLIDE 85

jmp+nop CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

split

MUX

1 if jmp 0 if nop

  • pcode

dest

+ 1 (nop size)

nop 1 jmp Dest 7 Dest

nop jmp dest 1 icode valC valP PC not in listing

32

slide-86
SLIDE 86

jmp+nop CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

split

MUX

1 if jmp 0 if nop

  • pcode

dest

+ 1 (nop size)

nop 1 jmp Dest 7 Dest

nop jmp dest 1 icode valC valP PC not in listing

32

slide-87
SLIDE 87

jmp+nop CPU

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF

split

MUX

1 if jmp 0 if nop

  • pcode

dest

+ 1 (nop size)

nop 1 jmp Dest 7 Dest

nop jmp dest 1 icode valC valP PC not in listing

32

slide-88
SLIDE 88

exercise: nop/add CPU

Let’s say we wanted to make nop+add CPU. Where would need MUXes?

  • A. before one or both of the register fjle ‘register number to read’

inputs

  • B. before the PC register’s input
  • C. before one of the register fjle ‘register number to write’ inputs
  • D. before one of the register fjle ‘register value to write’ inputs
  • E. before the instruction memory’s address input

33