Instructions Philipp Koehn 11 September 2019 Philipp Koehn - - PowerPoint PPT Presentation

instructions
SMART_READER_LITE
LIVE PREVIEW

Instructions Philipp Koehn 11 September 2019 Philipp Koehn - - PowerPoint PPT Presentation

Instructions Philipp Koehn 11 September 2019 Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019 1 number adder Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019 Design Goal 2 Build a


slide-1
SLIDE 1

Instructions

Philipp Koehn 11 September 2019

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-2
SLIDE 2

1

number adder

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-3
SLIDE 3

2

Design Goal

  • Build a machine that adds several numbers together
  • Numbers stored in 64 KB RAM
  • Idea:

Loop through memory with ripple counter

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-4
SLIDE 4

3

64 KB RAM

DI DO W A

64Kx8 RAM

1 6 8 8

  • Read/write 8 bits at a time (one byte)
  • 16 bit address space:

216=65,536 bytes

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-5
SLIDE 5

4

Control Panel

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-6
SLIDE 6

5

Control Panel

DI DO W A

64Kx8 RAM

1 6 8 8

Control Panel

We can enter numbers and inspect with a control panel

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-7
SLIDE 7

6

Ripple Counter

D > CLK Q Q NOT NOT

OUT0 OUT1

D > CLK Q Q

OUT2

D > CLK Q Q

OUT3

OUT0 OUT1 OUT2 OUT3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-8
SLIDE 8

7

Connecting Ripple Counter to Memory

DI DO W A

64Kx8 RAM

16 8

Control Panel Ripple Counter Oscillator

CLK O

  • Ripple counter rotates through number 0, 1, ...
  • Each clock cycle, a new number is emitted from memory

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-9
SLIDE 9

8

Adder

8

8-BIT ADDER

A B S CO CI

8 8

  • Adds two numbers:

S=A+B

  • Overflow:

Carry out (CO)

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-10
SLIDE 10

9

Latch

8

8-BIT LATCH

D Q >CLK

8

  • 8-bit memory
  • Edge-triggered:

stores value when clock turns to 1

  • To be used as accumulator

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-11
SLIDE 11

10

Connecting Adder and Latch

8 8 8-BIT LATCH

D Q >CLK

8-BIT ADDER

B S A CO CI

CLOCK OUT

8 8

DATA

  • Adder adds new value (DATA) to accumulator
  • Edge trigger prevents immediate feedback
  • Output (OUT) may be shown with light bulbs

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-12
SLIDE 12

11

Number Adder

8 8 8-BIT LATCH

D Q >CLK

8-BIT ADDER

B S A CO CI

OUT

8 8

DI DO W A

64Kx8 RAM

1 6

CONTROL PANEL RIPPLE COUNTER OSCILLATOR

CLK O

  • Everything

put together

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-13
SLIDE 13

12

Halt

RIPPLE COUNTER OSCILLATOR

CLK O

AND

HALT

NOT

  • Halt when external switch is turned on
  • Or:

cut connection to clock if ripple counter reaches final number

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-14
SLIDE 14

13

multiple operations

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-15
SLIDE 15

14

Modification: Alternate Add and Subtract

  • Let’s say we want to alternate between adding and subtracting
  • We already built an integrated adder and subtractor

4-BIT FULL ADDER A0 B3 S0 CO CI A1 A2 A3 B0 B1 B2 S1 S2 S3

B0 B1 B2 B3 SUB A0 A1 A2 A3 OVERFLOW SUM SUB SUB

  • Idea:

indicate operation from last bit of ripple counter

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-16
SLIDE 16

15

Alternate Add and Subtract

8 8 8-BIT LATCH

D Q >CLK

ALU

B S A CO CI

OUT

8 8

DI DO W A

64Kx8 RAM

1 6

CONTROL PANEL RIPPLE COUNTER

CLK O SUB O0

OSCILLATOR AND

HALT

NOT

  • Bit 0 of ripple

