COA Lecture4
COA Lecture4
LEVEL: 1.2
LECTURER: H. MUSABAYEKA
Machine instructions and
characteristics
• The operation of the processor is determined by the instructions it
executes, referred to as machine instructions or computer
instructions.
• The collection of different instructions that the processor can execute
is referred to as the processor’s instruction set.
Elements of a Machine Instruction
• 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.
Instruction Representation
• During instruction execution, an instruction is read into an instruction
register (IR) in the processor. The processor must be able to extract the
data from the various instruction fields to perform the required
operation.
• It is difficult for both the programmer and the reader of textbooks to
deal with binary representations of machine instructions. Thus, it has
become common practice to use a symbolic representation of machine
instructions.
• An example of this was used for the IAS instruction set.
• Opcodes are represented by abbreviations, called mnemonics, that
indicate the operation.
IAS machine examples
ADD Add
SUB Subtract
MUL Multiply
DIV Divide
LOAD Load data from memory
STOR Store data to memory
• Operands are also represented symbolically.
• For example, the instruction ADD R, Y may mean add the value
contained in data location Y to the contents of register R.
• In this example, Y refers to the address of a location in memory, and R
refers to a particular register.
• Note that the operation is performed on the contents of a location,
not on its address
Instruction Types
• Consider a high-level language instruction that could be expressed in a language
such as BASIC or FORTRAN.
For example, X = X + Y
• This statement instructs the computer to add the value stored in Y to the value
stored in X and put the result in X.
• How might this be accomplished with machine instructions?
Let us assume that the variables X and Y correspond to locations 513 and 514.
• If we assume a simple set of machine instructions, this operation could be
accomplished with three instructions:
1. Load a register with the contents of memory location 513.
2. Add the contents of memory location 514 to the register.
3. Store the contents of the register in memory location 513.
• Any program written in a high-level language must be translated into
machine language to be executed.
• We can categorize instruction types as follows:
Data processing: Arithmetic and logic instructions.
Data storage: Movement of data into or out of register and or memory
locations.
Data movement: I/O instructions.
Control: Test and branch instructions.
Addressing Modes
• Immediate
• Direct
• Indirect
• Register
• Register indirect
• Stack
• We use the following notation:
A = contents of an address field in the instruction
R = contents of an address field in the instruction that refers to a register
EA = actual (effective) address of the location containing the referenced
operand
(X) = contents of memory location X or register X
• Virtually all computer architectures provide more than one of these addressing modes.
• So how can the processor determine which address mode is being used in a particular
instruction?
• Several approaches are taken. Often, different opcodes will use different addressing
modes. Also, one or more bits in the instruction format can be used as a mode field.
The value of the mode field determines which addressing mode is to be used.
• The second comment concerns the interpretation of the effective address (EA). In a
system without virtual memory, the effective address will be either a main memory
address or a register. In a virtual memory system, the effective address is a virtual
address or a register. The actual mapping to a physical address is a function of the
memory management unit (MMU) and is invisible to the programmer.
Immediate Addressing
Operand = A
• This mode can be used to define and use constants or set initial
values of variables.
• The advantage of immediate addressing is that no memory reference
other than the instruction fetch is required to obtain the operand,
thus saving one memory or cache cycle in the instruction cycle. The
disadvantage is that the size of the number is restricted to the size of
the address field, which, in most instruction sets, is small compared
with the word length.
Direct Addressing
• A very simple form of addressing is direct addressing, in which the
address field contains the effective address of the operand:
EA = A
• The technique was common in earlier generations of computers but is
not common on contemporary architectures. It requires only one
memory reference and no special calculation. The obvious limitation
is that it provides only a limited address space.