Unit-2 CH-22
Unit-2 CH-22
Once the instruction is fetched, the operand is also fetched in the instruction. This reduces the
instruction cycle time. However, the value of the operand is limited because this mode is limited
to the size of the address field.
The index addressing mode includes an index register which holds an offset/displacement. The
effective address of the operand is obtained by adding the offset with the contents of the registers
present in the instruction.
The start address of an array in the memory is obtained from the address field in the instruction.
The difference between the start address and the operand address provides an index value for the
operand. The index value is stored in the index register. The operands are stored in consecutive
locations in the memory. Thus, by changing the value of the index or by incrementing the index
value, you can access any operand in the array.
Some CPUs possess auto-indexing feature, which automatically increments the index registers
when an instruction with index addressing is executed.
These addressing modes provide flexibility in writing efficient programs. Addressing modes help
in reducing the instruction length by including a separate field for the address. This helps the
programmers to handle complex tasks such as loop control, program relocations, and indexing of
an array.
Notes
Data transfer instructions transfer data from one location to another without causing any change
in the content present in the binary form. Data manipulation instructions perform arithmetic,
logic, and shift operations. Program control instructions provide decision making abilities and
are able to change the execution sequence. The program control instructions are explained in the
next section.
Notes
Data Manipulation Instructions
Data manipulation instructions have computational capabilities. They perform arithmetic, logic,
and shift operations on data. There are three basic types of data manipulation instructions:
1. Arithmetic Instructions
2. Logical and Bit Manipulation Instructions
3. Shift Instructions
During execution of the instruction, each instruction goes through the fetch phase, where it reads
the binary code of the instruction from the memory. According to the rules of the instruction
addressing mode, the operands are brought in processor registers. Finally, the instruction in the
processor is executed.
Arithmetic Instructions
Arithmetic operations include addition, subtraction, multiplication and division. Some computers
provide instructions only for addition and subtraction operations, and generate multiplication
and division operations from these two operations. Each instruction is represented by a mnemonic
symbol. Table 8.2 illustrates some of the arithmetic instructions and their respective mnemonic
symbols.
Example: For the conditions generated as a carry or borrow, the outcome is either 0 or
negative.
A flip-flop is used to store the carry from an addition operation. The add with carry instruction
performs the addition of two numbers along with the value of carry from the previous computation.
Similarly, the subtract with borrow instruction performs the subtraction of two numbers and a
borrow if any, from the previous computation. The negation instruction represents the 2’s
complement of a number.
Logical instructions carry out binary operations on the bits stored in the registers. In logical
operations, each bit of the operand is treated as a Boolean variable. Logical instructions can change
bit value, clear a group of bits, or can even insert new bit value into operands that are stored in
registers or memory words. Each logical instruction is represented by mnemonic symbols.
Notes Boolean variable is a numerical variable that can hold a single binary bit (0 or 1).
Table 8.3 illustrates some of the logical instructions andtheir respective mnemonic symbols.
Name Mnemonic
Clear CLR
Complement COM
AND AND
OR OR
Exclusive-OR XOR
Clear carry CLRC
Set carry SETC
Complement COMC
carry
Enable inter rupt EI
Disable interrupt DI
The clear instruction replaces the specific operand by 0’s. The complement instruction inverts all
the bits of the operand and produces 1’s complement. The AND, OR, and XOR instructions perform
logical operations on each bit or group of bits of the operand.
Logical instructions can also manipulate individual bits or group of bits. The bit manipulation
operation can clear a bit to 0, can set a bit to 1, or can complement a bit.
The AND instruction can clear a bit or group of bits of an operand. For Boolean variable a, the
relationship ‘ab0 = 0’ and ‘ab1 = a’ indicates that the binary variable when ANDed with 0 changes
the value to 0. However, the variable when ANDed with 1 does not change the value. Thus, bits
of an operand can be cleared by ANDing the operand with another operand that has to clear all 0
bits in its position. It is also known as mask because it masks 0s in selected bit positions of an
operand.
The OR instruction can set a bit or group of bits of an operand. For Boolean variable a, the
relationship ‘a + 1 =1’ and ‘a + 0 = a’ indicates that the binary variable when ORed with 1, changes
the value to 1. However, the variable when ORed with 0 does not change the value. Thus, OR
instruction is used to set the bits to 1 by ORing the bits of an operand with another operand that
has 1s in its bit positions.
The XOR instruction can complement bits of an operand. For Boolean variable a, the relationship
‘a + 1 = a’ and ‘a + 0 = a’ indicates that the binary variable is complemented when XORed with 1.
However, the variable does not change value when XORed with 0.
The carry bits can be cleared, set, or complemented with appropriate instructions. The bit
manipulation instructions can also enable or disable the interrupt facility, which is controlled by
the flip-flops.
Shift Instructions
Shift instruction helps to shift the bits of an operand to the right or to the left. The direction of
shift is based on specific instructions. The operand is first loaded into the accumulator and then
the shift operation is performed bit by bit.
Notes The shift-left operation shifts the zero into low-order vacated position.
Name Mnemonic
Branch BR
Jum p JMP
Skip SKP
Call CALL
Return RET
Compare (by CMP
subtraction)
Test (by ANDing) TST
Notes Branch and jump instructions can be conditional or unconditional. The unconditional branch
instruction creates a branch to the specified address without any conditions.
The JMP instruction transfers the flow of execution, without considering the
actual condition of the flags, to the indicated operator. The above instruction
makes the control jump to the part of the code where Displaydiagram is
specified.
The conditional branch instructions such as ‘branch if positive’, or ‘branch if zero’ specify the
condition to transfer the flow of execution. When the condition is met, the branch address is loaded
in the program counter.
Figure 8.7 depicts the conditional branch instructions.
The compare instruction performs an arithmetic subtraction. Here, the result of the operation is
not saved; instead, the status bit conditions are set. The test instruction performs the logical AND
operation on two operands and updates the status bits.
The status register comprises the status bits. The bits of the status register are modified according
to the operations performed in the ALU. Figure 8.8 depicts a block diagram of an 8-bit ALU with
a 4-bit status register.
In figure 8.8, if the end carry C 8 is 1, then carry (C) is set to 1. If C 8 is 0, then C is cleared to 0.
If the highest order bit F7 is 1, then Sign (S) is set to 1. If F7 is 0, then S is set to 0.
If the output of ALU is 0, then zero (Z) is set to 1, otherwise Z is set to 0.
If XOR of the last two carries is equal to 1, then overflow (V) is set to 1, otherwise V is cleared to
0.
The result of the 8-bit ALU operation is either 127 or -127.
Z is a status bit used to indicate the result obtained after comparing A and B. Here, XOR operation
is used to compare two numbers (Z = 0 if A = B).
Thus, when the status condition is true, the program control is transferred to the address specified
in the instruction, otherwise the control continues with the instructions that are in the subsequent
locations. The conditional instructions are also associated with the program control instructions
such as jump, call, or return.
The zero status bit checks if the result of the ALU is zero or not. The carry bit checks if the most
significant bit position of the ALU has a carry out. It is also used with rotate instruction to check
whether or not the bit is shifted from the end position of a register into a carry position. The sign
bit indicates the state of the most significant bit of the output from the ALU (S = 0 denotes positive
sign and S = 1 denotes negative sign). The branch if plus and branch if minus are used to check
whether the value of the most significant bit represents a sign or not. The overflow and underflow
instructions are used in conjunction with arithmetic operations performed on signed numbers.
The higher and lower words are used to denote the relations between unsigned numbers, whereas
the greater and lesser words are used to denote the relations between signed numbers.
Notes
Example: Consider two numbers M = 11110000 and N = 00010100. When we perform
M - N operation, the result obtained is
M: 11110000
N: 00010100
M-N: 11011100
The compare instruction updates the status bits:
C =1: Carry out of the last stage
S = 1: Left most bit is 1
Z = 0: Last two carries are equal to 1
V = 0: Result is not equal to 0
Consider the numeric value, where M = 60 and B =10 (unsigned numbers).
Here, M > N and M N. Therefore, the instructions that will cause branch
are BHI, BHE and BNE.
If M = -8 and N = 10, then we have M < N and M N. Therefore, the
instructions that will cause branch are BLT, BLE, and BNE
Example: An ADD instruction will use index addressing to specify one operand in memory
and direct addressing to specify second operand in memory. This instruction would use another
memory location to store the result. Thus, this instruction would use three memory references for
execution.
Many CISC architectures read the inputs and write their outputs in the memory system instead of
a register file. As CISC architecture takes large number of addressing modes, more hardware
logic is required to implement them. This reduces the computation speed.
Basically, the CISC architecture attempts to provide a single machine instruction for the statements
that are written in a high-level language.
Notes
Example: The IBM 370 computer uses the CISC architecture.
Example: Consider an example program for a RISC-type CPU, which include load and store
instructions that have one memory and one register address, and arithmetic instructions that are
specified by processor registers. The below program evaluates X = (P + Q)*(R + S)
LOAD R1 P R1 M[P]
LOAD R2 Q R2 M[Q]
LOAD R3 R R3 M[R]
LOAD R4 S R4 M[S]
ADD R1, R1, R2 R1 R1 + R2
ADD R3, R3, R4 R3 R3 + R4
MUL R1, R1, R3 R1 R1 + R3
STORE X, R1 M[X] R1
The LOAD instructions transfer the operand P, Q, R and S from memory to CPU
registers R1, R2, R3, and R4 respectively. The ADD and MUL instructions execute
the addition and multiplication operations with the data in the registers without
referring to the memory. The STORE instruction stores the result of the
computation in the memory (M[X]).
There are some significant differences between RISC and CISC processors. The comparison between
the common characteristics of RISC and CISC processor is shown in table 8.6:
RISC CISC
Few instructions Many instructions
Few addr essing modes. Most Many addressing modes
instructions have register to
register addressing modes
Includes simple instructions and Includes complex instr uctions and
takes one cycle takes multiple cycles
Some of the instructions refer to Most of the instr uctions r efer to
memory memory
Hardwar e executes the Microprogram executes the
instructions instr uctions
Fixed format instructions Var iable forma t instructions
Easier to decode as instructions Difficult to decode as instructions
have fixed for mat have variable format
Multiple register sets are used Single r egister set is used
RISC is highly pipelined CISC is not pipelined or less
pipelined
Load and store functions are Load and stor e functions are found
separate instr uctions in a single instr uction
Today, RISC and CISC architectures are becoming more alike. Many RISC chips now support
instructions of CISC chips also. Similarly, CISC chips are using many techniques associated with
RISC chips.
8.5 Summary
• Addressing modes provide different methods for specifying operand address in the instruction.
• Some of the commonly used addressing modes are direct addressing mode, indirect addressing
mode, register addressing mode, immediate addressing mode, and index addressing mode.
• Data transfer instructions help to move the data from one location to another. Data manipulation
instructions perform arithmetic, logic, and shift operations on data.
• Program control instructions specify the conditions for data processing operations.
• The Complex Instruction Set Computer (CISC) consists of many complex instruction sets.
• The Reduced Instruction Set Computer (RISC) consists of less instruction sets and executes the
instructions at a greater speed.
8.6 Keywords
Accumulator: A processor register that stores intermediate arithmetic and logic results.
Flip-flops: An electronic circuit that is interconnected to form logic gates. It changes its state when
it receives the input pulse (trigger). Hence, it is also known as bistable gate.
Microprogram: A computer program that has basic elemental commands which control the
operation of each components of a microprocessor.
Pipelining: In pipelining, while the processor is performing arithmetic operations, the computer
architecture allows the next instructions to be fetched, holding them in a buffer close to the
processor until each instruction operation can be performed.