counter as instruction flag

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-17
SLIDE 17

16

instructions

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-18
SLIDE 18

17

Goal

  • Control operations by instructions stored in memory

⇒ A programmable computer

  • First idea

– separate instruction memory – instructions: add or subtract

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-19
SLIDE 19

18

Instruction Memory

8 8 8-BIT LATCH

D Q >CLK

ALU

B S A CO CI

OUT

8 8

DI DO W A

64Kx8 RAM

16

CONTROL PANEL RIPPLE COUNTER

CLK O SUB

OSCILLATOR AND

HALT

NOT

DI DO W A

64Kx8 RAM

1 6

CONTROL PANEL CONTROL UNIT

8

Code Data

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-20
SLIDE 20

19

Operation Codes for Instructions

  • Each operation is encoded by a byte value

Operation Code (hex) Add 20h Subtract 21h

  • Example

Address Code Data Accumulator 0000h 20h Add 01h 0001h 20h Add 02h 0002h 21h Subtract 01h 0003h 20h Add 08h 0004h 21h Subtract 03h 00h 01h 03h 02h 0ah 07h

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-21
SLIDE 21

20

More Instructions

  • Load:

load number from memory into accumulator

  • Store:

store accumulator value in memory

  • Halt:

block clock

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-22
SLIDE 22

21

Operation Codes for Instructions

  • Each operation is encoded by a byte value

Operation Code (hex) Load 10h Store 11h Add 20h Subtract 21h Halt FFh

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-23
SLIDE 23

22

More Wiring

8 8 8-BIT LATCH

D Q >CLK

ALU

B S A CO CI

OUT

8

DI DO W A

64Kx8 RAM

1 6

CONTROL PANEL RIPPLE COUNTER

CLK O SUB

OSCILLATOR AND

HALT

NOT

DI DO W A

64Kx8 RAM

16

CONTROL PANEL CTRL UNIT

8

Code Data

8 8 SELECTOR 8

INSTR STR SUB HALT LD

NOT NOT

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-24
SLIDE 24

23

Load

8 8 8-BIT LATCH

D Q >CLK

ALU

B S A CO CI

OUT

8

DI DO W A

64Kx8 RAM

1 6

CONTROL PANEL RIPPLE COUNTER

CLK O SUB

OSCILLATOR AND

HALT

NOT

DI DO W A

64Kx8 RAM

16

CONTROL PANEL CTRL UNIT

8

Code Data

8 8 SELECTOR 8

INSTR STR SUB HALT LD

NOT

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-25
SLIDE 25

24

Store

8 8 8-BIT LATCH

D Q >CLK

ALU

B S A CO CI

OUT

8

DI DO W A

64Kx8 RAM

1 6

CONTROL PANEL RIPPLE COUNTER

CLK O SUB

OSCILLATOR AND

HALT

NOT

DI DO W A

64Kx8 RAM

16

CONTROL PANEL CTRL UNIT

8

Code Data

8 8 SELECTOR 8

INSTR STR SUB HALT LD

NOT

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-26
SLIDE 26

25

Halt

8 8 8-BIT LATCH

D Q >CLK

ALU

B S A CO CI

OUT

8

DI DO W A

64Kx8 RAM

1 6

CONTROL PANEL RIPPLE COUNTER

CLK O SUB

OSCILLATOR AND

HALT

NOT

DI DO W A

64Kx8 RAM

16

CONTROL PANEL CTRL UNIT

8

Code Data

8 8 SELECTOR 8

INSTR STR SUB HALT LD

NOT

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-27
SLIDE 27

26

Operations and Wiring

  • Each operation changes certain flags

Operation Code LD STR SUB HALT (hex) Load 10h 1 Store 11h 1 Add 20h Subtract 21h 1 Halt FFh 1

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-28
SLIDE 28

27

Program Example

