Csa Unit 3
Csa Unit 3
The part of computer that do data processing operations is called central processing unit (CPU)
The CPU is made of 3 parts:
1. Registers: stores intermediate data generated during execution
2. ALU: performs required micro operations
3. Control Unit: controls transfer of data among registers and instruct ALU to perform correct operation
In Basic Computer, there is only one general purpose register, the Accumulator (AC) but in modern CPUs, there are many general purpose
registers. It is advantageous to have many registers
Transfer between registers within the processor are relatively fast. Going “off the processor” to access memory is much slower.
BUS SYSTEM
A new bus organization will be introduced in order to clarify the idea of register banking and how to control their actions.
7 CPU registers that their outputs are connected to 2 MUX 8 X 1 to form the 2 buses A and B.
The A and B are inputted to ALU unit in which its operation is selected by their select lines among different arithmetic and logic operations.
The resulted ALU data can is directed to the input of all 7 registers which one of them will be selected according to 3 X 8 decoder connected
to LD inputs of the registers
bits to select A source, 3 bits to select B source, 5 bits to select operation required on them, and finally 3 bits to select destination register.
Encoding of 3 bits for selection of the 2 sources plus the destination is defined in next table. While the other table specifies ALU operations
encoding.
ALU
EXAMPLES
R1 R2 – R3
Stack Organization
Stack is a storage device that stores information in a way that the item is stored last is the first to be retrieved (LIFO).
Stack in computers is actually a memory unit with address register (stack pointer SP) that can count only. SP value always points at top item
in stack.
The two operations done on stack are
PUSH (Push Down), operation of insertion of items into stack
POP (Pop Up), operation of deletion item from stack
Those operation are simulated by INC and DEC stack register (SP).
1. Register stack
A stand alone unit that consists of collection of finite number of registers.
64 location stack unit with SP that stores address of the word that is currently on the top of stack.
3 items are placed in the stack A, B, and C. Item C is in top of stack so that SP holds 3 which the address of item C.
To remove top item from stack (popping stack) we start by reading content of address 3 and decrementing the content of SP. Item B is now
in top of stack holding address 2.
To insert new item (pushing the stack) we start by incrementing SP then writing a new word where SP now points to (top of stack).
in 64 word stack we need to have SP of 6 bits only (from 000000 to 111111). If 111111 is reached then at next push SP will be 000000, that
is when the stack is FULL. Similarly when SP is 000001 then at next pop SP will go to 000000 that is when the stack is EMTY.
Initially, SP = 0, EMPTY = 1, FULL =0
Procedures for pushing stack
SP SP + 1
M[SP] DR
IF (SP = 0) THEN (FULL = 1)
EMTY 0
DR M [SP]
SP SP + 1
initial value of SP is 4001 and first item when pushed in stack stores at address 4000 and second one stores at address 3999. The last address
pushed into will be 3000. (See limitation danger?)
Most computers are not supported by hardware to sense stack overflow and underflow. But can be implemented by saving the 2 limits in 2
registers. After each push or pop the SP is compared with the limit to see if stack has reached its limits. So must be taking care of using
software.
3. Reverse Polish Notation
Very useful notation to utilize stacks to evaluate arithmetic expressions.
infix notation:
A*B + C*D
We compute A*B, store product, compute C*D, then sum two products. So we have to scam back and forth to see which operation comes
first.
The 3 notations to evaluate expressions
1. A + B Infix notation
2. +AB Prefix notation (Polish notation)
3. AB+ Postfix notation (reverse Polish notation)
Reverse Polish Notation is in a form suitable for stack manipulation. Starts by scanning expression from left to right. When operator is
found then perform operation with 2 operands in left of operator and replace result place of 2 operands and operator. Then we can continue
this until you reach final answer.
Example
Expression A*B + C*D is written in RPN as AB*CD*+. And will be computed as
(A*B) CD *+
(A*B)(C*D)+
Example
Convert infix notation expression (A + B)*(C * (D + E) + F) to RPN?
AB+ DE+ C * F+ *. Will be computed as (A+B) (D+E) C * F + *
Reverse polish notation combined with stack comprised of registers is most efficient way to evaluate expression. Stacks are good for
handling long and complex problems involving chain calculations. But need first to convert arithmetic expressions into parenthesis-free
reverse polish notation.
This procedure is employed in some scientific calculators and some computers
Instruction Format
The Instruction coding fields in today’s computers follow the next format
1. Operation code field to specify operation
2. Address field that specifies operand address field or register
3. Mode field to specify effective address
In general, most processors are organized in one of 3 ways
Single register (Accumulator) organization
o Basic Computer is a good example
o Accumulator is the only general purpose register
Stack organization
o All operations are done using the hardware stack
o 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
Example:
1. Three-Address Instructions
2. Two-Address Instructions
Addressing Modes
The addressing mode specifies the rule for translating or modifying the address field of the instruction before the operand i s fetched. The
way the operands are chosen during program execution is dependent on addressing modes.
Load instruction is used to transfer data from memory to processor register(s) (Accumulator).
Store instruction transfers data from register(s)(Accumulator) to memory.
Move instruction is used to move data from registers and from register to memory and vice versa.
Exchange instruction swaps data between 2 registers or between 2 memory locations.
Input-Output instructions transfer data between processors and IO device
Push-Pop instructions transfer data between stack and registers
Arithmetic Instructions
They will be the 4 basic operations: Add, Subtract, Multiply, and Divide.
Multiplication and Division usually generated using software subroutines.
Next table shows typical arithmetic instructions in general processors.
ADD, SUB, MUL, DIV instructions may operate with different data types whether available in registers or memory.
o Like in integer type, floating Point type, and BCD type
o Needs special instructions
ADDI add integers
ADDF add floating point
ADDD add in BCD
Since number of bits in registers is finite and hence resulted data are finite precision, some processors support hardware double precision
operations arithmetic that occupies 2 words.
Logical instructions perform binary operations on bits stored in registers and maybe in memory.
Helpful for manipulating single bits or group of bits
Performs on single bits as separated from each other and treated as Boolean variable.
Clear instruction forces all bits of operand to be 0
o Complement instruction inverts all bits of operand (0 1, 10).
Shift instructions
Shifts are : logical shifts, arithmetic shifts, and rotate type instructions
The program control instructions may change address in PC and cause the normal sequential execution to be. So this types of i nstruction
causes breaks in execution sequence.
Branch and jump instructions are usually the same and they execute immediate change of program sequence to another address.
Branch and Jump instructions may be conditional or unconditional. in conditional case specifies a condition (aero, positive, negative, greater
than, and so on) if condition is met the execution transfers to new address. If not met then execution continues sequentially.
Skip instruction skips the instruction immediately after it and executes the next then next one. Conditional skip will do the skip if a
condition is met
SKIP ON COND
BRA AD1
BRA AD2
Call and Return instructions are used with subroutines to jump to and come back from subroutines.
Compare instruction subtracts the 2 operand and change some flags in status register. Used to make conditional jumps afterword.
Test instruction performs AND between 2 operands and conditional flags will be changed accordingly.
Reference