0% found this document useful (0 votes)
13 views47 pages

Comp Arch-B-1

Chapter 2 discusses machine instructions and addressing modes, detailing the characteristics of instruction sets and the elements of a machine instruction, including op-codes and operand references. It categorizes instruction types such as data processing, storage, movement, and program flow control, while explaining various addressing modes like immediate, direct, indirect, and register addressing. The chapter also covers instruction formats, trade-offs in instruction length, and the allocation of bits in instruction formats to balance opcode variety and addressing capability.

Uploaded by

gebrusiye9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views47 pages

Comp Arch-B-1

Chapter 2 discusses machine instructions and addressing modes, detailing the characteristics of instruction sets and the elements of a machine instruction, including op-codes and operand references. It categorizes instruction types such as data processing, storage, movement, and program flow control, while explaining various addressing modes like immediate, direct, indirect, and register addressing. The chapter also covers instruction formats, trade-offs in instruction length, and the allocation of bits in instruction formats to balance opcode variety and addressing capability.

Uploaded by

gebrusiye9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Chapter 2

Machine Instructions
and Addressing Modes
Machine instruction
characteristics
• Instruction Sets: The complete collection of
machine or computer instructions that are
executed (understood) by a CPU.
– Determines the operation of the CPU.
– Usually represented by assembly codes
Elements Of a Machine Instruction
• Information of each instruction required by the CPU
for execution, and are specified by binary code:
 Operation Code (Op-code): specifies the operation to
be performed. Ex. ADD, IN, MOV
 Source Operand Reference: one or more source
operands. i.e. inputs for the operation.
 Result Operand Reference: the result of the
operation.
 Next Instruction Reference: tells the CPU where to
fetch the next instruction after the execution of this
instruction is complete.
• The source and result operands can be in one
of the three areas.
– Main or virtual memory: address must be
supplied.
– CPU register: the instruction must contain
the number of the desired register.
– I/O device: the I/O module and device must
be specified.
Instruction Representation
• Represented by a sequence of bits, and is
divided in to fields corresponding to the
elements.
• Example of a simple instruction format
• During instruction execution,
– instruction is read in to an Instruction
Register (IR).
– CPU extracts the data from various fields of
the instruction.
• Since it is difficult to deal with binary
representation of instructions, it is a common
practice to use a symbolic representation.
Instruction type Op-code Symbolic description
representation
Arithmetic 00000101 ADD M(X) Add M(X) AC; put the result in
AC
00000110 SUB M(X) Subtract M(X) from AC; put the
result in AC

• Op-Codes are represented by abbreviations


(mnemonics), and Operands are represented
symbolically.
• The operation is performed on the contents of
a location, not on its address.
Ex. ADD R, Y
Instruction Types
• Machine Instructions:
 Defines many of the functions performed by the
processor (has an effect on the implementation of
processor)
 Programmer’s means of controlling the processor.
 Must allow the user to formulate any data processing
task.
 Must be sufficient to express any of the instructions