Address Code Data Accumulator 0000h 10h Load 56h 0001h 20h Add 2Ah 0002h 21h Subtract 38h 0003h 11h Store 0004h FFh Halt 00h 56h 80h 48h 48h 48h

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-29
SLIDE 29

28

adding 16 bit numbers

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-30
SLIDE 30

29

Adding 16 Bit Numbers

  • 1 byte integers will not suffice in practice

– unsigned: 0 to 255 – signed:

  • 128 to 127
  • Let’s use 2 bytes (16 bit)
  • How can we do addition with our 8-bit adder?

Add the bytes separately

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-31
SLIDE 31

30

Example

  • Task:

76ABh + 232Ch

  • Lower order byte

0ABh +2Ch

  • 0D7h
  • Higher order byte

076h +23h

  • 099h
  • Putting it together:

99D7h

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-32
SLIDE 32

31

Another Example

  • Task:

76ABh + 236Ch

  • Lower order byte

0ABh +6Ch

  • 117h
  • Higher order byte

(add the carry) 001h +76h +23h

  • 09Ah
  • Putting it together:

9AD7h

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-33
SLIDE 33

32

More Instructions

  • Add with Carry

– when addition results in a carry, store this in a flag – new add instruction that includes carry if flag set

  • Subtract with Borrow

– when subtraction results in a carry, store this in a flag – new subtract instruction that includes carry if flag set

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-34
SLIDE 34

33

Circuit

ALU

B S A CO CI SUB

CTRL UNIT

INSTR STR CO HALT LD D >CLK Q CI SUB

Carry Flag

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-35
SLIDE 35

34

Instructions

  • Each operation is encoded by a byte value

Operation Code (hex) Load 10h Store 11h Add 20h Subtract 21h Add with carry 22h Subtract with borrow 23h Halt FFh

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-36
SLIDE 36

35

Code

Address Code Data Carry Accumulator 0000h 10h Load ABh 0001h 20h Add 6Ch 0002h 11h Store 0003h 10h Load 76h 0004h 22h Add with carry 23h 0005h 11h Store 0006h FFh Halt 00h ABh 1 17h 1 17h 1 76h 9Ah 9Ah 9Ah

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-37
SLIDE 37

36

addressing memory

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-38
SLIDE 38

37

Motivation

  • Currently using two memories

– code memory for instructions – data memory

  • Very limiting
  • Instead:

– store code and data in same memory – add explicit addresses to instructions

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-39
SLIDE 39

38

Adapted 16-Bit Adder

  • Memory

Address Data 4000h ABh 4001h 76h 4002h 6Ch 4003h 23h

  • Code

Address Bytes Code 0000h 10h 00h 40h Load 4000h 0003h 20h 02h 40h Add 4002h 0006h 11h 04h 40h Store 4004h 0009h 10h 01h 40h Load 4001h 000Ch 22h 03h 40h Add with carry 4003h 000Fh 11h 05h 40h Store 4005h 0012h FFh Halt Note: Instructions take up 1 or 3 bytes

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-40
SLIDE 40

39

Instruction Fetch

DI DO W A

64Kx8 RAM CONTROL PANEL RIPPLE COUNTER

CLK O

OSCILLATOR

AND

HALT

NOT

8 8 8 8 LATCH

D Q >CLK

8 8 LATCH

D Q >CLK

8 LATCH

D Q >CLK

CTRL UNIT

INSTR STR CO HALT LD CI SUB Z D1 D2

INSTRUCTION FETCH 8

CLK S X INSTR CLK

3 registers: code and 2 byte data

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-41
SLIDE 41

40

Instruction Fetch

DI DO W A

64Kx8 RAM CONTROL PANEL RIPPLE COUNTER

CLK O

OSCILLATOR

AND

HALT

NOT

8 8 8 8 LATCH

D Q >CLK

8 8 LATCH

D Q >CLK

8 LATCH

D Q >CLK

CTRL UNIT

INSTR STR CO HALT LD CI SUB Z D1 D2

INSTRUCTION FETCH 8

