Computer Architecture
Computer Architecture
com/
Computer Architecture
CSC. 201
Third Semester
Special thanks to Mr. Arjun Singh Saud for providing this valuable note!
Prepared By: Arjun Singh Saud
Chapter 1
Data representation
Number System
Number of digits used in a number system is called its base or radix. We can categorize
number system as below:
- Binary number system
- Octal Number System
- Decimal Number System
- Hexadecimal Number system
Conversion between number systems (do yourself)
Therefore this approach is useful in the systems where there is much calculation than
input/output.
Therefore this approach is useful in the systems where there is much input/output than
arithmetic and logical calculation.
Complements
(R-1)'s Complement
(R-1)'s complement of a number N is defined as (rn -1) –N
Where N is the given number
r is the base of number system
n is the number of digits in the given number
To get the (R-1)'s complement fast, subtract each digit of a number from (R-1)
Example
- 9's complement of 83510 is 16410
- 1's complement of 10102 is 01012(bit by bit complement operation)
R's Complement
R's complement of a number N is defined as rn –N
Where N is the given number
r is the base of number system
n is the number of digits in the given number
To get the R's complement fast, add 1 to the low-order digit of its (R-1)'s complement
- 10's complement of 83510 is 16410 + 1 = 16510
- 2's complement of 10102 is 01012 + 1 = 01102
e.g.
+9 ==> 0 001001
-9 ==> 1 110111
Overflow Detection
If we add two n bit numbers, result may be a number with n+1 bit which cannot be stored
in n-bit register. This situation is called overflow. We can detect whether there is
overflow or not as below:
Case Unsigned numbers
Consider a 4-bit register
Maximum numbers that can be stored N<= 2n -1 = 15
If there is no end carry => No overflow
e.g.
6 0110
9 1001
15 1111
Overflow
Case Signed Numbers:
Consider a 5-bit register
Maximum and Minimum numbers that can be stored -2n-1 =< N<= +2n-1 -1
-16 =<N<= +15
To detect the overflow we seed to see two carries. Carry into the sign bit position and
carry out of the sign bit position.
If both carries are same => No overflow
6 0 0110
9 0 1001
15 0 1111
9 0 1001
+9 0 1001
18 1 0010
Mantissa
Signed fixed point number, either an integer or a fractional number
Exponent
Designates the position of the decimal point
Decimal Value
N=m*re
Where m is mantissa
r is base
e is exponent
Example
Consider the number N= 1324.567
Now
m = 0.1324567
e =4
r = 10
therefore
N= m * r e = 0.1324567 * 10 +4
Note:
In Floating Point Number representation, only Mantissa (m) and Exponent (e) are
explicitly represented. The position of the Radix Point is implied.
Another example
Consider the binary number N=1001.11 (6-bit exponent and 10-bit fractional mantissa)
Now
m= 100111000
e= 0 00100 = +4
r= 2
sign bit = 0
To normalize the above number we need to remove the leading zeros of mantissa and
need to subtract the exponent from the number of zeros that are removed.
i.e.
m= 1001110
e= 0 00100 = +4
Message Parity
1011001 0
1010010 1
Odd Parity
One bit is attached to the information so that the total number of 1 bits is an odd number
Message Parity
1011001 1
1010010 0
Parity generator
Now
P=xyz
Parity Checker:
Considers original message as well as parity bit
e=pxyz
e= 1 => No. of 1’s in pxyz is even => Error in data
e= 0 => No. of 1’s in pxyz is odd => Data is error free
xy
P=x yz
p z
Excess-3: BCD + 3
Chapter 2
Register Transfer and microoperations
Combinational and sequential circuits can be used to create simple digital systems.
These are the low-level building blocks of a digital computer. The operations on the
data in registers are called microoperations. The functions built into registers are
examples of microoperations
– Shift
– Load
– Clear
– Increment
Alternatively we can say that an elementary operation performed during one clock
pulse on the information stored in one or more registers is called microopeartion.
Register transfer language can be used to describe the (sequence of) microoperations
Control Function
Often actions need to only occur if a certain condition is true. In digital systems, this is
often done via a control signal, called a control function.
e.g.
P: R2 R1
Which means “if P = 1, then load the contents of register R1 into register R2”, i.e., if (P =
1 then (R2 R1))
If two or more operations are to occur simultaneously, they are separated with commas
e.g.
P: R3 R5, MAR IR
Microoperations
Arithmetic microoperations
• The basic arithmetic microoperations are
– Addition
– Subtraction
– Increment
– Decrement
Binary Adder
To perform multibit addition in computer a full adder must be allocated for each bit so
that all bits can be added simultaneously. Thus, to add two 4-bit numbers to produce a
4-bit sum (with a possible carry), we need four full adders with carry lines cascaded, as
shown in the figure given below. For two 8-bit numbers, we need eight full adders, which
can be formed by cascading two of these 4-bit blocks. By extension, two binary numbers
of any size may be added in this manner.
B3 A3 B2 A2 B1 A1 B0 A0
FA C3 FA C2 FA C1 FA C0
C4 S3 S2 S1 S0
Binary Subtractor
The subtraction A – B can be done by taking the 2’s complement of B and adding it to A
because A- B = A + (-B). It means if we use the inverters to make 1’s complement of B
(connecting each Bi to an inverter) and then add 1 to the least significant bit (by setting
carry C0 to 1) of binary adder, then we can make a binary subtractor.
Binary Incrementer
The increment microoperation adds one to a number in a register. For example, if a 4-bit
register has a binary value 0110, it will go to 011 1 after it is incremented. This can be
accomplished by means of half-adders connected in cascade.
A = A +1
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
Cin
S1
S0
A0 X0 C0
S1 FA D0
S0
B0 0 4x1 Y0 C1
1 MUX
2
3
A1 X1 C1
S1 FA D1
S0
B1 0 4x1 Y1 C2
1 MUX
2
3
A2 X2 C2
S1 FA D2
S0
B2 0 4x1 Y2 C3
1 MUX
2
3
A3 X3 C3
S1 FA D3
S0
B3 0 4x1 Y3 C4
1 MUX
2
3 Cout
0 1
If s0 and s1 both are zero mux selects the input a lebel 0 (i.e. Y= B) Then adder adds A
and Y and cin (i.e. A and B and cin)
D=A+B if cin=0
D = A + B+1 if cin=1
If s0 =0 and s1=1 mux selects the input at label 1 (i.e. Y= B’) Then adder adds A and Y
(i.e. A and B’ and cin)
D = A + B’ if cin=0
D = A + B’ +1 if cin=1
If s0 =1 and s1=0 mux selects the input at label 2 (i.e. Y= 0000) Then adder adds A and Y
(i.e. A and 0 and cin)
D=A if cin=0
D = A +1 if cin=1
If s0 =1 and s1=1mux selects the input at label 3 (i.e. Y= 1111= -1) Then adder adds A
and Y (i.e. A and -1 and cin)
D=A-1 if cin=0
D=A if cin=1
Logic Microoperations
Logic microoperations are bit-wise operations, i.e., they work on the individual bits of
data. It is useful for bit manipulations on binary data. Useful for making logical
decisions based on the bit value. There are, in principle, 16 different logic functions
that can be defined over two binary input variables. However, most systems only
implement four of these
– AND (), OR (), XOR (), Complement/NOT
The others can be created from combination of these
Ai
0
Bi
1
4X1 Fi
MUX
2
3 Select
S1
S0
S1 S0 Output -operation
0 0 F=AB AND
0 1 F = AB OR
1 0 F=AB XOR
1 1 F = A’ Complement
– Selective-set AA+B
– Selective-complement AAB
– Selective-clear A A • B’
– Mask (Delete) AA•B
– Clear AAB
– Insert A (A • B) + C
– Compare AAB
Selective-set
In a selective set operation, the bit pattern in B is used to set certain bits in A
1 1 0 0 At
1010B
1 1 1 0 At+1 (A A + B)
If a bit in B is set to 1, that same position in A gets set to 1, otherwise that bit in A
keeps its previous value
Selective-complement
In a selective complement operation, the bit pattern in B is used to complement
certain bits in A
1 1 0 0 At
1010B
0 1 1 0 At+1 (A A B)
If a bit in B is set to 1, that same position in A gets complemented from its original
value, otherwise it is unchanged
Selective-clear
n a selective clear operation, the bit pattern in B is used to clear certain bits in A
1 1 0 0 At
1010B
0 1 0 0 At+1 (A A B’)
If a bit in B is set to 1, that same position in A gets set to 0, otherwise it is unchanged
Mask Operation
In a mask operation, the bit pattern in B is used to clear certain bits in A
1 1 0 0 At
1010B
1 0 0 0 At+1 (A A B)
If a bit in B is set to 0, that same position in A gets set to 0, otherwise it is unchanged
Clear Operation
In a clear operation, if the bits in the same position in A and B are the same, they are
cleared in A, otherwise they are set in A
1 1 0 0 At
1010B
0 1 1 0 At+1 (A A B)
Insert Operation
An insert operation is used to introduce a specific bit pattern into A register, leaving the
other bit positions unchanged.
This is done as
– A mask operation to clear the desired bit positions, followed by
– An OR operation to introduce the new bits into the desired positions
– Example
» Suppose you wanted to introduce 1010 into the low order four bits
of A: 1101 1000 1011 0001 A (Original)
1101 1000 1011 1010 A (Desired)
Shift Micro-Operations
There are three types of shifts
– Logical shift
– Circular shift
– Arithmetic shift
Right shift operation
Serial
input
Seria
input
In a circular shift the serial input is the bit that is shifted out of the other end of the
register.
An arithmetic shift is meant for signed binary numbers (integer). An arithmetic left shift
multiplies a signed number by two and an arithmetic right shift divides a signed number
by two. The main distinction of an arithmetic shift is that it must keep the sign of the
number the same as it performs the multiplication or division
sig
bit
S
H0
0 MUX
1
A0
A1 S
H1
0 MUX
A2 1
A3
S
H2
0 MUX
1
S
H3
0 MUX
1
Chapter 3
Basic Computer Organization and Design
Introduction
Every different processor type has its own design (different registers, buses,
microoperations, machine instructions, etc). Modern processor is a very complex
device. It contains
– Many registers
– Multiple arithmetic units, for both integer and floating point calculations
– The ability to pipeline several consecutive instructions to speed execution
– Etc.
However, to understand how processors work, we will start with a simplified
processor model. M. Morris Mano introduces a simple processor model he calls the
Basic Computer. The Basic Computer has two components, a processor and memory
• The memory has 4096 words in it
– 4096 = 212, so it takes 12 bits to select a word in memory
• Each word is 16 bits long
CPU RAM
0
15 0
4095
The instructions of a program, along with any needed data are stored in memory. The
CPU reads the next instruction from memory. It is placed in an Instruction Register
(IR). Control circuitry in control unit then translates the instruction into the sequence
of microoperations necessary to implement it
Instruction Format
1 1 1 1 0
5I 4Opcode
2 1 Address
Addressing
Mode
Addressing Modes
The address field of an instruction can represent either
– Direct address: the address operand field is effective address (the address
of the operand), or
– Indirect address: the address in operand field contains the memory address
where effective address resides.
2 0 ADD 45 3 1 ADD 30
2 7 5 0
30 135
0 0
45 Operand
7
135 Operand
0
+ +
AC AC
Since the memory in the Basic Computer only has 4096 (=212) locations, PC and AR only
needs 12 bits
Since the word size of Basic Computer only has 16 bit, the DR, AC, IR and TR needs 16
bits.
The Basic Computer uses a very simple model of input/output (I/O) operations
– Input devices are considered to send 8 bits of character data to the
processor
– The processor can send 8 bits of character data to output devices
The Input Register (INPR) holds an 8 bit character gotten from an input device
The Output Register (OUTR) holds an 8 bit character to be send to an output device
S2 S1 S0 Register
0 0 0 x
0 0 1 AR
0 1 0 PC
0 1 1 DR
1 0 0 AC
1 0 1 IR
1 1 0 TR
1 1 1 Memory
S1 Bus
S0
Memory unit 7
4096 x 16
Address
Write Read
AR 1
LD INR CLR
PC 2
LD INR CLR
DR 3
LD INR CLR
E
ALU AC 4
LD INR CLR
INPR
IR 5
LD
TR 6
LD INR CLR
OUTR
Clock
LD
16-bit common bus
Either one of the registers will have its load signal activated, or the memory will have
its read signal activated
– Will determine where the data from the bus gets loaded
The 12-bit registers, AR and PC, have 0’s loaded onto the bus in the high order 4 bit
positions. When the 8-bit register OUTR is loaded from the bus, the data comes from
the low order 8 bits on the bus
15 14 12 11 0
I Opcode Operand
15 14 12 11 0
0 111 Register Operation
15 14 12 11 0
1 111 I/O Operation
ADD, CMA (complement), INC can be used to perform addition and subtraction and CIR
(circular right shift), CIL (circular left shift) instructions can be used to achieve any kind
of shift operations. Addition subtraction and shifting can be used together to achieve
multiplication and division. AND, CMA and CLA (clear accumulator) can be used to
achieve any logical operations.
LDA instruction moves data from memory to register and STA instruction moves data
from register to memory.
The branch instructions BUN, BSA and ISZ together with skip instruction provide the
mechanism of program control and sequencing.
INP instruction is used to read data from input device and OUT instruction is used to
send data from processor to output device.
Control Unit
Control unit (CU) of a processor translates from machine instructions to the control
signals for the microoperations that implement them. Control units are implemented in
one of two ways
• Hardwired Control
– CU is made up of sequential and combinational circuits to generate the
control signals
– If logic is changed we need to change the whole circuitry
– Expensive
– Fast
• Microprogrammed Control
– A control memory on the processor contains microprograms that activate
the necessary control signals
– If logic is changed we only need to change the microprogram
– Cheap
– Slow
Hardwired control unit of Basic Computer
3x8
decoder
7 6543 210
D0
I Combinational
D7 Control
logic
T15
T0
15 14 . . . . 2 1 0
4 x 16
decoder
T0 T1 T2 T3 T4 T0
Clock
T0
T1
T2
T3
T4
D3
CLR
SC
After an instruction is executed, the cycle starts again at step 1, for the next
instruction
T1 S2
T0 S1 Bus
S0
Memory
unit 7
Address
Read
AR 1
LD
PC 2
INR
IR 5
LD Clock
Common bus
Start
SC
AR PC T0
IR M[AR], PC PC + 1 T1
(Register or I/O) = 1 D7
= 0 (Memory-reference)
T3 T3 T3 T3
Execute Execute AR M[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.
let
r = D7 IT3 => Register Reference Instruction
Bi = IR(i) , i=0,1,2,...,11
CLA rB11: AC 0, SC 0
CLE rB10: E 0, SC 0
CMA rB9: AC AC’, SC 0
CME rB8: E E’, SC 0
CIR rB7: AC shr AC, AC(15) E, E AC(0), SC 0
CIL rB6: AC shl AC, AC(0) E, E AC(15)
INC rB5: AC AC + 1, SC 0
SPA rB4: if (AC(15) = 0) then (PC PC+1), SC 0
SNA rB3: if (AC(15) = 1) then (PC PC+1), SC 0
SZA rB2: if (AC = 0) then (PC PC+1), SC 0
SZE rB1: if (E = 0) then (PC PC+1), SC 0
HLT rB0: S 0, SC 0 (S is a start-stop flip-flop)
The effective address of the instruction is in AR and was placed there during
timing signal T2 when I = 0, or during timing signal T3 when I = 1
- Memory cycle is assumed to be short enough to complete in a CPU cycle
- The execution of memory reference instruction starts with T4
Operation
Symbol Decoder Symbolic Description
AND D0 AC AC M[AR]
ADD D1 AC AC + M[AR], E Cout
LDA D2 AC M[AR]
STA D3 M[AR] AC
BUN D4 PC AR
BSA D5 M[AR] PC, PC AR + 1
ISZ D6 M[AR] M[AR] + 1, if M[AR] + 1 = 0 then PC PC+1
AND to AC
D0T4: DR M[AR] //Read operand
D0T5: AC AC DR, SC 0 //AND with AC
ADD to AC
D1T4: DR M[AR] //Read operand
D1T5: AC AC + DR, E Cout, SC 0 //Add to AC and stores carry in E
LDA: Load to AC
D2T4: DR M[AR] //Read operand
D2T5: AC DR, SC 0 //Load AC with DR
STA: Store AC
AC
Transmitter
Keyboard interface INPR FGI
- The flags are needed to synchronize the timing difference between I/O device and
the computer
CPU:
/* Input */ /* Initially FGI = 0 */
loop: If FGI = 0 goto loop
AC INPR, FGI 0
Input Device:
loop: If FGI = 1 goto loop
INPR new data, FGI 1
FGI=0
Start Input
FGI 0
yes
FGI=0
no
AC INPR
yes More
Character
no
END
CPU:
/* Output */ /* Initially FGO = 1 */
loop: If FGO = 0 goto loop
OUTR AC, FGO 0
Output Device:
loop: If FGO = 1 goto loop
consume OUTR, FGO 1
FGO=1
Start Output
AC Data
yes
FGO=0
no
OUTR AC
FGO 0
yes More
Character
no
END
Let
D7IT3 = p
IR(i) = Bi, i = 6, …, 11
Interrupt Cycle
R = Interrupt flip-flop
Instruction cycle = = Interrupt cycle
R
0 1
Execute =
IE
instructions 0
N= Branch to location 1
1 PC 1
= FG
1 I =
=
0 IEN 0
1
FG R0
O=
R1 0
Main Main
255 Program 255 Program
PC = 256 256
1120 1120
I/O I/O
Program Program
1 BUN 0 1 BUN 0
Control of AR register
Scan all of the register transfer statements that change the content of AR:
R’T0: AR PC LD(AR)
R’T2: AR IR(0-11) LD(AR)
D’7IT3: AR M[AR] LD(AR)
RT0: AR 0 CLR(AR)
D5T4: AR AR + 1 INR(AR)
Now,
LD(AR) = R'T0 + R'T2 + D'7IT3
CLR(AR) = RT0
INR(AR) = D5T4
1 1
From bus AR To bus
D'7 2 2
I
LD Clock
T3
T2 IN
R CLR
R
T0
D
T4
D
7
p
I J IE
Q
B7 N
T3
B6
K
R
T2
Selected
x1 x2 x3 x4 x5 x6 x7 S2 S1 S0 Register
0 0 0 0 0 0 0 0 0 0 none
1 0 0 0 0 0 0 0 0 1 AR
0 1 0 0 0 0 0 0 1 0 PC
0 0 1 0 0 0 0 0 1 1 DR
0 0 0 1 0 0 0 1 0 0 AC
0 0 0 0 1 0 0 1 0 1 IR
0 0 0 0 0 1 0 1 1 0 TR
0 0 0 0 0 0 1 1 1 1 Memory
To find the logic that makes x1=1 we scan and extract all the statements that use AR as
source.
D4T4: PC AR
D5T5: PC AR
=>
x1 = D4T4 + D5T5
x1
x2 S2
Multiplexer
x3
Encoder S1 bus select
x4
x5 inputs
x6 S0
x7
Control of AC Register
=>
LD(AC) = D0T5 + D1T5 + D2T5 + pB11 + rB9+ rB7 + rB6
CLR(AC) = rB11
INR (AC) = rB5
From Adder 16 16
AC To
and Logic
bus
D0 AND LD Clock
T5 INR
D1 ADD CLR
D2 DR
T5
p INPR
B 11
r COM
B9
SHR
B7
SHL
B6
INC
B5
CLR
B 11
Chapter 4
Microprogrammed control
Terminologies
Microprogram
Program stored in memory that generates all the control signals required to
execute the instruction set correctly
Consists of microinstructions
Microinstruction
Contains a control word and a sequencing word
Control Word – contains all the control information required for one clock cycle
Sequencing Word - Contains information needed to decide the next
microinstruction address
Control Memory(Control Storage: CS)
Storage in the microprogrammed control unit to store the microprogram
Address Sequencing
Process of finding address of next micro-instruction to be executed is called address
sequencing. Address sequencer must have capabilities of finding address of next micro-
instruction in following situations:
In-line Sequencing
Unconditional Branch
Conditional Branch
Subroutine call and return
Looping
Mapping from instruction op-code to address in control memory.
Instruction code
Mapping Logic
Incrementer
select a status
bit
Microoperations
Branch address
Control address register receives address of next micro instruction from different
sources.
Incrementer simply increments the address by one
In case of branching branch address is specified in one of the field of
microinstruction.
In case of subroutine call return address is stored in the register SBR which is
used when returning from called subroutine.
Conditional Branch
If Condition is true, set the appropriate field of status register to 1. Conditions are
tested for O (overflow), N (negative), Z (zero), C (carry), etc.
Then test the value of that field if the value is 1 take branch address from the next
address field of the current microinstruction)
Otherwise simple increment the address.
Unconditional Branch
Fix the value of one status bit at the input of the multiplexer to 1. So that always
branching is done
Mapping:
Mapping from the OP-code of an instruction to the address of the Microinstruction
which is the starting microinstruction of its subroutine in memory
Direct mapping:
Directly use opcode as address of Control memory
Address
OP-codes of Instructions 0000 ADD Routine
0001 AND Routine
ADD 0000
0010 LDA Routine
AND 0001 . 0011
LDA 0010 STA Routine
. 0100 BUN Routine
STA 0011
BUN 0100 .
Control
Storage
Machine OP-code
1 0 1 1 Address
Instruction
Mapping bits 0 x x x x 0 0
Microinstruction
address 0 1 0 1 1 0 0
Mapping memory
(ROM or PLA)
Control Memory
Microinstruction Format
3 3 3 2 2 7
F1 F2 F3 CD BR AD
Description of CD
Description of BR
BR Symbol Function
Symbolic Microinstruction
Symbols are used in microinstructions as in assembly language. A symbolic
mcroprogram can be translated into its binary equivalent y a microprogram assembler.
Format of Microinstruction:
Label: may be empty or may specify a symbolic address terminated with a colon
Micro-ops: consists of one, two, or three symbols separated by commas
ORG 64
FETCH: PCTAR U JMP NEXT
READ, INCPC U JMP NEXT
DRTAR U MAP
Binary equivalents translated by an assembler
Binary
Address F1 F2 F3 CD BR AD
Microprogram Sequencer
External
(MAP
)
L
I0 3 2 1 0
Input Load
I1 S1 MUX SB
logic
T S0 1 R
1 Incrementer
I MUX2 Test
S
Z Select
Clock CAR
Control memory
Microops C B A
... D R D. ..
MUX-1 selects an address from one of four sources and routes it into a CAR
- In-Line Sequencing CAR + 1
- Branch, Subroutine Call Take address from AD field
- Return from Subroutine Output of SBR
- New Machine instruction MAP
MUX-2 Controls the condition and branching as below
Input Logic
S0 = I0
S1 = I0I1 + I0’T
L = I0’I1T
F Field Decoding
microoperation fields
F F F
1 2 3
AND
ADD AC
Arithmetic
logic and
DRTAC DR
shift unit
P D From From
C R PC DR(0-10)
T T Load
A A
AC
R R
Select 0 1
Multiplexers
Load Clock
AR
Since there are three microoperation fields we need 3 decoders. Only some of the outputs
of decoders are shown to be connected to their output. Each of the output of the decoders
must be connected to the proper circuit to initiate the corresponding microoperation. For
example when F1=101 the next clock pulse transition transfers content of DR(0-10) to
AR (Symbolized by DRTAC). Similarly other operations are also performed.
Chapter 5
CENTRAL PROCESSING UNIT
Clock Input
R1
R2
R3
R4
R5
R6
R7
Load
(7 lines)
SELA { MUX A MUX B } SELB
3x8 A bus B bus
decoder
SELD
OPR ALU
Output
All registers are connected to two multiplexers (MUXA and MUXB) that select the
registers for bus A and bus B. Registers selected by multiplexers are sent to ALU.
Another selector (OPR) connected to ALU selects the operation for the ALU. Output
produced by CPU is stored in some register and the destination register for storing the
result is activated by the destination decoder (SELD).
Example: R1 R2 + R3
– MUX A selector (SELA): BUS A R2
– MUX B selector (SELB): BUS B R3
– ALU operation selector (OPR): ALU to ADD
– Decoder destination selector (SELD): R1 Out Bus
Control word
Combination of all selection bits of a unit is called control word. Control Word for above
CPU is as below
3 3 3 5
SELA SELB SELD OP
R
Examples of Microoperations for CPU
Symbolic Designation
Microoperation SELA SELB SELD OPR Control Word
Register Stack
It is the collection of finite number of registers. Stack pointer (SP) points to the register
that is currently at the top of stack.
stack Address
Flags 6
3
FULL EMPTY
Stack pointer
4
SP C 3
6 bits B 2
A 1
0
D
R
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
A portion of memory is used as a stack with a processor register as a stack pointer
100
Program 0
P (Instructions)
C
Data
AR (Operands)
S 300
P Stack 0
399
399
7
399
8
9
400
400
0
1 grows
Stack
In this direction
PUSH:
SP SP - 1
M[SP] DR
POP:
DR M[SP]
SP SP + 1
PROCESSOR ORGANIZATION
– Stack organization
» All operations are done with the 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
e.g.
PUSH X // TOS M[X]
ADD // TOS=TOP(S) + TOP(S)
Types of instruction:
The number of address fields in the instruction format depends on the internal
organization of CPU. On the basis of no. of address field we can categorize the
instruction as below:
• 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) :
MOV R1, A // R1 M [A]
ADD R1, B // R1 R1 + M [A]
MOV R2, C // R2 M[C]
ADD R2, D // R2 R2 + M [D]
MUL R1, R2 // R1 R1 * R2
MOV X, R1 // M[X] R1
• One-Address Instructions
• Zero-Address Instructions
Can be found in a stack-organized computer
Program to evaluate X = (A + B) * (C + D):
PUSH A // TOS A
PUSH B // TOS B
ADD // TOS (A + B)
PUSH C // TOS C
PUSH D // TOS D
ADD // TOS (C + D)
MUL // TOS (C + D) * (A + B)
POP X // M[X] TOS
Operation Symbol
Complement COM
AND AND
OR OR
Exclusive-OR XOR
Shift instructions
Some examples:
Operation symbol
Logical shift left SHL
Arithmetic shift right SHRA
Arithmetic shift left SHLA
Rotate right ROR
Rotate left ROL
+1
In-Line Sequencing (Next instruction is fetched from
the next adjacent location in the memory)
PC
Addressing Modes
Specifies a rule for interpreting or modifying the address field of the instruction
before the operand is actually referenced.
We use variety of addressing modes:
To give programming flexibility to the user
To use the bits in the address field of the instruction efficiently
• Implied Mode
Address of the operands are specified implicitly in the definition of the
instruction
- No need to specify address in the instruction
- Examples from Basic Computer CLA, CME, INP
ADD X;
PUSH Y;
• Immediate Mode
Instead of specifying the address of the operand, operand itself is specified in the
instruction.
- No need to specify address in the instruction
- However, operand itself needs to be specified
- Sometimes, require more bits than the address
- Fast to acquire an operand
• Register Mode
Address specified in the instruction is the address of a register
- Designated operand need to be in a register
- Shorter address than the memory address
600 900
702
325
800
300
Computers with many instructions and addressing modes came to be known as Complex
Instruction Set Computers (CISC).One goal for CISC machines was to have a machine
language instruction to match each high-level language statement type so that job of
compiler writer becomes easy. Characteristics of CISC computers are:
– The large number of instructions and addressing modes led CISC machines to
have variable length instruction formats
– Multiple operand instructions could specify different addressing modes for each
operand
– Variable length instructions greatly complicate the fetch and decode problem for a
processor
– They have instructions that act directly on memory addresses due to which
multiple memory cycle are needed for executing instructions.
– Microprogrammed control is used rather than hardwired
R73
Local to D
R64
R63 R63
Common to C and D
R58 R58
Proc D R57
Local to C
R48
R47 R47
Common to B and C
R42 R42
Proc C R41
Local to B
R32
R31 R31
Common to A and B
R26 R26
Proc B R25
Local to A
R16
R15 R15
Common Common to A and D
R10 to D and A R10
R9 Proc A
Common to all
procedures
R0
Global
– Global Registers
» Available to all functions
The advantage of overlapped register windows is that the processor does not have to push
registers on a stack to save values and to pass parameters when there is a function call.
This saves
– Accesses to memory to access the stack.
– The cost of copying the register contents at all
And, since function calls and returns are so common, this results in a significant savings
relative to a stack-based approach
Chapter 7
Input-Output Organization
I/O subsystem
The input-output subsystem (also referred as I/O) proves an efficient mode of
communication between the central system and outside environment. Data and programs
must be entered into the computer memory for processing and result of processing must
be must be recorded or displayed for the user
Peripheral devices
Any input/output devices connected to the computer are called peripheral devices.
Data
Processor Address
Control
Keyboard and
Display Magnetic Magnetic
Printer
terminal dsk Tape
I/O bus from the processor is connected to all peripheral interfaces. To communicate with
a particular device, the processor places a device address on the address lines. Each
peripheral has an interface module associated with its interface. Functions of an interface
are as below:
- Decodes the device address (device code)
- Decodes the I/O commands (operation or function code)
- Provides signals for the peripheral controller
- Synchronizes the data flow and
- Supervises the transfer rate between peripheral and CPU or Memory
I/O Bus
Communication between CPU and all interface units is via a common I/O bus. An
interface connected to a peripheral device may have a number of data registers, a control
register, and a status register. A command is passed to the peripheral by sending to the
appropriate interface register
Interface communicates with the CPU through the data bus. The chip select and register
select inputs determine the address assigned to the interface. Control lines I/O read and
write are used to specify the input and output respectively. Bidirectional lines represent
both data in and out from the CPU. Information in each port can be assigned a meaning
Downloaded from: http://www.bsccsit.com/ Page 60
Prepared By: Arjun Singh Saud
depending on the mode of operation of the I/O device: Port A = Data; Port B =Command;
Port C = Status. CPU initializes (loads) each port by transferring a byte to the Control
Register. CPU can define the mode of operation of each port
Modes of I/O transfer
Three different Data Transfer Modes between the central computer (CPU or Memory)
and peripherals;
- Program-Controlled I/O
- Interrupt-Initiated I/O
- Direct Memory Access (DMA)
Program-Controlled I/O (Input Dev to CPU)
- Continuous CPU involvement
- CPU slowed down to I/O speed
- Simple
- Least hardware
n Operation
Complete?
ye
Continue with
program
- Actual transfer of data is done directly between the device and memory through
DMA controller freeing CPU for other tasks
- DMA works by stealing the CPU cycles
Cycle Stealing:
- While DMA I/O takes place, CPU is also executing instructions
- DMA Controller and CPU both access Memory which causes memory Access
Conflict
- Memory Bus Controller is responsible for coordinating the activities of all devices
requesting memory access by using priority schemes
- Memory accesses by CPU and DMA Controller are interwoven; with the top
priority given to DMA Controller which is called cycle Stealing
- CPU is usually much faster than I/O(DMA), thus CPU uses the most of the
memory cycles
- DMA Controller steals the memory cycles from CPU for those stolen cycles, CPU
remains idle
- For those slow CPU, DMA Controller may steal most of the memory cycles which
may cause CPU remain idle long time
DMA Transfer
Interrupt
Random-access
BG
CPU memory unit (RAM)
BR
RD WR Addr Data RD WR Addr Data
Read control
Write control
Data bus
Address bus
Address
select
RD WR Addr Data
DS DMA ack.
RS DMA I/O
Controller Peripheral
BR device
BG DMA request
Interrupt
Input
– Send read control signal to Input Device
– DMA controller collects the input from input device byte by bye and assembles
the byte into a word until word is full
– Send write control signal to memory
– Increment address register (Address Reg <- Address Reg +1)
– Decrement word count (WC <- WC – 1)
– If WC = 0, then Interrupt to acknowledge done, else repeat same process
Output
– Send read control signal to memory
– Read data from memory
– Increment address register (Address Reg <- Address Reg +1)
– Decrement word count (WC <- WC – 1)
– Disassemble the word
– Transfer data to the output device byte by byte
– If WC = 0, then Interrupt to acknowledge done, else repeat same process
Central
processing
Mem unit (CPU)
ory Peripheral devices
Bus
Memory
unit PD PD PD PD
Input-output
processor
(IOP) I/O bus
Send instruction
to test IOP.path
Transfer status word
to memory
If status OK, then send
start I/O instruction
to IOP. Access memory
for IOP program
Continue
Chapter 8
Computer Arithmetic
Minuend
Minuend in
in A
A Augends in A
Subtrahend
Subtrahendinin Addend in B
=0 =1 =1 =0
As Bs As Bs
As Bs As = Bs
As = Bs
As Bs
EA A + B + 1 EA A + B + 1
=0 =1
E
AVF E
AB
A<B
A A A
=0
0
A A + 1 As 0
As As
END
Result in A and
Perform 45 + (-23)
Operation is add
45 = 00101101
-23 = 10010111
As = 0 A=0101101
Bs = 1 B=0010111
As Bs =1
Exercise
Perform
(-65) + (50), (-30) + (-12), (20) + (34), (40) – (60), (-20) – (50)
Minuend in AC Augends in AC
Subtrahend in Addend in BR
AC AC + BR + 1 AC AC + BR
V overflow V overflow
EN EN
D D
Example:
33 + (-35)
AC = 33 = 00100001
BR = -35 = 2’s complement of 35 = 11011101
Multiplicand in B
Multiplier in Q
As = Qs Bs
Qs = Qs Bs
A = 0, E = 0
SC = n-1
=0 =1
Q
n
EA = A + B
Shr EAQ
SC = SC -1
0 =0
S
END Product is in AQ
Example:
Perform 5 x – 4
Bs B = 5 = 0 0101
Qs Q = - 4 = 1 0100
As = 1
Qs = 1
E A Q SC
0 0000 0100 4
Step1
Qn =0
Shr 0 0000 0010 3
Step2
Qn =0
Shr 0 0000 0001 2
Step 3
Qn=1 0 0000 0001
0101
0 0101 0001
Shr 0 0010 1000 1
Step 4
Qn = 0
Shr 0 0001 0100 0
As AQ = 0001 0100 = - 20
Question:
Perform the operation 4 x 3, 6 x -7, -9 x 8 by using 5-bit representation
Multiply operation
Multiplicand in
BR
AC = 0
Qn +1 = 0
Sc = n
= 10 = 01
Qn
= 00
= 11
AC = AC + BR + 1 AC = AC + BR
Shr AC & QR
SC = SC -1
0 =0
SC
EN
D
BR = 10111
BR + 1 = 01001
Qn Qn+1 AC QR Qn+1 SC
1 0 00000 10011 0 5
Step 1
Subtract BR 01001 10011
AShr 00100 11001 1 4
Step 2
1 1 00100 11001 1 4
AShr 1 1 00010 01100 1 3
Step 4
0 0 11100 10110 0 2
AShr 0 0 11110 01011 0 1
Step 5
1 0 11110 01011 0 1
Subtract BR 01001
00111 01011 0 1
AShr 00011 10101 0 0
Divide Operation
Divide Magnitude
Dividend in
AQ
Divisor in B
Shl EAQ
=0 =1
Qs = As Bs E
SC = n-1
EA=A+B+1 EA=A+B+1
EA = A+B+1
=1
AB E
=1 =0 =0 A<B AB
E
A<B EA=A+B Qn = 1
EA=A+B EA=A+B
DVF = 1 DVF=0
SC = SC -1
=0 0
S
C
END END
Divide overflow Quotient in Q
remainder in A