from high level languages.
• Can be categorized as follows:
Data Processing: arithmetic and logic
instructions.
Data Storage: memory instructions
Data Movement: I/O instructions
Program Flow Control: test and branch
instructions
• Arithmetic Instruction: provide computational
capabilities for processing numerical data.
• Logic (Boolean) Instructions: operate on the bits
of a word. They provide capabilities for
processing any other type of data.
They are performed on data in CPU registers.
• Memory Instructions: used for moving data
between memory and the registers.
• I/O Instructions: are needed to transfer
programs and data in to memory and the results
of computation back out to the user.
• Test Instructions: used to test the value of a
data word or the status of a computation.
• Branch Instructions: used to branch to a
different set of instructions depending on the
decision made.
Number Of Addresses
• Helps to describe processor architecture.
• Is the maximum number of addresses needed in
an instruction.
• Example consider the Arithmetic & logic
instruction:
– Maximum of two addresses to reference
operands.
– A third address to reference the result.
– Finally fourth address to reference the next
instruction
• Most CPUs are of the one-, two-, or three-
address variety, with the address of the next
instruction being implicit (obtained from the
PC)
• Types of operands: data types on which
machine instructions operate. Categories are
– Addresses
– Numbers
– Characters
– Logic data
• Addresses: unsigned integers
some calculations are done on the operand reference
in an instruction to determine actual address.
• Numbers:
– Integers or fixed point
– Floating point
– Decimal
• Characters: a common form of data.
• ASCII code is the most commonly used character
code. Each character in this code is represented by a
unique 7-bit pattern. Another code is EBCDIC
• Logical Data: when data are treated as a single n-bit
unit of data consisting of n 1 bit items of data.
Types of operations
Op-Codes vary widely from machine to machine.
The same general purpose types of operations
found on all machines are:
• Data transfer: most fundamental type, and
specifies: the location of source and destination
operands, length of data to be transferred, mode
of addressing.
Ex. MOV EXCHANGE
STORE PUSH
LOAD POP
• Arithmetic:
– basic arithmetic operations are ADD, MUL, SUB
– Single operand instructions are Absolute,
Negate, Increment
– Data transfer operations may be involved
• Logical:
– Operations for manipulating individual bits (bit
wise operations) of a word
– Based upon Boolean operations
– Ex. AND, OR, shift, rotate
• Conversion:
Operations that change the format or operate on
the format of data. Ex. Translate, convert
• example is converting from decimal to binary
• Input Output:
A means of exchanging data (like control, status, and
data signals) between the external environment and
the computer.
May be:
• Specific instructions
• May be done using data movement instructions
(memory mapped)
• May be done by a separate controller (DMA)
– Ex. IN, OUT
• System Control:
– Reserved for the use of the operating system.
– May read or alter control register
– May read or modify a storage protection key
• Transfer Of Control:
– Change the sequence of instruction execution
– Most importance :
If a group of instructions is executed repeatedly
Ex. Loop
During decision making Ex. Jump conditional,
branch
To break down a large programs.
Addressing Mode
• A technique used to determine the address of the
operands.
different op-codes use different addressing modes
one or more bits in the instruction format can be
used as a mode field.
• The most common are:
Immediate Register Indirect
Direct Displacement (Indexed)
Indirect Stack
Register
Immediate Addressing
• Operand is part of instruction
• Operand = address field
• Ex. ADD 5
– Add 5 to contents of accumulator
– 5 is operand
• No memory reference to fetch data; Fast
• Limited range: the size of number is restricted to the
size of address field
Instruction

Opcode Operand
Direct Addressing
• Address field contains address of operand
• Effective address (EA) = address field (A)
• Ex. ADD A
– Add contents of cell A to accumulator
– Look in memory at address A for operand
• Single memory reference to access data
• No additional calculations to work out effective
address
• Limited address space
Direct Addressing Diagram
Instruction

Opcode Address A
Memory

Operand
Indirect Addressing
• Memory cell pointed to by address field contains
the address of (pointer to) the operand
• EA = (A)
• Ex. ADD (A) ;Add contents of cell pointed to by
contents of A to accumulator
• Large address space; 2n where n = word length
• Multiple memory accesses to find operand
• Hence slower
Indirect Addressing Diagram
Instruction

Opcode Address A
Memory

Pointer to operand

Operand
Register Addressing
• Operand is held in register named in address
filed; EA = R
• Limited number of registers
• Very small address field needed
– Shorter instructions
– Faster instruction fetch
• No memory access
• Very fast execution
• Very limited address space
Register Addressing Diagram
Instruction

Opcode Register Address R


Registers

Operand
Register Indirect Addressing
• Similar to indirect addressing
• Operand is in memory cell pointed to by
contents of register R; EA = (R)
• Large address space (2n)
• One fewer memory access than indirect
addressing
Register Indirect Addressing Diagram

Instruction

Opcode Register Address R


Memory

Registers

Pointer to Operand Operand


