Unit 2 Co
Unit 2 Co
Contents:
1. Register Transfer Language 11. Stack Organization
2. Arithmetic Microoperations 12. Instruction Formats
3. Logic Microoperations
4. Shift Microoperations
5. Arithmetic Logic Shift Unit
6. Instruction codes
7. Computer Instructions
8. Instruction Cycle
9. Memory-Reference Instructions
10. Input-Output and Interrupt
1. Register Transfer Language
SIMPLE DIGITAL SYSTEMS
Typically,
Operations are performed on the data in the registers.
Load
Clear
Increment
…
Microoperations (2)
An elementary operation performed (during one clock pulse),
on the information stored in one or more registers.
R f(R, R)
f: shift, load, clear, increment, add, subtract, complement, and, or, xor, …
Organization of a Digital System
The internal organization of a computer is defined as
1. Set of registers and their functions.
2. Microoperations (Set of allowable microoperations provided by the
organization of the computer).
3. Control signals that initiate the sequence of microoperations (to
perform the functions).
Register Transfer Level
Viewing a computer, or any digital system, in this way is called
the register transfer level.
For any function of the computer, the register transfer language can be
used to describe the (sequence of) microoperations.
registers)
Shift microoperations
Arithmetic Microoperations cont.
The basic arithmetic microoperations are:
➢ addition
➢ subtraction
➢ increment
➢ decrement
Addition Microoperation:
R3 R1+R2
Subtraction Microoperation:
R3 R1+ R2 +1
Arithmetic Microoperations cont
One’s Complement Microoperation:
R2 R2
R2 R2+1
Increment Microoperation:
R2 R2+1
Decrement Microoperation:
R2 R2-1
Summary of Typical Arithmetic Micro-Operations
Operations Description
R3 R1 + R2 Contents of R1 plus R2 transferred to R3
R3 R1 - R2 Contents of R1 minus R2 transferred to R3
R2 R2 Complement the contents of R2
R2 R2+ 1 2's complement the contents of R2 (negate)
R3 R1 + R2+ 1 subtraction
R1 R1 + 1 Increment
R1 R1 - 1 Decrement
Arithmetic Microoperations: Binary Adder
B3 A3 B2 A2 B1 A1 B0 A0
C3 C2 C1
FA FA FA FA C0
C4 S3 S2 S1 S0
C3 C2 C1 C0
FA FA FA FA
C4 S3 S2 S1 S0
4-bit adder-subtractor
Arithmetic Microoperations Binary Incrementer
A3 A2 A1 A0 1
x y x y x y x y
HA HA HA HA
C S C S C S C S
C4 S3 S2 S1 S0
This circuit performs seven distinct arithmetic operations and the basic
component of it is the parallel adder.
3 2 1 0 S1 S0 3 2 1 0 S1 S0 3 2 1 0 S1 S0 3 2 1 0 S1 S0
Y3 X3 Y2 X2 Y1 X1 Y0 X0
C3 C2 C1
FA FA FA FA Cin
Cout D3 D2 D1 D0
4x1
S1
S0
Y1 FAC2
D1
B1 0
1
2
3MUX
A2 X2 C2
S1 D2
B2 0
4x1
S0
Y2 FAC3
1
2
3MUX
A3 X3 C3
S1
S04x1 FAC4
D3
B3 0 Y3
1
2
3
MUX Cout
0 1
There are,16 different logic functions that can be defined over two binary input
variables
Truth tables for 16 functions of 2 variables and the corresponding 16 logic micro-operations
Logic Microoperations
OR Microoperation
Symbol: , +
Gate:
• Gate:
• Symbol:
−
• Gate:
• Gate:
1
4X1 Fi
MUX
2
3 Select
S1
S0
Function table
S1 S0 Output -operation
0 0 F=AB AND
0 1 F=AB OR
1 0 F=AB XOR
1 1 F = A’ Complement
4. Shift Microoperations
There are three types of shifts
Logical shift
Circular shift
Arithmetic shift
Serial
input
Examples:
R2 shr R2
R3 shl R3
Circular Shift
In a circular shift the serial input is the bit that is shifted out of the other end of the
register.
Examples:
R2 cir R2
R3 cil R3
Arithmetic Shift
An arithmetic shift is meant for signed binary numbers
(integer).
R n-1 R n-2 R1 R0
– Examples:
» R2 ashr R2
» R3 ashl R3
Arithmetic Shifts
Shifts a signed binary number to the left or right
S
MUX H0
0
1
A0
A1 S
MUX H1
0
A2 1
A3
S
MUX H2
0
1
S
MUX H3
0
1
Serial
input (IL)
5. Arithmetic Logic Shift Unit
S3
S2 Ci
S1
S0
Arithmetic Di
Circuit
Select
Ci+1
0 4x1 Fi
1 MUX
2
3
Ei
Logic
Bi
Ai
Circuit
Ai-1 shr
Ai+1 shl
15 0 Operands
Binary operand (data)
Processor register
Fig: Stored program organization (accumulator or AC)
Instruction Format
A computer instruction is often divided into two parts
An opcode (Operation Code) that specifies the operation for that instruction
An address that specifies the registers and/or locations in memory to use for that operation
In the Basic Computer, since the memory contains 4096 (= 212) words, we
needs 12 bit to specify which memory address this instruction will use
15 14 12 11 0
Opcode Address
I
Since the memory words, and hence the instructions, are 16 bits long, that
leaves 3 bits for the instruction’s opcode.
7. Basic Computer Instructions
• Basic Computer Instruction Format
3. Read the effective address from memory if the instruction has an indirect
address
Note: Every different processor has its own (different) instruction cycle .
Fetch and Decode
• Fetch and Decode T0: AR PC (S0S1S2=010, T0=1)
T1: IR M [AR], PC PC + 1 (S0S1S2=111, T1=1)
T2: D0, . . . , D7 Decode IR(12-14), AR IR(0-11), I IR(15)
T1 S2
T0 S1 Bus
S0
Memory
unit 7
Address
Read
AR 1
LD
PC 2
INR
IR 5
LD Clock
Common bus
Determine The Type Of Instruction
Start
SC
AR PC T0
T1
IR M[AR],PCPC +1
T2
Decode Opcode in IR(12-14),
AR IR(0-11), I IR(15)
(Register or I/O) = 1 = 0 (Memory-reference)
D7
(I/O) = 1 = 0 (register) (indirect) = 1 = 0 (direct)
I I
T3 T3
T3 T3
Execute Execute ARM[AR] Nothing
input-output register-reference
instruction instruction
SC 0 SC 0 Execute T4
memory-reference
instruction
SC 0
D'7IT3: AR M[AR]
D'7I'T3: Nothing
D7I'T3: Execute a register-reference instr.
D7IT3: Execute an input-output instr.
Register Reference Instructions
Register Reference Instructions are identified when
- D7 = 1, I = 0
- Register Ref. Instr. is specified in b0 ~ b11 of IR
- Execution starts with timing signal T3
AR = 135 135 21
136 Subroutine PC = 136 Subroutine
D0T 4 D1 T 4 D2T 4 D 3T 4
D0T 5 D1 T 5 D2T 5
AC AC DR AC AC + DR AC DR
SC 0 E Cout SC 0
SC 0
D5T 5 D6T 5
PC AR DR DR + 1
SC 0
D6T 6
M[AR] DR
If (DR = 0)
then (PC PC + 1)
SC 0
10. Input-Output And Interrupt
A Terminal with a keyboard and a Printer
• Input-Output Configuration
Input-output Serial Computer
terminal communication
interface registers and
Receiver flip-flops
Printer interface OUTR FGO
AC
Transmitter
Keyboard interface INPR FGI
INPR Input register - 8 bits
OUTR Output register - 8 bits Serial Communications Path
FGI Input flag - 1 bit Parallel Communications Path
FGO Output flag - 1 bit
IEN Interrupt enable - 1 bit
D7IT3 = p
IR(i) = Bi, i = 6, …, 11
p: SC 0 Clear SC
INP pB11: AC(0-7) INPR, FGI 0 Input char. to AC
OUT pB10: OUTR AC(0-7), FGO 0 Output char. from AC
SKI pB9: if(FGI = 1) then (PC PC + 1) Skip on input flag
SKO pB8: if(FGO = 1) then (PC PC + 1) Skip on output flag
ION pB7: IEN 1 Interrupt enable on
IOF pB6: IEN 0 Interrupt enable off
Program-Controlled Input/Output
Program-controlled I/O
Execute =0
IEN
instructions
=1 Branch to location 1
=1
FGI
PC 1
=0
=1
IEN 0
FGO R0
=0
R 1
1 BUN 0 1 BUN 0
Register Transfer Statements for Interrupt Cycle
- R F/F 1 if IEN (FGI + FGO)T0T1T2
T0T1T2 (IEN)(FGI + FGO): R 1
- The fetch and decode phases of the instruction cycle
must be modified ➔Replace T0, T1, T2 with R'T0, R'T1, R'T2
- The interrupt cycle :
RT0: AR 0, TR PC
RT2: PC PC + 1, IEN 0, R 0, SC 0
11. A Stack Machine
A Stack machine has a stack as
Processor a part of the processor state
typical operations:
stack Main push, pop, +, *, ...
Store
Instructions like + implicitly
: specify the top 2 elements of
the stack as operands.
push c
push b ➔ c pop
➔ b b ➔ b
a a a a
7/4/2025
Register Stack Organization
Stack
- Very useful feature for nested subroutines, nested interrupt services
- Also efficient for arithmetic expression evaluation
- Storage which can be accessed in LIFO
- Pointer: SP
- Only PUSH and POP operations are applicable stack Address
Register Stack Flags 63
FULL EMPTY
Stack pointer 4
SP C 3
6 bits B 2
A 1
Push, Pop operations 0
DR
PUSH POP
SP SP + 1 DR M[SP]
M[SP] DR SP SP − 1
If (SP = 0) then (FULL 1) If (SP = 0) then (EMPTY 1)
EMPTY 0 FULL 0
Memory Stack Organization
1000
Program
PC
Memory with Program, Data, (instructions)
SP 3000
stack
3997
3998
3999
- A portion of memory is used as a stack with a processor 4000
4001
register as a stack pointer. Stack grows
In this direction
- PUSH: SP SP - 1
M[SP] DR
- POP: DR M[SP]
SP SP + 1
- Most computers do not provide hardware to check stack overflow (full stack) or
underflow (empty stack) → must be done in software
Reverse Polish Notation
• Arithmetic Expressions: A + B
A+B Infix notation
+AB Prefix or Polish notation
AB+ Postfix or reverse Polish notation
- The reverse Polish notation is very suitable for stack
manipulation
• Evaluation of Arithmetic Expressions
Any arithmetic expression can be expressed in parenthesis-free
Polish notation, including reverse Polish notation
(3 * 4) + (5 * 6) 34*56*+
6
4 5 5 30
3 3 12 12 12 12 42
3 4 * 5 6 * +
Processor Organization
In general, most processors are organized in one of 3 ways
Stack organization
All operations are done using the hardware stack.
For example, an OR instruction will pop the two top elements from the stack, do a
logical OR on them, and push the result on the stack.
12. Instruction Format
Instruction Fields
OP-code field - specifies the operation to be performed
Address field - designates memory address(es) or a processor register(s)
Mode field - determines how the address field is to be interpreted (to get effective
address or the operand)
• The number of address fields in the instruction format depends on the
internal organization of CPU.
• The three most common CPU organizations:
Single accumulator organization:
ADD X /* AC AC + M[X] */
General register organization:
ADD R1, R2, R3 /* R1 R2 + R3 */
ADD R1, R2 /* R1 R1 + R2 */
MOV R1, R2 /* R1 R2 */
ADD R1, X /* R1 R1 + M[X] */
Stack organization:
PUSH X /* TOS M[X] */
ADD
Three, and Two-Address Instructions
• Three-Address Instructions
Program to evaluate X = (A + B) * (C + D) :
ADD R1, A, B /* R1 M[A] + M[B] */
ADD R2, C, D /* R2 M[C] + M[D] */
MUL X, R1, R2 /* M[X] R1 * R2 */
• Two-Address Instructions
Program to evaluate X = (A + B) * (C + D) :