Module 4 Instruction and Adressing
Module 4 Instruction and Adressing
Displacement addressing requires that the instruction have two address fields, at
least one of which is explicit.
The value contained in one address field (value = A) is used directly.
The other address field, or an implicit reference based on opcode, refers to a
register whose contents are added to A to produce the effective address.
Three of the most common use of displacement addressing are:
• Relative addressing
• Base-register addressing
• Indexing
1 Relative Addressing:
Because this is such a common operation, some system will automatically do this as part of the same
instruction cycle.
If certain registers are devoted exclusively to indexing, then auto-indexing can be invoked implicitly and
automatically. If general purpose register are used, the autoindex operation may need to be signaled by
a bit in the instruction.
First, the contents of the address field are used to access a memory location
containing an address.
This address is then indexed by the register value.
With preindexing, the indexing is performed before the indirection:
EA = ( A + (R) )
An address is calculated, the calculated address contains not the operand, but the
address of the operand.
Stack Addressing:
The machine instructions need not include a memory reference but implicitly
operate on the top of the stack.
The operation of a CPU is determine by the instruction it executes, referred to as
machine instructions or computer instructions.
The collection of different instructions is referred as the instruction set of the CPU.
Each instruction must contain the information required by the CPU for execution.
The elements of an instruction are as follows:
Operation Code:
Specifies the operation to be performed (e.g., add, move etc.). The operation is
specified by a binary code, know as the operation code or opcode.
Within the computer, each instruction is represented by a sequence of bits. The instruction is divided into fields,
corresponding to the constituent elements of the instruction. The instruction format is highly machine specific and it
mainly depends on the machine architecture. A simple example of an instruction format is shown in the figure. It is
assume that it is a 16-bit CPU. 4 bits are used to provide the operation code. So, we may have to 16 (24 = 16)
different set of instructions. With each instruction, there are two operands. To specify each operands, 6 bits are used.
It is possible to provide 64 ( 26 = 64 ) different operands for each operand reference.
It is difficult to deal with binary representation of machine instructions. Thus, it has become common practice to use a
symbolic representation of machine instru ctions.
Opcodes are represented by abbreviations, called mnemonics, that indicate the operations.
Common examples include:
ADD Add
SUB Subtract
MULT Multiply
DIV Division
LOAD Load data from memory to CPU
STORE Store data to memory from CPU.
A simple instruction format.
Operands are also represented symbolically. For example, the
instruction
MULT R, X : R R xX
may mean multiply the value contained in the data location X by
the contents of register R and put the result in register R
In this example, X refers to the address of a location in memory
and R refers to a particular register.
Thus, it is possible to write a machine language program in
symbolic form. Each symbolic opcode has a fixed
binary representation, and the programmer specifies the
location of each symbolic operand.
Instruction Types
One of the most interesting, and most analyzed, aspects of computer design is instruction set design.
The instruction set defines the functions performed by the CPU. The instruction set is the
programmer's means of controlling the CPU.
Thus programmer requirements must be considered in designing the instruction set.
Most important and fundamental design issues:
Operation repertoire : How many and which operations to provide, and how complex operations
should be.
Data Types : The various type of data upon which operations are performed.
Instruction format : Instruction length (in bits), number of addresses, size of various fields and so on.
Registers : Number of CPU registers that can be referenced by instructions and their
use.
Addressing : The mode or modes by which the address of an operand is specified.
Types of Operands
The number of different opcodes and their types varies widely from
machine to machine. However, some
general type of operations are found in most of the machine
architecture. Those operations can be categorized as
follows:
1 Data Transfer
2 Arithmatic
3 Logical
4 Conversion
5 Input Output [ I/O ]
6 System Control
7 Transfer Control
Data Transfer:
The most fundamental type of machine instruction is the data transfer instruction. The data
transfer instruction must specify several things.
First, the location of the source and destination operands must be specified.
Each location could be memory, a register, or the top of the stack. Second, the length of data
to be transferred must be indicated.
Third, as with all instructions with operands, the mode of addressing for each operand must
be specified.
The CPU has to perform several task to accomplish a data transfer operation. If both source
and destination are registers, then the CPU simply causes data to be transferred from one
register to another; this is an operation internal to the CPU.
If one or both operands are in memory, then the CPU must perform some or all of the
following actions:
a) Calculate the memory address, based on the addressing mode.
b) If the address refers to virtual memory, translate from virtual to actual memory address.
c) Determine whether the addressed item is in cache.
d) If not, issue a command to the memory module.
Commonly used data transfer operation page 183:
A branch instruction, also called a jump instruction, has one of its operands as the address of the next
instruction to be executed. Basically there are two types of branch instructions: Conditional Branch
instruction and unconditionla branch instruction. In case of unconditional branch instruction, the branch is
made by updating the program counter to address specified in operand. In case of conditional branch
instruction, the branch is made only if a certain condition is met. Otherwise, the next instruction in
sequence is executed.
There are two common ways of generating the condition to be tested in a conditional branch instruction
First most machines provide a 1-bit or multiple-bit condition code that is set as the result of some
operations. As an
example, an arithmetic operation could set a 2-bit condition code with one of the following four values:
zero, positive,
negative and overflow. On such a machine, there could be four different conditional branch instructions:
BRP X Branch to location X if result is positive
BRN X Branch to location X if result is negative
BRZ X Branch to location X is result is zero
BRO X Branch to location X if overflow occurs
In all of these cases, the result referred to is the result of the most recent operation that set the condition
code.
Another approach that can be used with three
address instruction format is to perform a
comparison and specify a branch in the same
instruction.
For example,
BRE R1, R2, X Branch to X if contents of R1 =
Contents of R2.
Skip Instruction
ISZ R1
This instruction will increment the value of the register R1. If the
result of the increment is zero, then it will skip the next instruction.
Procedure Call Instruction
A procedure is a self contained computer program that is incorporated into a large program. At any point in the
program the procedure may be invoked, or called.
The processor is instructed to go and execute the entire procedure and then return to the point from which the call
took place.
The procedure mechanism involves two basic instructions: a call instruction that branches from the present
location to the procedure, and a return instruction that returns from the procedure to the place from which it was
called. Both of these are forms of branching instructions.
Number of Operands:
Typical instructions on today's machines provide for two operands.
Each operand address in the instruction might require its own mode indicator, or the use of a mode indicator
could be limited to just one of the address field.
Register versus memory:
A machine must have registers so that data can be brought into the CPU for processing.
With a single user-visible register (usually called the accumulator), one operand address is
implicit and consumes no instruction bits.
Even with multiple registers, only a few bits are needed to specify the register. The more
that registers can be used for operand references, the fewer bits are needed.
Number of register sets:
A number of machines have one set of general purpose registers, with typically 8 or 16
registers in the set. These registers can be used to store data and can be used to store
addresses for displacement addressing.
The trend recently has been away from one bank of general purpose registers and toward a
collection of two or more specialized sets (such as data and displacement).
Address range:
For addresses that reference memory, the range of addresses that can be referenced is
related to the number of address bits.
With displacement addressing, the range is opened up to the length of the address register.
Address granularity:
In a system with 16- or 32-bit words, an address can reference a word or a byte
at the designer's choice. Byte addressing is convenient for character
manipulation but requires, for a fixed size memory, more address bits.
Variable-Length Instructions:
Instead of looking for fixed length instruction format, designer may choose to
provide a variety of instructions formats of different lengths. This tectic
makes it easy to provide a large repertoire of opcodes, with different opcode
lengths.
Addressing can be more flexible, with various combinations of register and
memory references plus addressing modes. With variable length instructions,
many variations can be provided efficiently and compactly.
The principal price to pay for variable length instructions is an increase in the
complexity of the CPU.
Number of addresses :
The processor architecture is described in terms of the number of addresses contained in each instruction. Most of
the arithmatic and logic instructions will require more operands.
All arithmatic and logic operations are either unary (one source operand, e.g. NOT) or binary (two source operands,
e.g. ADD).
Thus, we need a maximum of two addresses to reference source operands. The result of an operation must be
stored, suggesting a third reference.
Three address instruction formats are not common because they require a relatively long instruction format to hold
the three address reference.
With two address instructions, and for binary operations, one address must do double duty as both an operand and
a
result.
In one address instruction format, a second address must be implicit for a binary operation. For implicit reference, a
processor register is used and it is termed as accumulator(AC). the accumulator contains one of the operands and is
used to store the result.
Consider a simple arithmatic expression to evalute:
Y= (A + B) / (C * D)