You are on page 1of 28

Computer architecture, part

1:

What we’ll cover for this


lecture topic:
– What is a CPU?
– How is a program executed
by the CPU?
– Boolean logic
– Binary circuits that can add!

COMP 4—Power Tools for the Mind What’s in the box? 1


Central Processing Unit (CPU):
– Carries out the program’s instructions!
• Operates on data it finds in the computer’s memory.
– Also called Microprocessor
• Includes all binary circuits that carry out arithmetic &
logic operations---reduced to a single IC.
– CPU has four key parts that we will examine:
• Control Unit
• Arithmetic & Logic Unit
• Registers
• Clock
And, of course, wires that connect everything
together.
COMP 4—Power Tools for the Mind What’s in the box? 2
—CONTROL UNIT (CU): circuitry for coordinating
machine’s activities. Controls sequence of operations.
—ARITHMETIC & LOGIC UNIT (ALU): circuitry
to perform data manipulation (arithmetic & logic).
—Registers: Temporary storage areas. Holds
information applicable to the current operation.
—Clock: Triggers start and stop of all CPU operations.
(heartbeat) CPU
Two main
functional CU ALU
Registers
units:
clock What’s in the box? 3
COMP 4—Power Tools for the Mind
• CPUs support a set of very simple
instructions that typically fall into the
following categories:
• Data movement (load, store, copy…)
• Arithmetic/logical (add, subtract,
compare..)
• Program control (branch, halt…)
– Very primitive commands (operations) executed
by the CPU [logical structure]
– These commands are implemented as electronic
binary circuits [physical structure] which can
transform the 0s and 1s.
BASIC INSTRUCTION SET
COMP 4—Power Tools for the Mind What’s in the box? 4
Sample of a partial Basic instruction set
Instr: Meaning:
STO Store data in a particular memory location
ADD Add two numbers together
SUB Subtract one number from another
MUL Multiply two numbers
DIV Divide two numbers
INC Increment a number by adding 1
CMP Compare two numbers to see if they are equal
JMP Jump to a specific position in the instruction code

• Instructions are given to the processor in the form of


a program … so it knows what circuits to use, in
what order; and from where the data should be read
or to where it should be stored.
COMP 4—Power Tools for the Mind What’s in the box? 5
More specifically:
• A program consists of a sequence of
instructions.
• EACH instruction specifies both:
– The operation to perform
– The address of the data it will transform in that
operation (if necessary).
• Instructions are stored and processed in machine
language--also called microcode.
• Like everything else (e.g. like ASCII characters,
pixels of an image, …) machine language consists
solely of bit patterns.
COMP 4—Power Tools for the Mind What’s in the box? 6
Machine language or Machine Code
a/k/a microcode
– ML bit patterns are based directly on CPU’s instruction
set (on its binary circuits). So who created them?
– CPU chip: designed to recognize certain bit patterns as
representing certain ML instructions, which correspond
directly to certain available binary circuits.
– Each ML instruction contains a fixed-length
instruction code that:
• Identifies the operation to perform: op code
• Tells the CPU how to determine the operands

For example:
assume a 4-bit op-code + two 6-bit operands
= one 16 bit instruction
COMP 4—Power Tools for the Mind What’s in the box? 7
E.G.: An ADD instruction in a 16-bit machine language:
0101 110011 111100
Op-code: Operands: (RAM or Register addresses)
0101 110011 111100
• Before it can process a M.L. instruction, the CPU
must fetch it from main memory.
• The CPU must keep track of its position in the
instruction code. It uses a bookmark of sorts.
• The offset at which the next instruction starts is stored
in a special register, called the Program Counter or
Instruction Pointer. Important digression…
– who knows if bits in memory are data or program … ?
– increments to memory address of next instruction ...
COMP 4—Power Tools for the Mind What’s in the box? 8
Putting it all together
Processor: simple minded! repeats same steps over & over...
MACHINE CYCLE: “Instruction-Execution cycle”
Processing of a single machine-level instruction (one
Op Code) in a basic machine.

Instruction Cycle: in the Control Unit


