Instruction Codes: Computer Organisation and Architecture
Instruction Codes: Computer Organisation and Architecture
CODES
Computer Organisation and Architecture
INTRODUCTION
An instruction code is a group of bits that instruct the computer to perform a
specific operation.
The operation code of an instruction is a group of bits that define operations
such as addition, subtraction, shift, complement, etc.
◦ An instruction must also include one or more operands, which indicate the
registers and/or memory addresses from which data is taken or to which data
is deposited.
◦ The instructions are stored in computer memory in the same manner that
data is stored.
◦ The control unit interprets these instructions and uses the operations code to
determine the sequences of micro operations that must be performed to
execute the instruction.
COMPUTER INSTRUCTIONS
An instruction comprises of groups called fields. These fields include:
The Operation code (Opcode) field which specifies the operation to be performed.
The Address field which contains the location of the operand, i.e., register or
memory location.
◦ The Mode field which specifies how the operand will be located.
Stored Program Organization
◦ The operands are specified by indicating the
registers and/or memory locations in which
they are stored.– k bits can be used to
specify which of 2k registers (or memory
locations) are to be used.
◦ The simplest design is to have one processor
register (called the accumulator) and two
fields in the instruction, one for the opcode
and one for the operand.
◦ Any operation that does not need a memory
operand frees the other bits to be used for
other purposes, such as specifying different
operations.
STRUCTURE
The instruction code is also known as an instruction set. It is a collection of binary codes. It represents
the operations that a computer processor can perform. The structure of an instruction code can vary. It
depends on the architecture of the processor but generally consists of the following parts:
Opcode: The opcode (Operation code) represents the operation that the processor must perform. It
might indicate that the instruction is an arithmetic operation such as addition, subtraction, multiplication,
or division.
Operand(s): The operand(s) represents the data that the operation must be performed on. This data can
take various forms, depending on the processor’s architecture. It might be a register containing a value,
a memory address pointing to a location in memory where the data is stored, or a constant value
embedded within the instruction itself.
Addressing mode: The addressing mode represents how the operand(s) can be interpreted. It might
indicate that the operand is a direct address in memory, an indirect address (i.e. A memory address
stored in a register), or an immediate value (i.e. A constant embedded within the instruction).
◦ Prefixes or modifiers: Some instruction sets may include additional prefixes or modifiers that modify
the behavior of the instruction. For example, they may specify that the operation should be performed
only if a specific condition is met or that the instruction should be executed repeatedly until a specific
condition is met.
TYPES OF INSTRUCTION CODE
There are various types of instruction codes. They are classified based on the number of operands, the
type of operation performed, and the addressing modes used. The following are some common types of
instruction codes:
One-operand instructions: These instructions have one operand and operate on that operand. For
example, the “neg” instruction in the x86 assembly language negates the value of a single operand.
Two-operand instructions: These instructions have two operands and perform an operation involving
both. For example, the “add” instruction in x86 assembly language adds two operands together.
Three-operand instructions: These instructions have three operands and perform an operation that
involves all three operands. For example, the “fma” (fused multiply-add) instruction in some processors
multiplies two operands together, adds a third operand, and stores the result in a fourth operand.
◦ Data transfer instructions: These instructions move data between memory and registers or between
registers. For example, the “mov” instruction in the x86 assembly language moves data from one
location to another.
TYPES OF INSTRUCTION CODE
Control transfer instructions: These instructions change the flow of program execution by
modifying the program counter. For example, the “jmp” instruction in the x86 assembly
language jumps to a different location in the program.
Arithmetic instructions: These instructions perform mathematical operations on operands.
For example, the “add” instruction in x86 assembly language adds two operands together.
Logical instructions: These instructions perform logical operations on operands. For example,
the “and” instruction in x86 assembly language performs a bitwise AND operation on two
operands.
Comparison instructions: These instructions compare two operands and set a flag based on
the result. For example, the “cmp” instruction in x86 assembly language compares two
operands and sets a flag indicating whether they are equal, greater than, or less than.
◦ Floating-point instructions: These instructions perform arithmetic and other operations on
floating-point numbers. For example, the “fadd” instruction in the x86 assembly language adds
two floating-point numbers together.
OPCODE
◦ An opcode is a collection of bits representing the basic operations, including add,
subtract, multiply, complement, and shift. The number of bits required for the
opcode is determined by the number of functions the computer gives. For ‘2n’
operations, the minimum bits accessible to the opcode should be ‘n’, where n is the
number of bits. We implement these operations on information saved in processor
registers or memory.
TYPES OF OPCODES
There are three different types of instruction codes on
the main computer. The instruction’s operation code
(opcode) is 3 bits long, and the remaining 13 bits are
determined by the operation code encountered.
There are three types of formats:
Memory Reference Instruction: It specifies the
address with 12 bits and the addressing mode with 1
bit (I). For direct addresses, I equal 0, while for
indirect addresses, I equal 1.
Register Reference Instruction: The opcode 111
with a 0 in the leftmost bit of the instruction
recognizes these instructions. The remaining 12 bits
specify the procedure to be carried out.
◦ Input-Output Instruction: The operation code 111
with a 1 in the leftmost bit of instruction recognizes
these instructions. The input-output action is
specified using the remaining 12 bits.
ADDRESS
We represent the memory address where
a given instruction is built. We use an
instruction code’s address bits as an
operand rather than an address. The
instruction in such methods has an
immediate operand. The command is
directed to a direct address if the second
portion contains an address.
◦ In the second half, there is another
choice, which includes the operand’s
address. It points to an oblique address.
One bit might indicate whether the
instruction code executes the direct or
indirect address.
ADDRESSING MODES
We can mainly describe the address field
for instruction in the following ways:
Direct Addressing − Uses the address of
the operand.
Indirect Addressing − Enables the
address as a pointer to the operand.
◦ Immediate operand − The second part
of the instruction code specifies an
operand.