Lecture 9
Lecture 9
Damon Anderson
Review (1/2)
• Floating point approximates real numbers:
– Largest magnitude: 2128 – 2104 (Exp = 0xFE)
Smallest magnitude: 2-149 (denorm)
– Also has encodings for 0, ±∞, NaN
31 30 23 22 0
S Exponent (8) Significand (23)
• Big Takeaways:
– The smallest gap between two FP numbers change
depending on the exponent
– Rounding errors occur because of these gaps
6/29/2017 CS61C Su17 - Lecture 8 2
Review (2/2)
• Compiler converts a single HLL file into a single
assembly file .c → .s
• Assembler removes pseudo-instructions, converts
what it can to machine language, and creates a
checklist for linker (relocation table) .s → .o
– Resolves addresses by making 2 passes (for internal
forward references)
• Linker combines several object files and resolves
absolute addresses .o → .out
– Enable separate compilation and use of libraries
4
Discuss with Neighbors:
(previous midterm question)
In one word each, name the most common
producer and consumer of the following items.
Choose from: Linker, Loader, Compiler,
Assembler, Programmer
5
C program: foo.c
Compiler
• Compiler
Assembler
• Administrivia
Object (mach lang module): foo.o
• Assembler
• Linker Linker
lib.o
heap
static data
code
~ 0hex
10
C.A.L.L. Example
#include <stdio.h>
int main(){
printf("Hello, %s\n","world");
return 0;
}
19
Loader
STACK
HEAP
STATIC
CODE
20
Question: Which statement is TRUE about the
following code?
la t0,Array
Loop: lw t1,0(t0)
addi t0,t0,4
bne a0,t1,Loop
Exit: ...
(A) The la pseudoinstruction will be edited
during the link phase
(B) The bne instruction will be edited during the
link phase
(C) This code will be the output of the compiler
no matter what machine it’s run on
(D) This was written by a programmer because
compilers don’t allow pseudo-instructions 21
Question: Which statement is TRUE about the
following code?
la t0,Array
Loop: lw t1,0(t0)
addi t0,t0,4
bne a0,t1,Loop
Exit: ...
(A) The la pseudoinstruction will be edited
during the link phase
(B) The bne instruction will be edited during the
link phase
(C) This code will be the output of the compiler
no matter what machine it’s run on
(D) This was written by a programmer because
compilers don’t allow pseudo-instructions 22
Administrivia
• No lab tomorrow, no section Wed, Happy 4th of
July!
• HW2 and Proj 2-1 due this Friday
• Midterm 1 Tomorrow
– Monday, 9:30 – 11 AM, 10 Evans
– Expected Average: 55-75. This is normal!
– One 8.5”x11” cheatsheet
• HW3 releasing on Thurs.
Synchronous:
• All operations coordinated by a central clock
‒ “Heartbeat” of the system!
Digital:
• Represent all values with two discrete values
• Electrical signals are treated as 1’s and 0’s
‒ 1 and 0 are complements of each other
• High/Low voltage for True/False, 1/0
7/2/2018 CS61C Su17 - Lecture 9 26
Agenda
• Transistors, Switching Networks
• Meet the staff!
• Combinational Logic Representations
– Truth Tables
– Boolean Algebra
datapath control
register logic
switching
networks
7/2/2018 CS61C Su17 - Lecture 9 28
Switches (1/2)
• The basic element of physical implementations
• Convention: if input is a “1,” the switch is asserted
A Z
Open switch if A is “0” (unasserted)
and turn OFF light bulb (Z)
A Z
Close switch if A is “1” (asserted)
and turn ON light bulb (Z)
In this example, Z ≡ A.
7/2/2018 CS61C Su17 - Lecture 9 29
Switches (2/2)
• Can compose switches into more complex ones
(Boolean functions)
– Arrows show action upon assertion (1 = close)
A B
AND: “1” Z ≡ A and B
A
OR: “1” Z ≡ A or B
31
Transistors and CS61C
• The internals of transistors are important, but
won’t be covered in this class
– Physical limitations relating to speed and power
consumption
– High/Low voltage ↔1/0
– Better understand Moore’s Law
– Can take EE16A/B, EE105, and EE140
• We will proceed with the abstraction of Digital
Logic (0/1)
7/2/2018 CS61C Su17 - Lecture 9 32
1947 → 2018
33
Basics
N-channel P-channel
Gate
Gate
X
Voltage Source
(“1”) X Y
3V
1
00 V 31V
Y
31V 00V
0V
0
Ground
(“0”)
Called an inverter or NOT gate
7/2/2018 CS61C Su17 - Lecture 9 35
Two Input Networks
X Y Z
1 0 0 1
0 1 1
1 0 1
0 1 1 0
X Y Z
1 0 0 1
0 1 0
1 0 0
0 1 1 0
36
Question: Which set(s) of inputs will result in the
output Z being 1?
X Y
X Y
1 (A) 0 0
(B) 0 1
Z (C) 1 0
0 (D) 1 1
37
Question: Which set(s) of inputs will result in the
output Z being 1?
X Y
X Y
1 (A) 0 0
(B) 0 1
Z (C) 1 0
0 (D) 1 1
38
Block Diagrams
• In reality, chips composed of just transistors
and wires
– Small groups of transistors form useful building
blocks, which we show as blocks
X Y
1
X
Z
≡ Y
NAND Z
0
• Can combine to build higher-level blocks
– You can build AND, OR, and NOT out of NAND!
7/2/2018 CS61C Su17 - Lecture 9 39
Meet the Staff
Nick
Favorite Villain The Other Mother Project 1
datapath control
register logic
switching
networks
7/2/2018 CS61C Su17 - Lecture 9 42
Type of Circuits
• Digital Systems consist of two basic types of
circuits:
• Combinational Logic (CL)
– Output is a function of the inputs only, not the history
of its execution
– e.g. circuits to add A, B (ALUs)
• Sequential Logic (SL)
– Circuits that “remember” or store information
– a.k.a. “State Elements”
– e.g. memory and registers (Registers)
7/2/2018 CS61C Su17 - Lecture 9 43
Representations of
Combinational Logic
✓ Text Description
✓ Circuit Diagram
– Transistors and wires
– Logic Gates
✓ Truth Table
✓ Boolean Expression
C
F 1 0 0 F(1,0,0)
0
1 Rows
1 0 1 F(1,0,1)
1
1 1 0 F(1,1,0)
1
0
1 1 1 F(1,1,1)
0
If N inputs, how many distinct
functions F do we have?
Function maps each row to 0 or 1,
2R N) possible functions
so 2^(2
7/2/2018 CS61C Su17 - Lecture 9 46
CL: Multiple Outputs
A
X
B
Y
C F
D Z
a b c
0 0 0
0 1 0
AND 1 0 0
1 1 1
a b c
0 0 0
0 1 1
OR 1 0 1
1 1 1
7/2/2018 CS61C Su17 - Lecture 9 48
Logic Gates (2/2)
• Special names and symbols:
a b c
0 0 1
0 1 1
NAND 1 0 1
1 1 0
a b c
0 0 1
0 1 0
NOR 1 0 0
1 1 0
a b c
0 0 0
0 1 1
XOR 1 0 1
1 1 0
7/2/2018 CS61C Su17 - Lecture 9 49
Question: Convert the following statements into
a Truth Table assuming the output is whether
Damon is comfortable (1) or uncomfortable (0).
• Input X: Damon wears light (0) or heavy (1) clothing
• Input Y: It is cold (0) or hot (1) outside
• Input Z: Damon is indoors (0) or outdoors (1)
X Y Z (A) (B) (C) (D)
0 0 0 1 1 1 1
0 0 1 0 0 0 0
0 1 0 1 1 1 1
0 1 1 1 1 1 1
1 0 0 0 1 1 1
1 0 1 1 1 0 1
1 1 0 1 1 1 0
1 1 1 1 0 1 1
50
Question: Convert the following statements into
a Truth Table assuming the output is whether
Damon is comfortable (1) or uncomfortable (0).
• Input X: Damon wears light (0) or heavy (1) clothing
• Input Y: It is cold (0) or hot (1) outside
• Input Z: Damon is indoors (0) or outdoors (1)
X Y Z (A) (B) (C) (D)
0 0 0 1 1 1 1
0 0 1 0 0 0 0
0 1 0 1 1 1 1
0 1 1 1 1 1 1
1 0 0 0 1 1 1
1 0 1 1 1 0 1
1 1 0 1 1 1 0
1 1 1 1 0 1 1
51
52
Agenda
• Transistors, Switching Networks
• Meet the staff!
• Combinational Logic Representations
– Truth Tables
– Boolean Algebra
2)
3)
4)
This is difficult to
Circuit do efficiently! Truth
Diagram Table
Pr hro
op ug
at ut
s
bin np
t
ag h
ion
m ll i
at ga
(e
e s te
co y a
W st t
as
ire o
ign s
Tr
ie
als
inp use
oS
ut AN
rP
st D
Po
op ,O
So
Boolean
ro R,
pe an
Expressi
r
g a
on
te OT)
dN
s
C
• Options:
1) Test all combinations of the inputs and build the
Truth Table, then use SoP or PoS
2) Write out expressions for signals based on gates
• Will show this method here
7/2/2018 CS61C Su17 - Lecture 9 65
Circuit Simplification Example (2/4)
• Simplify the following circuit:
A
A AB ¬(AB)
B
B A A+¬BC D
¬B
¬BC
C
C
• Start from left, propagate signals to the right
• Arrive a D = ¬(AB)(A + ¬BC)
• Simplified Circuit:
A
B D
C
– Reduction from 6 gates to 3!
7/2/2018 CS61C Su17 - Lecture 9 68