1. FETCH
• Fetches instruction (from memory) at address given by
instruction pointer; copies it into CU storage register.
2. COPY & DECODE
• Copies op code into instruction register, operands into address
registers.
• Interprets instruction. ALU is invoked to perform decoded
operation for any ALU ops (enters Execution Cycle)
3. ADVANCE INSTRUCTION POINTER (counter)
• Pointer incremented; contains memory address of next instruction
that will be fetched. 9
Imprecise data representation, and a vast simplification--
but general concepts are correct.
A single Instruction cycle (Add) PROCESSOR
3 000001 Advance CONTROL , UNIT 2b Enter execute ALU
000011pointer
110011 cycle
Pointer
0101 2a Address reg
Instr. reg. Copy &
111100
1 Fetch Decode
0101 110011 111100 Address reg
Storage register

0101 1100 1111 1100 85 data shown in base 10 MEMORY


#000001 #000010 #110011 ….
0111 1110 0111 1110 65 data shown in base 10

#000011 #000100 #111100 ….


10
Imprecise data representation, and a vast simplification--
but general concepts are correct.
Another single Inst Cycle (Divide) PROCESSOR
3 000011 Advance CONTROL , UNIT 2b Enter execute ALU
000101pointer
111001 cycle
Pointer
0111 2a Address reg
Instr. reg. Copy &
111110
1 Fetch Decode
0111 111001 111110 Address reg
Storage register

0101 1100 1111 1100 85 data shown in base 10 MEMORY


#000001 #000010 #110011 ….
0111 1110 0111 1110 65 data shown in base 10

#000011 #000100 #111100 ….


11
Execution Cycle: by the CU/ALU
– Execution cycles vary, depending on the op code.
• Eg: load register R03 with contents of memory cell 47:
Just for culture: The CU causes the load to occur.
• CU activates ALU circuitry, which performs the actual
Op Code. EG: MUL, ADD, DIV, …
E.G: an arithmetic operation: ADD
1. LOAD
• Data copied from memory to ALU register.
2. ADD
• Data values are added in ALU adder circuitry.
3. COPY
• Result stored in ALU accumulator.
4. STORE
• Result copied from ALU to memory. 12
Execution cycle
PROCESSOR
C.U. ALU
3
85
Enter execute Result Register
cycle 85 + 65 copied to
= 150 Accumulator 65
2
Register
Data values
Adder 150
4
Accumulator
1 Data loaded to registers
MEMORY added
0101 1100 1111 1100 85 data shown in base 10 150
#000001 #000010 #111110 ….
#110011 ….
Result
0111 1110 0111 1110 65 data shown in base 10
stored in
#000011 #000100 #111100 …. memory
COMP 4—Power Tools for the Mind What’s in the box? 13
Boolean logic
• Boolean algebra: solve complex math problems
by reducing them to questions answered by Y/N.
– Logic gate: Mathematical operation that handles
only data that is represented in one of only two states:
TRUE/FALSE
– Physical gate: electronic device that transforms
binary input(s) to produce a single binary output,
according to its transformation rule.
– Many computer binary circuits employ complex
Boolean logic to perform various tasks.
• Such circuits can test the truth of propositions by making
comparisons, as well as carry out complex calculations.
• Gates: AND, OR, NOT
COMP 4—Power Tools for the Mind What’s in the box? 14
Truth tables
STRICT Parents COOL Parents Stubborn child
AND
ANDtruth
truth
table
table OR truth table
Homework? Clean? Homework? Clean? NOT truth table
2 Inputs1 Output 2 Inputs1 Output
1 Input1 Output
0 0 0 0 0 0
0 1 1
0 1
0 1 0
1
1 0
1 0 0 1 0
1 1 1 1 1 1

– Engineers design binary computer circuits


using gates based on truth tables.
– Gates: building blocks of all digital devices!
– Such circuits can carry out +, –, *, /,
comparisons, and many complex operations.
COMP 4—Power Tools for the Mind What’s in the box? 15
Digital
Logic
• Remember, the fundamental part of the digital
computer is the switch.
• A switch simply lets current either flow
completely or not at all (binary) :
– Relay: mechanical switch
– Vacuum tubes: electronic switch
– Transistors: electronic switch
– ICs: use many transistors on a circuit board
• Speed of computer determined by how fast a
switch “switches”!
COMP 4—Power Tools for the Mind What’s in the box? 16
Transistor
How does a transistor work?
Current trying
If input voltage is low (binary 0) the to flow
switch opens and the current through
cannot pass through.

Input Transistor
Voltage (Switch)

If input voltage is high (binary 1), the


