COA MODULE 4 PART 2cdfsd
COA MODULE 4 PART 2cdfsd
● The part of the computer that performs the data-processing operations is called the central
teachics.org
processing unit(CPU).
1 3
Control Word
● The combined value of a binary selection inputs specifies the control word.
● It consist of four fields SELA,SELB,and SELD contains three bit each and OPR field contains four
bits thus the total bits in the control word are 13-bits.
● The three bit of SELA select a source registers of the a input of the ALU.
● The three bits of SELB select a source registers of the b input of the ALU.
● The three bits of SELD select a destination register using the decoder.
● The four bits of OPR select the operation to be performed by ALU.
Stack Organization
6 8
Stack Organization Register Stack
● A useful feature that is included in the CPU of most computers is a stack or last-in, first-out ● FULL = 1 , when stack is full & EMPTY=1 if stack is
(LIFO) list. empty
● The register that holds the address for the stack is called a stack pointer (SP) because its value ● Initially SP=0, EMPTY=1 and FULL=0
always points at the top item in the stack.
To delete an item.
● The stack in digital computers is essentially a memory unit with an address register that can
count only after an initial value is loaded into it. ● Item is deleted, if the stack is not empty.
● The two operations of a stack are the insertion and deletion of items. ● Read the top item into DR.
● If SP reaches 0, EMPTY is set to 1.
● Decrement SP by 1.
● DR ← M [SP]
SP ← SP — 1
If (SP = 0) then (EMTY ← 1)
FULL ← 0
9 11
10 12
Memory Stack Instruction Formats
● Implementated by assigning a portion of memory to a ● The bits of the instruction are divided into groups called fields.
stack operation and using a processor register as a stack 1. Opcode field - specifies the operation to be performed.
pointer. 2. Address field - specifies a memory address / processor register.
● The program counter (PC) points at the address of the 3. Mode field - specifies the way the operand or the effective address is determined.
next instruction in the program. ● The number of address fields depends on the internal organization of registers.
● PC is used during the fetch phase to read an instruction. ● Three types of CPU organizations:
● The address register (AR) points at an array of data.
1. Single accumulator organization.
● AR is used during the execute phase to read an Eg: ADD X
operand. 2. General register organization.
● The stack pointer SP points at the top of the stack. Eg: ADD R1, R2, R3 - MOV R1, R2
● P is used to push or pop items into or the stack. 3. Stack organization
● Advantage - CPU can refer to it without having to Eg: PUSH X
specify an address (instead use SP). ● Based on these, instructions are classified into four formats.
13 15
Three-Address Instruction
● Computers with three-address instruction formats can use each address field to specify either a
processor register or a memory operand.
● The program in assembly language that evaluates 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
● Advantage - It results in short programs when evaluating arithmetic expressions.
● Disadvantage - The binary-coded instructions require too many bits to specify three addresses.
● Eg: Commercial computer Cyber 170.
Instruction Formats
14 16
Two-Address Instruction Zero-Address Instruction
● Two-address instructions are the most common in commercial computers. ● Used in stack-organized computers.
● Here again each address field can specify either a processor register or a memory word. ● The program to evaluate X = (A + B) * (C + D) for a stack-organized computer
● The program to evaluate X = (A + B) * (C + D) PUSH A // TOS ← A
PUSH B // TOS ← B
MOV R1, A // R1 ← M[A]
ADD // TOS ← (A + B)
ADD R1, B // R1 ← R1 + M[B]
PUSH C // TOS ← C
MOV R2, C // R2 ← M[C]
PUSH D // TOS ← D
ADD R2, D // R2 ← R2 + M[D]
ADD // TOS ← (C + D)
MUL R1, R2 // R1 ← R1*R2
MUL // TOS ← (C + D)*(A + B)
MOV X, R1 // M[X] ← R1
POP X // M[X] ← TOS
● To evaluate arithmetic expressions in a stack computer, it is necessary to convert the expression
into reverse Polish notation.
17 19
One-Address Instruction
18 20
Addressing Mode 2. Immediate Mode
● The operation field of an instruction specifies the operation to be performed. ● The operand is specified in the instruction itself.
● This operation must be executed on some data stored in computer registers or memory words. ● I has an operand field rather than an address field.
● The way the operands are chosen during program execution is dependent on the addressing ● The operand field contains the actual operand to be used in conjunction with the operation
mode of the instruction. specified in the instruction.
● The addressing mode specifies a rule for interpreting or modifying the address field of the ● They are are useful for initializing registers to a constant value.
instruction before the operand is actually referenced. ● Eg: ADD 7
● Computers use addressing mode techniques for the purpose of accommodating one or both of
the following provisions:
1. To give programming versatility to the user by providing such facilities as pointers to
memory, counters for loop control, indexing of data, and program relocation.
2. To reduce the number of bits in the addressing field of the instruction
21 23
● The operands are specified implicitly in the definition of the instruction. ● The address field specifies a processor register.
● Eg: CMA - Complement Accumulator. ● In this mode the operands are in registers that reside within the CPU.
● All register reference instructions that use an accumulator are implied-mode instructions. ● The particular register is selected from a register field in the instruction.
● Zero-address instructions in a stack-organized computer are implied-mode instructions since ● A k-bit field can specify any one of 2k registers.
the operands are implied to be on top of the stack. ● Eg: ADD R1
22 24
4. Register Indirect Mode 6.Direct Address Mode
● The instruction specifies a register in the CPU whose contents give the address of the operand ● The effective address is equal to the address part of the instruction.
in memory. ● The operand resides in memory and its address is given directly by the address field of the
● The selected register contains the address of the operand rather than the operand itself. instruction.
● Before using a register indirect mode instruction, the programmer must ensure that the ● In a branch-type instruction the address field specifies the actual branch address.
memory address of the operand is placed in the processor register with a previous instruction.
● Advantage - The address field of the instruction uses fewer bits to select a register.
25 27
● Similar to the register indirect mode except that the register is incremented or decremented ● The address field of the instruction gives the address where the effective address is stored in
after (or before) its value is used to access memory. memory.
● When the address stored in the register refers to a table of data in memory, it is necessary to ● Control fetches the instruction from memory and uses its address part to access memory again
increment or decrement the register after every access to the table. to read the effective address.
● This can be achieved by using the increment or decrement instruction.
26 28
8. Relative Address Mode 10. Base Register Addressing Mode
● Content of the program counter is added to the address part of the instruction in order to ● In this mode the content of a base register is added to the address part of the instruction to
obtain the effective address. obtain the effective address.
● The address part of the instruction is usually a signed number (positive or negative). ● Similar to the indexed addressing mode except that the register is now called a base register.
● This number is added to the content of the program counter, producing an effective address ● The difference between the two modes is in the way they are used rather than in the way that
whose position in memory is relative to the address of the next instruction. they are computed.
● It is often used with branch-type instructions. ● A base register holds a base address and the address field of the instruction gives a
● Example: displacement relative to this base address.
Let PC contains the number 825. ● This mode is used to facilitate the relocation of programs in memory.
The address part of the instruction contains the number 24. ● When programs and data are moved from one segment of memory to another, as required in
The instruction at location 825 is read from memory during the fetch phase and the program multiprogramming systems, the address values of instructions must reflect this change of
counter is then incremented by one to 826. position.
The effective address computation for the relative address mode is 826 + 24 = 850. ● Here only the value of the base register requires updating to reflect the beginning of a new
memory segment.
29 31
● Content of an index register is added to the address part of the instruction to obtain the
effective address.
● The index register is a special CPU register that contains an index value.
● The address field of the instruction defines the beginning address of a data array in memory.
● The distance between the beginning address and the address of the operand is the index value
stored in the index register.
● Any operand in the array can be accessed with the same instruction if the index register
contains the correct index value.
● The index register can be incremented to facilitate access to consecutive operands.
Data Transfer and Manipulation
30 32
Data Transfer & Manipulation Data Manipulation Instructions
● Computers provide an extensive set of instructions to give the user the flexibility to carry out ● Perform operations on data and provide the computational capabilities for the computer.
various computational tasks. ● Divided into three basic types:
● The basic set of operations available in a typical computer can be classified into three 1. Arithmetic instructions.
categories: 2. Logical and bit manipulation instructions.
1. Data transfer instructions 3. Shift instructions.
2. Data manipulation instructions
3. Program control instructions
● Data transfer instructions cause transfer of data from one location to another without changing
the binary information content.
● Data manipulation instructions are those that perform arithmetic, logic, and shift operations.
● Program control instructions provide decision-making capabilities and change the path taken by
the program when executed in the computer.
33 35
● Data transfer instructions move data from one place in the computer to another without ● Increment (INC) : adds 1 to the value stored in a register or memory word.
changing the data content. ● Decrement (DEC) : subtracts 1 from a value stored in a register or memory word.
● The most common transfers are between memory and processor registers, between processor ● Add (ADD) : Addition.
registers and input or output, and between the processor registers themselves. ● Subtract (SUB) : Subtraction.
● Typical Instructions are, ● Multiply (MUL) : Multiplication.
1. Load (LD) - Transfer from memory to a processor register, usually an accumulator.
● Divide (DIV) : Division.
2. Store (ST) - Transfer from a processor register into memory.
● Add with carry (ADDC) : Performs the addition on two operands plus the value of the carry
3. Move (MOV) - Transfer from one register to another.
from the previous computation.
4. Exchange (XCH) - Swaps information between two registers or a register and a memory
word. ● Subtract with borrow (SUBB) : Subtracts two words and a borrow which may have resulted
5. Input (IN), Output (OUT) - Transfer data among processor registers and input or output from a previous subtract operation.
terminals. ● Negate (NEG) : Forms the 2’s complement of a number.
6. Push (PUSH), Pop(POP) - Transfer data between processor registers and a memory stack.
34 36
Logical and Bit Manipulation Instructions Logical Shift
37 39
● Shifts are operations in which the bits of a word are moved to the left or right. ● Arithmetic Shift Right - Preserve sign bit in the left most position. Sign bit shifted to right along
● The bit shifted in at the end of the word determines the type of shift used. with other numbers but sign bit remain unchanged.
● Types
1. Logical Shift. Arithmetic Shift Right (SHRA) Arithmetic Shift Left (SHLA)
2. Arithmetic Shift
3. Rotate Shift
38 40
Rotate Shift Program Control Instructions
● Bits are shifted out one end are not lost but circulated back into other end. ● Program control instructions specify conditions for altering the content of the program counter.
● Rotate Left Through Carry(ROLC), Rotate right through Carry (RORC) treats carry bit as an ● Provides decision making capabilities.
extension of register whose word is being rotated. ● Branch (BR) : BR ADR, branch the program to Address ADR. (PC←ADR)
● Jump (JMP)
Rotate Right (ROR) Rotate Left (ROL)
● Skip (SKP) : Skip instruction(PC←PC + 1) if some condition is met.
● Call (CALL) : Used with subroutines
● Return (RET)
● Compare (CMP) : Compare by subtraction.
● Test (by ANDing) TST : AND instruction without storing result.
41 43
42 44