Logic
Logic
Dr.Ahmed Bayoumi
Dr.Shady Elmashad
Objectives
Identify the basic gates and describe the behavior of each
Combine basic gates into circuits
Describe the behavior of a gate using Boolean
expressions, truth tables, and logic diagrams
Definition
A gate is a device that performs a basic operation on
electrical signals
Gates are combined into circuits to perform more
complicated tasks
describing the behavior of gates
and circuits by
Boolean expressions
logic diagrams
truth tables
Gates
six types of gates
NOT
AND
OR
XOR
NAND
NOR
NOT Gate
A NOT gate accepts one input value
and produces one output value
By definition, if the input value for a NOT gate is 0, the
output value is 1, and if the input value is 1, the output is 0
A NOT gate is sometimes referred to as an inverter
because it inverts the input value
AND Gate
4–8
NAND and NOR Gates
Because there are three inputs to this circuit, eight rows are required
to describe all possible input combinations
This same circuit using Boolean algebra:
(AB + AC)
4–14
Now let’s go the other way; let’s take a
Boolean expression and draw
• Now compare the final result column in this truth table to the truth table for
the previous example
• They are identical
Properties of Boolean Algebra
Adders
At the digital logic level, addition is performed in binary
Addition operations are carried out
by special circuits called, appropriately, adders
The result of adding two binary digits could produce a
carry value
Recall that 1 + 1 = 10
in base two
A circuit that computes the sum of two bits
and produces the correct carry bit is called a half
adder
Adders
Circuit diagram representing
a half adder
Two Boolean expressions:
sum = A B
carry = AB
Integrated Circuits
Basic components
Instruction processing
The von Neumann Model - 1
Memory
MAR MDR
Processing Unit
Input ALU Register Set Output
*keyboard *monitor
Control Unit
PC IR
0-26
The von Neumann Model - 3
Processing Unit
ALU (Arithmetic and Logic Unit)
Generally operates on entire words of data
Some also work on subsets of words (eg. bits and bytes)
Registers:
Small, fast “on-board” storage for words
Close to the ALU (much faster access than RAM)
Control Unit
Program Counter (PC) or Instruction Pointer
Holds the address of the next instruction to be executed
Instruction Register (IR)
Holds the instruction being executed
The control unit coordinates all actions needed to execute the instruction
4 - 27
4 - 28
Arithmetic/Logic Operations
Logic: AND, OR, XOR
Rotate and Shift: circular shift, logical shift, arithmetic
shift
Arithmetic: add, subtract, multiply, divide
0-30
Instructions
Instruction word: 16 bits
Opcode
defines (names) the instruction to be executed
bits[15:12]: 4 bits allow 16 instructions
Operands
Registers: 8 registers (i.e. require 3 bits for addressing)
Address parameters: Offset (9 bits) or Index (6 bits) (more later)
Immediate value: 5 bits
Examples
ADD DR, SR1, SR2 ; DR (SR1) + (SR2)
[15:12] [11:9] [8:6] [2:0] - Note: (Reg1) means “content of Reg1”
Evaluate Address
Computes the address of the memory location required to process
the instruction (if any): e.g. the location from which to obtain a
value.
This is known as the Effective Address (EA).
Fetch Operands
Obtains the source operand(s) (if any) either from Registers or from
memory, i.e. from the EA calculated in the previous step.
Instruction Cycle - 4
Execute
Carries out the execution of the instruction - e.g. add two operands
present at the input of the ALU
Store Result
Writes the result (if any) to its designated destination, either
register or memory (using the EA calculated earlier)
Start over …
Recall that the PC was incremented already in the first step, so the
next Fetch will bring back the next instruction - unless the
instruction just executed changed the PC.
Instruction Cycle - 5
Some instructions don't need all 6 phases
If only using registers, skip Evaluate Address
If only moving data, skip Execute
Control Instructions
These change the sequence of instructions
Branch
Loop
Function or procedure call
Execute phase changes the content of the PC, so the next
instruction will be out of sequence.