switch closes and the current passes
through freely.

COMP 4—Power Tools for the Mind What’s in the box? 17


Logic
Gates
Transistors are only switches. They simply
determine whether or not current can pass
through a wire.
Transistors are used to create logic gates.
These gates perform logic operations on the
input voltages and give the result in form of
an output voltage.
Let’s construct a few simple gates to see how
this works…

COMP 4—Power Tools for the Mind What’s in the box? 18


NOT gate
When input is low, then switch is open, Steady current
and high current flows to output. (high)

When input is high, then switch is


closed, and the current is grounded Output
(instead of passing into output), therefore Voltage
the output voltage is low.
Input
Voltage

logical operator: NOT


Low input becomes high IN OUT
output. 0 1
High input become low Ground
1 0
(low)
output.
COMP 4—Power Tools for the Mind What’s in the box? 19
NAND gate (NOT
AND) If both inputs are
IN1 IN2 OUT
High, then current
0 0 1 passes through, and
0 1 1 Input Input
1 0 1
output is Low.
Voltage 1 Voltage 2
1 1 0
If either input is Low,
switch closes, and
output is High.

Steady
current
(high)

Ground
(low) Output
Voltage
COMP 4—Power Tools for the Mind What’s in the box? 20
NOR gate (NOT
If both inputs are Low, thenOR)
neither switch is closed, and
Steady current
output is High. (high)
If either input is High, a switch
opens, and output is Low.
Output
Voltage

Input Input
Voltage 1 Voltage 2

IN1 IN2 OUT


0 0 1
0 1 0
1 0 0 Ground Ground
1 1 0
(low) (low)

COMP 4—Power Tools for the Mind What’s in the box? 21


Digital
Logic
• We have only created NOT, NAND, and
NOR. We wanted ANDs and ORs as well…
• Just feed output of NAND and NOR into
NOT gate.
• Actually, all boolean logic expressions can
be constructed just from NAND or from
NOR – complete!
• Demo: 4-bit half adder

COMP 4—Power Tools for the Mind What’s in the box? 22


How can binary circuits ADD?

1 OR 1 AND 1
Output
Bit

+ 0 AND 0 NOT 1
0
0 1
Carry
You will not have to reconstruct diagrams! Bit
But you should know how to evaluate Boolean ops.
16
How can binary circuits ADD?

1 OR 1 AND 0
Output
Bit

+ 1 AND 1 NOT 0

1
1 0
Carry
Bit

17
What about other operations?
• Subtraction
– Addition using two’s complement representation
• Multiplication
– Repeated addition (with bit shifting)
• Division
– Repeated subtraction (with bit shifting)

Basically, a computer just adds.

COMP 4—Power Tools for the Mind What’s in the box? 25


Important digression!
– What kind of code do programmers use? Source Code
– What is the only kind of code a CPU Machine Code
understands? or Object code
– So, what has to occur before the CPU Translation
can execute a source-code program? or Compilation
High-level language
(source code) Machine language
(object code)

e.g.:
Turing
Translat
or
COMP 4—Power Tools for the Mind(Compile What’s in the box? 26
An Analogy
Carbon-based unit
JOHNNY, age 4 (obeys orders to
transform raw material into tasty sandwiches.)
Basic Instruction Set:
Simple commands he can do: Go, Bring, Unwrap, …
Child brain, hands, skills he uses.
Grandpa’s commands:
“Please make 2 p&j sandw’s on rye!”

Mom: Grandpa language to Child Talk


Child-talk instructions to
Johnny that he understands:
GO to pantry.
BRING bread & PB to kitchen.
UNWRAP bread.
PULL OUT 4 slices ….
20
Silicon-based unit
CPU (obeys orders to Johnny
transform raw data into meaningful info.)
STO; ADD; SUB; MUL; DIV; what Johnny
INC; CMP; JMP… Basic Instruction Set: can do
Primitive commands (log’l) it can do
Computer circuits (phy’l) it uses
Source code Grandpa’s command
Answer := Num1 + Num2
Translator prog: Mom translates
Source to object
Object code (Low-level ML) Child
so CPU can understand it: talk
0010 00001100 0111 LOAD M012 R07
0010 00001101 1000 LOAD M013 R08
0101 0111 1000 0010 as binary
0011 0010 00100001 ADD R07 R08 R02 21
codes

You might also like