CLK S X INSTR CLK

Transfer bytes from memory to instruction code and data register

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-42
SLIDE 42

41

Instruction Fetch

DI DO W A

64Kx8 RAM CONTROL PANEL RIPPLE COUNTER

CLK O

OSCILLATOR

AND

HALT

NOT

8 8 8 8 LATCH

D Q >CLK

8 8 LATCH

D Q >CLK

8 LATCH

D Q >CLK

CTRL UNIT

INSTR STR CO HALT LD CI SUB Z D1 D2

INSTRUCTION FETCH 8

CLK S X INSTR CLK

Instruction fetch logic determines which register is written to

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-43
SLIDE 43

42

Instruction Fetch

DI DO W A

64Kx8 RAM CONTROL PANEL RIPPLE COUNTER

CLK O

OSCILLATOR

AND

HALT

NOT

8 8 8 8 LATCH

D Q >CLK

8 8 LATCH

D Q >CLK

8 LATCH

D Q >CLK

CTRL UNIT

INSTR STR CO HALT LD CI SUB Z D1 D2

INSTRUCTION FETCH 8

CLK S X INSTR CLK

This is informed by instruction code

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-44
SLIDE 44

43

Instruction Fetch

DI DO W A

64Kx8 RAM CONTROL PANEL RIPPLE COUNTER

CLK O

OSCILLATOR

AND

HALT

NOT

8 8 8 8 LATCH

D Q >CLK

8 8 LATCH

D Q >CLK

8 LATCH

D Q >CLK

CTRL UNIT

INSTR STR CO HALT LD CI SUB Z D1 D2

INSTRUCTION FETCH 8

CLK S X INSTR CLK

Once all registers are filled, execute instruction

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-45
SLIDE 45

44

Data Paths

  • Data needs to be transferred in various ways
  • Adress passed on to memory (overriding program counter)
  • Add/subtract:

read byte from memory, pass to ALU

  • Load:

read byte from memory, store in accumulator

  • Store:

read byte from accumulator, store in memory

  • No detailed wiring worked out here...

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-46
SLIDE 46

45

multiplication

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-47
SLIDE 47

46

Plan

  • Multiplication by repeated addition
  • Pseudo-code

load number1 into accumulator loop subtract 1 from number2 last if number2 = 0 add number1 to accumulator store accumulator in result

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-48
SLIDE 48

47

Needed

  • Jump

– set the ripple counter to specified value

  • Zero flag

– detect that subtraction resulted in number 0 – implemented as flag of the ALU

  • Jump if zero

– check if zero flag is set – only then update ripple counter – otherwise, do nothing

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-49
SLIDE 49

48

Zero Flag

ALU

B S A CO CI SUB

CTRL UNIT

INSTR STR CO HALT LD D >CLK Q CI SUB

Carry Flag

D >CLK Q

Zero Flag

Z Z

  • Flag when the ALU operation results in 0

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-50
SLIDE 50

49

Instructions

Operation Code (hex) Load 10h Store 11h Add 20h Subtract 21h Add with carry 22h Subtract with borrow 23h Jump 30h Jump if zero 31h Jump if carry 32h Jump if not zero 33h Jump if not carry 34h Halt FFh

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019

slide-51
SLIDE 51

50

Code (8 Bit Version)

  • Memory

Address Data 4000h 0Bh 4001h 0Fh 4002h 01h

  • Code

Address Bytes Code 0000h 10h 00h 40h Load 4000h ; load number1 0003h 11h 03h 40h Store 4003h ; save in result 0006h 10h 01h 40h Load 4001h ; load number2 0009h 21h 02h 40h Subtract 4002h ; subtract 1 000Bh 31h 18h 00h jump if zero to 0018h ; jump to end if done 000Fh 10h 03h 40h load 4003h ; load result 0012h 20h 00h 40h add 4000h ; add number1 0015h 30h 03h 00h jump to 0003h ; loop 0018h FFh halt ; quit

Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019