unit 2
unit 2
UNIT 2
Operation code: Specifies the operation to be performed (e.g., ADD, I/O).The operation is
specified by a binary code, known as the operation code,or opcode.
Source operand reference: The operation may involve one or more source operands, that is,
operands that are inputs for the operation.
Result operand reference: The operation may produce a result.
Next instruction reference: This tells the processor where to fetch the next instruction after the
execution of this instruction is complete.
TYPES OF OPERANDS
Machine instructions operate on data. The most important general categories of data are
• Addresses
• Numbers
• Characters
• Logical data
ADDRESSES
In many cases, some calculation must be performed on the operand reference in an instruction to
determine the main or virtual memory address. In this context, addresses can be considered to be
unsigned integers.
NUMBERS
All machine languages include numeric data types. Three types of numerical data are there in
computers.
CHARACTERS
A common form of data is text or character strings. American Standard Code for Information
Interchange (ASCII) representation is used. Each character in this code is represented by a
unique 7-bit pattern; thus, 128 different characters can be represented.
LOGICAL DATA
Normally, each word or other addressable unit (byte, halfword, and so on) is treated as a single
unit of data. It is sometimes useful, however, to consider an n-bit unit as consisting of n 1-bit
items of data, each item having the value 0 or 1.When data are viewed this way, they are
considered to be logical data.
TYPES OF OPERATIONS
• Data transfer
• Arithmetic
• Logical
• Conversion
• Input/Output
• System control
• Transfer of control
ADDRESSING MODES
1. Immediate Mode
2. Direct Mode
3. Indirect Mode
4. Indexed Mode
5. Relative Mode
6. Auto Increment Mode
7. Auto Decrement Mode
Immediate Mode:
According to this addressing mode, the value of the operand is (immediately) available in the
instruction itself.
Consider, for example, the case of loading the decimal value 1000 into a register Ri. This
operation can be performed using an instruction such as the following:
Indirect Mode:
In the indirect mode, what is included in the instruction is not the address of the operand, but
rather a name of a register or a memory location that holds the (effective) address of the operand.
In order to indicate the use of indirection in the instruction, it is customary to include the name of
the register or the memory location in parentheses.
Indexed Mode:
In this addressing mode, the address of the operand is obtained by adding a constant to the
content of a register, called the index register.
Relative Mode:
Relative addressing is the same as indexed addressing except that the program counter (PC)
replaces the index register.
LOAD X(PC),Ri
loads register Ri with the contents of the memory location whose address is the sum of the
contents of the program counter (PC) and the value X.
In this mode, the content of the autoincrement register is automatically incremented after
accessing the operand.
This instruction decrements the content of the register Rauto and then uses the new content as the
effective address of the operand that is to be loaded into register Ri.
INSTRUCTION TYPES
Based on number of operands:
ASSEMBLY LANGUAGE
Machine language is the native language of a given processor. Since assembly language is the
symbolic form of machine language, each different type of processor has its own unique
assembly language.
N=I+J+K
Suppose we wished to program this statement in machine language and to initialize I, J, and K to
2, 3, and 4, respectively.. The program starts in location 101 (hexadecimal). Memory is reserved
for the four variables starting at location 201.The program consists of four instructions:
1. Load the contents of location 201 into the AC.
2. Add the contents of location 202 to the AC.
3. Add the contents of location 203 to the AC.
CSE Department AITAM, Tekkali
7
G. VIJAY KUMAR, Asst.Prof COMPUTER ARCHITECTURE AND
ORGANIZATION
PROCESSOR ORGANIZATION
Fetch instruction: The processor reads an instruction from memory (register, cache, main
memory).
Decode instruction: The instruction is decoded to determine what action is required.
Process data: The execution of an instruction may require performing some arithmetic or logical
operation on data.
Write data: The results of an execution may require writing data to memory or an I/O module.
REGISTER ORGANIZATION
The registers in the processor perform two roles:
Control and status registers: Used by the control unit to control the operation of the processor
and by privileged, operating system programs to control the execution of programs.
User-Visible Registers
A user-visible register is one that may be referenced by means of the machine language that the
processor executes. We can characterize these in the following categories:
• General purpose
• Data
• Address
• Condition codes
Data registers may be used only to hold data and cannot be employed in the calculation of an
operand address.
Address registers may themselves be somewhat general purpose, or they may be devoted to a
particular addressing mode.
CSE Department AITAM, Tekkali
9
G. VIJAY KUMAR, Asst.Prof COMPUTER ARCHITECTURE AND
ORGANIZATION
Condition codes (also referred to as flags). Condition codes are bits set by the processor
hardware as the result of operations.
Sign: Contains the sign bit of the result of the last arithmetic operation.
Zero: Set when the result is 0.
Carry: Set if an operation resulted in a carry (addition) into or borrow (subtraction) out of a
high-order bit. Used for multiword arithmetic operations.
Equal: Set if a logical compare result is equality.
Overflow: Used to indicate arithmetic overflow.
Interrupt Enable/Disable: Used to enable or disable interrupts.
Supervisor: Indicates whether the processor is executing in supervisor or user mode. Certain
privileged instructions can be executed only in supervisor mode, and certain areas of memory
can be accessed only in supervisor mode.
INSTRUCTION CYCLE:
Instruction cycle
INSTRUCTION PIPELINE
Pipelining is the use of the processor to work on different phases of multiple instructions in
parallel
Fetch instruction (FI): Read the next expected instruction into a buffer.
Decode instruction (DI): Determine the opcode and the operand specifiers.
Calculate operands (CO): Calculate the effective address of each source operand. This may
involve displacement, register indirect, indirect, or other forms of address calculation.
Fetch operands (FO): Fetch each operand from memory. Operands in registers need not be
fetched.
Execute instruction (EI): Perform the indicated operation and store the result, if any, in the
specified destination operand location.
Write operand (WO): Store the result in memory.
Pipeline Performance:
The cycle time of an instruction pipeline is the time needed to advance a set of instructions one
stage through the pipeline.
Total time required for a pipeline with k stages to execute n instructions and t is the time delay.
The speedup factor for the instruction pipeline compared to execution without the pipeline is
defined as
Pipeline Hazards:
A pipeline hazard occurs when the pipeline, or some portion of the pipeline, must stall because
conditions do not permit continued execution.
There are three types of hazards: resource (structural), data, and control.
Resource Hazard:
A resource hazard occurs when two (or more) instructions that are already in the pipeline need
the same resource. The result is that the instructions must be executed in serial rather than
parallel for a portion of the pipeline. A resource hazard is sometime referred to as a structural
hazard.
Data Hazard:
A data hazard occurs when there is a conflict in the access of an operand location.
Control Hazard:
A control hazard, also known as a branch hazard, occurs when the pipeline makes the wrong
decision on a branch prediction and therefore brings instructions into the pipeline that must
subsequently be discarded