Displacement Addressing
• Combines the direct addressing and register
indirect addressing
• EA = A + (R)
• Address field hold two values
– A = base value
– R = register that holds displacement
– or vice versa
• Includes: Relative, Base-register, and Indexing
Displacement Addressing Diagram
Instruction

Opcode Register R Address A


Memory

Registers

Pointer to Operand + Operand


Relative Addressing
• A version of displacement addressing also
called PC-relative addressing
• R = Program counter, PC
• EA = A + (PC)
• i.e. get operand from a cell displaced by A
from current location pointed to by PC.
• It saves address bits in the instruction.
Base-Register Addressing
• R holds pointer to base address (main memory
reference)
• A holds displacement (usually an unsigned
integer representation) from that address.
• R may be explicit or implicit
• Ex. segment registers in 80x86
Indexed Addressing
• The address field references a main memory
address, and the referenced register contains a
positive displacement from that address.
• It is just the opposite for base-register addressing.
• A = base; R = displacement; EA = A + R
• Good for accessing arrays by incrementing or
decrementing the index register after each
reference to it (auto-indexing.)
– EA = A + R;
– R++
• If indexing is performed after the indirection, it
is termed postindexing:
EA = (A) + (R)
• With preindexing, the indexing is performed
before the indirection:
EA = (A+(R))

• (Draw the diagrams)


Stack Addressing
• Stack is a linear array of reserved block
locations.
• It is sometimes referred to as a pushdown list
or last-in-first-out queue.
• Operand is (implicitly) on top of stack
• E.x. Pop, Push
• In fact it is Register Indirect Addressing Mode
since the Stack Pointer is maintained in a
register.
INSTRUCTION FORMATS
• Defines the layout of the bits of an instruction, in
terms of its constituent fields.
• Must include an op_code and, implicitly or explicitly,
zero or more operands.
• Each explicit operand is referenced using one of the
addressing modes described for each operand.
• Instruction Format Length
• Affects, and is affected by, memory size, memory
organization, bus structure, processor complexity, and
processor speed.
• Determines the richness and flexibility of the machine
as seen by the assembly-language programmer.
• Trade-off here is between the desire for a powerful
instruction range or longer instruction length (more:
opcodes, operands, addressing modes, and greater
address range) and a need to save space.
• But longer instruction length may be wasteful. A 64-
bit instruction occupies twice the space of a 32-bit
instruction but is probably less than twice as useful.
• Other considerations Beyond this basic trade-off:
 Either the instruction length should be equal to the
memory-transfer length (in a bus system, data-bus
length) or one should be a multiple of the other.
The memory transfer rate has not kept up with
increases in processor speed. Accordingly,
memory can become a bottleneck if the
processor can execute instructions faster than it
can fetch them.
One solution to this problem is to use cache
memory; another is to use shorter instructions.
Additional important feature is that the
instruction length should be a multiple of the
character length (usually 8 bits) and of the length
of fixed-point numbers.
• The word length of memory is, in some sense, the
“natural” unit of organization.
• The size of a word usually determines the size of
fixed-point numbers (usually the two are equal).
• Word size is also typically equal to, or at least
integrally related to, the memory transfer size.
• Because a common form of data is character
data, we would like a word to store an integral
number of characters.
• Otherwise, there are wasted bits in each word
when storing multiple characters, or a character
will have to straddle a word boundary.
• Allocation of Bits
• An issue of how to allocate the bits in the instruction
format.
• There is clearly a trade-off between the number of
opcodes and the power of the addressing capability.
• One refinement to this trade-off is the use of
variable-length opcodes.
• In this approach, there is a minimum opcode length
but, for some opcodes, additional operations may be
specified by using additional bits in the instruction.
• For a fixed-length instruction, this leaves fewer bits
for addressing. Thus, is used for those instructions
that require fewer operands and/or less powerful
addressing.
• The following interrelated factors go into
determining the use of the addressing bits.
 Number of addressing modes:
 Number of operands:
 Register versus memory:
 Number of register sets:
 Address range:
 Address granularity:

You might also like