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 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
64 KB RAM 3 A 1 6 64Kx8 RAM W DO DI 8 8 • Read/write 8 bits at a time (one byte) 2 16 =65,536 bytes • 16 bit address space: Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Control Panel 4 Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Control Panel 5 Control Panel A 1 6 64Kx8 RAM W DI DO 8 8 We can enter numbers and inspect with a control panel Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Ripple Counter 6 OUT0 OUT1 OUT2 OUT3 NOT D Q D Q D Q NOT > CLK Q > CLK Q > CLK Q 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1 0 OUT0 0 0 1 1 0 1 1 0 0 1 1 0 0 1 1 OUT1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 OUT2 OUT3 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Connecting Ripple Counter to Memory 7 Control Panel A Ripple O 16 Oscillator CLK Counter 64Kx8 RAM W DI DO 8 • 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
Adder 8 8 8 A B 8-BIT ADDER CI CO S 8 • Adds two numbers: S=A+B • Overflow: Carry out (CO) Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Latch 9 8 D 8-BIT LATCH >CLK Q 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
Connecting Adder and Latch 10 DATA 8 8 A B 8-BIT ADDER CO S CI 8 CLOCK D >CLK 8-BIT LATCH Q 8 OUT • 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
Number Adder 11 CONTROL PANEL RIPPLE OSCILLATOR CLK A O 1 6 COUNTER 64Kx8 W RAM DI DO 8 8 A B 8-BIT ADDER CO S CI 8 D >CLK 8-BIT LATCH Q • Everything 8 put together OUT Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Halt 12 OSCILLATOR RIPPLE AND CLK O COUNTER NOT HALT • 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
13 multiple operations Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Modification: Alternate Add and Subtract 14 • Let’s say we want to alternate between adding and subtracting • We already built an integrated adder and subtractor A0 A1 A2 A3 B0 B1 B2 B3 SUB A0 A1 A2 A3 B0 B1 B2 B3 4-BIT SUB CI CO FULL ADDER SUB S0 S1 S2 S3 OVERFLOW SUM • Idea: indicate operation from last bit of ripple counter Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Alternate Add and Subtract 15 CONTROL PANEL OSCILLATOR RIPPLE CLK A AND O 1 6 COUNTER 64Kx8 W RAM O0 DI DO NOT 8 8 A B HALT ALU SUB CO S CI 8 D >CLK 8-BIT LATCH • Bit 0 of ripple Q counter as 8 instruction flag OUT Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
16 instructions Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Goal 17 • 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
Instruction Memory 18 CONTROL PANEL OSCILLATOR RIPPLE Data AND CLK COUNTER O A 16 64Kx8 W NOT RAM DI DO 1 6 CONTROL 8 HALT UNIT 8 A B 8 ALU SUB CO S CI A DO 64Kx8 W RAM 8 DI D >CLK 8-BIT LATCH Code Q CONTROL 8 PANEL OUT Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Operation Codes for Instructions 19 • Each operation is encoded by a byte value Operation Code (hex) Add 20h Subtract 21h • Example Address Code Data Accumulator 00h 01h 0000h 20h Add 01h 0001h 20h Add 02h 03h 0002h 21h Subtract 01h 02h 0003h 20h Add 08h 0ah 0004h 21h Subtract 03h 07h Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
More Instructions 20 • 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
Operation Codes for Instructions 21 • 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
More Wiring 22 CONTROL PANEL OSCILLATOR RIPPLE Data AND CLK COUNTER O A 1 6 64Kx8 W NOT RAM DI DO STR 16 CTRL SUB HALT 8 HALT UNIT 8 LD INSTR A B ALU SUB 8 CO S CI A DO NOT NOT 8 64Kx8 W SELECTOR RAM 8 DI 8 D >CLK 8-BIT LATCH Code Q CONTROL 8 PANEL OUT Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Load 23 CONTROL PANEL OSCILLATOR RIPPLE Data AND CLK COUNTER O A 1 6 64Kx8 W NOT RAM DI DO STR 16 CTRL SUB HALT 8 HALT UNIT 8 LD INSTR A B ALU SUB 8 S CO CI A DO NOT 8 64Kx8 W SELECTOR RAM 8 DI 8 D >CLK Code 8-BIT LATCH Q CONTROL 8 PANEL OUT Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Store 24 CONTROL PANEL OSCILLATOR RIPPLE Data AND CLK COUNTER O A 1 6 64Kx8 W NOT RAM DI DO STR 16 CTRL SUB HALT 8 HALT UNIT 8 LD INSTR A B ALU SUB 8 S CO CI A DO NOT 8 64Kx8 W SELECTOR RAM 8 DI 8 D >CLK Code 8-BIT LATCH Q CONTROL 8 PANEL OUT Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Halt 25 CONTROL PANEL OSCILLATOR RIPPLE Data AND CLK COUNTER O A 1 6 64Kx8 W NOT RAM DI DO STR 16 CTRL SUB HALT 8 HALT UNIT 8 LD INSTR A B ALU SUB 8 S CO CI A DO NOT 8 64Kx8 W SELECTOR RAM 8 DI 8 D >CLK Code 8-BIT LATCH Q CONTROL 8 PANEL OUT Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Operations and Wiring 26 • Each operation changes certain flags Operation Code LD STR SUB HALT (hex) Load 10h 1 0 0 0 Store 11h 0 1 0 0 Add 20h 0 0 0 0 Subtract 21h 0 0 1 0 Halt FFh 0 0 0 1 Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Program Example 27 Address Code Data Accumulator 00h 0000h 10h Load 56h 56h 0001h 20h Add 2Ah 80h 48h 0002h 21h Subtract 38h 0003h 11h Store 48h 0004h FFh Halt 48h Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
28 adding 16 bit numbers Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Adding 16 Bit Numbers 29 • 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
Example 30 • 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
Another Example 31 • Task: 76ABh + 236Ch • Lower order byte 0ABh +6Ch ---- 117h • Higher order byte 001h +76h (add the carry) +23h ---- 09Ah • Putting it together: 9AD7h Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
More Instructions 32 • 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
Circuit 33 STR CTRL CO HALT UNIT SUB LD INSTR CI A B SUB ALU CI CO S Q D >CLK Carry Flag Philipp Koehn Computer Systems Fundamental: Instructions 11 September 2019
Instructions 34 • 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
Recommend
More recommend