CS 3: Intro to Systems Digital Logic Martin Gagné Swarthmore College January 3, 27 You re going to want scratch papr today borrow some if needed.
Quick nnouncements Late Policy Reminder 3 late days total for the whole semester Lab work Start early, especially multi-week labs Readings Only the page linked, no further links
Today (and Thursday) Hardware basics Machine memory models Digital signals Logic gates Manipulating/Representing values in hardware dders Storage & memory (latches)
The system stack c program compiler software shell operating system Starting this week This class memory CPU hardware circuits gates transistors electrical engineering wires
Hardware Models (94 s) Harvard rchitecture: Program Memory CPU (Control and rithmetic) Data Memory Input/Output Von Neumann rchitecture: CPU (Control and rithmetic) Input/Output Program and Data Memory
Von Neumann rchitecture Model Computer is a generic computing machine: ased on lan Turing s Universal Turing Machine
Von Neumann rchitecture Model Computer is a generic computing machine: ased on lan Turing s Universal Turing Machine The hardware only ever executes one program: Initialize program counter Repeat forever: { fetch instruction indicated by program counter increment the program counter execute the instruction }
Von Neumann rchitecture Model Computer is a generic computing machine: ased on lan Turing s Universal Turing Machine Stored program model: computer stores program rather than encoding it (feed in data and instructions) No distinction between data and instructions memory 5 parts connected by buses (wires): Memory, Control, Processing, Input, Output Memory Cntrl Unit Processing Unit Input/Output addr bus cntrl bus data bus
Memory Stores instructions and data. ddressable, like array indices. addr,, 2, (In CPU:) Memory ddress Register: address to read/write Memory Data Register: value to read/write Memory Cntrl Unit Processing Unit Input/Output addr bus cntrl bus data bus
Central Processing Unit (CPU) Processing Unit: executes instructions selected by the control unit LU (arithmetic logic unit): simple functional units: DD, SU, ND, OR, etc. Registers: temporary storage directly accessible by instructions Control unit: determines the order in which instructions execute PC: program counter: address of next instruction IR: instruction register: holds current instruction clock-based control: clock signal+ir trigger state changes
Input/Output Keyboard Files on the hard drive Network communication Memory Cntrl Unit Processing Unit Input/Output addr bus cntrl bus data bus
Digital Computers ll input is discrete (driven by periodic clock) ll signals are binary (: no voltage, : voltage) data, instructions, control signals, arithmetic, clock To run program, need different types of circuits Circuits to execute program instructions that act on program data CPU LU, Cntrl, Storage RM Cntrl & Storage bus Circuits to store program data and instructions and support reading and writing addressable storage locations
Goal: uild a CPU (model) Three main classifications of HW circuits:. LU: implement arithmetic & logic functionality (ex) adder to add two values together 2. Storage: to store binary values (ex) Register File: set of CPU registers, lso: main memory (RM) 3. Control: support/coordinate instruction execution (ex) fetch the next instruction to execute
bstraction User / Programmer Wants low complexity pplications Specific functionality Software library Reusable functionality Operating system Manage resources Complex devices Compute & I/O
bstraction Hardware Circuits Logic Gates Transistors Complex devices Compute & I/O Here be dragons. (Electrical Engineering) (Physics)
Logic Gates Input: oolean value(s) (high and low voltages for and ) Output: oolean value result of boolean function lways present, but may change when input changes Not Or nd a a out b out = a & b out b out = a b & a out out = ~a ~
More Logic Gates Note the circle on the output. This means negate it. NND NOR a a out b out = ~(a & b) out b out = ~(a b) NND NOR
Combinational Logic Circuits uild up higher level processor functionality from basic gates cyclic Network of Gates Inputs Outputs Outputs are boolean functions of inputs Outputs continuously respond to changes to inputs
What does this circuit output? Not Or nd X Output Y Clicker Choices X Y Out Out OutC OutD OutE
What can we do with these? uild-up XOR from basic gates (ND, OR, NOT) ^ Q: When is ^ ==?
Which of these is an XOR circuit? nd Or Not Draw an XOR circuit using ND, OR, and NOT gates. I ll show you the clicker options after you ve had some time.
Which of these is an XOR circuit? : : C: D: E: None of these are XOR.
Checking the XOR circuit ^ == (~ & ) ( & ~) : : ^: : : ^: out = ^ : : ^: : : ^:
bstracting the XOR circuit ^ == (~ & ) ( & ~) out = ^ = XOR out = ^ ^
Digital Circuits - uilding a CPU Three main classifications of HW circuits:. LU: implement arithmetic & logic functionality (ex) adder to add two values together 2. Storage: to store binary values (ex) Register File: set of CPU registers 3. Control: support/coordinate instruction execution (ex) fetch the next instruction to execute HW Circuits Logic Gates Transistor
Digital Circuits - uilding a CPU Three main classifications of HW circuits:. LU: implement arithmetic & logic functionality (ex) adder to add two values together Start with LU components (e.g., adder, logic circuits) Combine (with multiplexer) into LU! HW Circuits Logic Gates Transistor
rithmetic Circuits bit adder: + Two outputs:. Obvious one: the sum 2. Other one:?? Cout Sum(+)
Which of these circuits is a one-bit adder? Sum(+) : Sum Cout : Sum Cout Cout C: D: Sum Cout Sum Cout
More than one bit? When adding, sometimes have carry in too +
One-bit (full) adder Need to include: Carry-in & Carry-out Cin Sum Cout Cin = -bit adder Cout Sum
One-bit (full) adder Need to include: Carry-in & Carry-out cin Cin Sum Cin cout H Cout cout cout sum H sum = -bit adder Cout Sum
Multi-bit dder (Ripple-carry dder) -bit adder Sum 3 3 Cout -bit adder -bit adder Cout Sum3 Cout Sum Cout 2 2 -bit adder N- N- Sum2 -bit adder Cout SumN-
Three-bit dder (Ripple-carry dder) (2) + (3) Carry in -bit adder -bit adder -bit adder = 2 2 3-bit adder Carry out Sum Sum Sum2
rithmetic Logic Unit (LU) One component that knows how to manipulate bits in multiple ways ddition Subtraction Multiplication / Division itwise ND, OR, NOT, etc. uilt by combining components Take advantage of sharing HW when possible (e.g., subtraction using adder)
Simple 3-bit LU: dd and bitwise OR 3-bit inputs and : 2 Sum Sum Sum2 3-bit adder 2 Or Or Or2 t any given time, we only want the output from ONE of these!
Simple 3-bit LU: dd and bitwise OR Extra input: control signal to select Sum vs. OR 3-bit inputs and : 2 Sum Sum Sum2 3-bit adder 2 Or Or Or2 Circuit that takes in Sum-2 / Or-2 and only outputs one of them, based on control signal.
Which of these circuits lets us select between two inputs? Input : Input Control Signal Input 2 Control Signal Input 2 Input Control Signal Input 2 C: :
Multiplexor: Chooses an input value Inputs: 2N data inputs, N signal bits Output: is one of the 2N input values s bit 2-way MUX b a out out = (s & a) (~s &b) Control signal s, chooses the input for output When s is : choose a, when s is : choose b
Word Multiplexor s s b3 Input: two 32 bit values (a, b) one bit signal s out3 Each corresponding bit of 32 bit input values, fed through bit mux a3 Output: b Out out3 a3 b3 MUX out One 32 bit value (either a or b) a 38
N-Way Multiplexor Choose one of N inputs, need log2 N select bits s 4-Way Multiplexor s s D D3 choose D D D2 D3 s s D D2 s S Input to choose D Out MUX4 D.........
Simple 3-bit LU: dd and bitwise OR Extra input: control signal to select Sum vs. OR 3-bit inputs and : 2 Sum Sum Sum2 3-bit adder 2 Or Or Or2 Multiplexer!
LU: rithmetic Logic Unit CPU Instruction: DD 2 op bits: selects which op to output 3 Y X L U X op Y OF Output flags: set as a side effect of op (e.g., overflow detected) rithmetic and logic circuits: DD, SU, NOT, Control circuits: use op bits to select output Circuits around LU: Select input values X and Y from instruction or register Select op bits from instruction to feed into LU Feed output somewhere
Up next More digital circuits (storage and control)