0% found this document useful (0 votes)
4 views

instruction code

Instruction code ppt c language

Uploaded by

sakshipawar5668
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

instruction code

Instruction code ppt c language

Uploaded by

sakshipawar5668
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Computer Instructions

Computer instructions are a set of machine language instructions that a particular


processor understands and execute computer performs tasks on the basis of the
instruction provided.

An instruction comprises of groups called fields. These fields include:

o The Operation code (Opcode) field which specifies the operation to be performed.
o The Address field which contains the location of the operand, i.e., register or memory
location.
o The Mode field which specifies how the operand will be located.

A basic computer has three instruction code formats which are:

1. Memory - reference instruction


2. Register - reference instruction
3. Input-Output instruction

Memory - reference instruction

In Memory-reference instruction, 12 bits of memory is used to specify an address and


one bit to specify the addressing mode 'I'.

Register - reference instruction

The Register-reference instructions are represented by the Opcode 111 with a 0 in the
leftmost bit (bit 15) of the instruction.
Note: The Operation code (Opcode) of an instruction refers to a group of bits that
define arithmetic and logic operations such as add, subtract, multiply, shift, and
compliment.

A Register-reference instruction specifies an operation on or a test of the AC


(Accumulator) register.

Input-Output instruction

Just like the Register-reference instruction, an Input-Output instruction does not need a
reference to memory and is recognized by the operation code 111 with a 1 in the
leftmost bit of the instruction. The remaining 12 bits are used to specify the type of the
input-output operation or test performed.

Note
o The three operation code bits in positions 12 through 14 should be equal to 111.
Otherwise, the instruction is a memory-reference type, and the bit in position 15 is
taken as the addressing mode I.
o When the three operation code bits are equal to 111, control unit inspects the bit in
position 15. If the bit is 0, the instruction is a register-reference type. Otherwise, the
instruction is an input-output type having bit 1 at position 15.
Addressing Modes– The term addressing modes refers to the way in
which the operand of an instruction is specified. The addressing mode
specifies a rule for interpreting or modifying the address field of the
instruction before the operand is actually executed.
Addressing modes for 8086 instructions are divided into two
categories:
1) Addressing modes for data
2) Addressing modes for branch
The 8086 memory addressing modes provide flexible access to memory,
allowing you to easily access variables, arrays, records, pointers, and
other complex data types. The key to good assembly language
programming is the proper use of memory addressing modes.
An assembly language program instruction consists of two parts

The memory address of an operand consists of two components:


IMPORTANT TERMS
 Starting address of memory segment.
 Effective address or Offset: An offset is determined by adding any
combination of three address elements: displacement, base and
index.
o Displacement: It is an 8 bit or 16 bit immediate value given in
the instruction.
o Base: Contents of base register, BX or BP.
o Index: Content of index register SI or DI.
According to different ways of specifying an operand by 8086
microprocessor, different addressing modes are used by 8086.
Addressing modes used by 8086 microprocessor are discussed below:
 Implied mode:: In implied addressing the operand is specified in the
instruction itself. In this mode the data is 8 bits or 16 bits long and data
is the part of instruction.Zero address instruction are designed with
implied addressing mode.

Example: CLC (used to reset Carry flag to 0)


 Immediate addressing mode (symbol #):In this mode data is present
in address field of instruction .Designed like one address instruction
format.
Note:Limitation in the immediate mode is that the range of constants
are restricted by size of address field.

Example: MOV AL, 35H (move the data 35H into AL register)
 Register mode: In register addressing the operand is placed in one of
8 bit or 16 bit general purpose registers. The data is in the register that
is specified by the instruction.
Here one register reference is required to access the data.

Example: MOV AX,CX (move the contents of CX register to AX


register)
 Register Indirect mode: In this addressing the operand’s offset is
placed in any one of the registers BX,BP,SI,DI as specified in the
instruction. The effective address of the data is in the base register or
an index register that is specified by the instruction.
Here two register reference is required to access the data.

The 8086 CPUs let you access memory indirectly through a register
using the register indirect addressing modes.
 MOV AX, [BX](move the contents of memory location s
addressed by the register BX to the register AX)
 Auto Indexed (increment mode): Effective address of the operand is
the contents of a register specified in the instruction. After accessing
the operand, the contents of this register are automatically incremented
to point to the next consecutive memory location.(R1)+.
Here one register reference,one memory reference and one ALU
operation is required to access the data.
Example:
 Add R1, (R2)+ // OR
 R1 = R1 +M[R2]
R2 = R2 + d
Useful for stepping through arrays in a loop. R2 – start of array d – size
of an element
 Auto indexed ( decrement mode): Effective address of the operand is
the contents of a register specified in the instruction. Before accessing
the operand, the contents of this register are automatically
decremented to point to the previous consecutive memory location. –
(R1)
Here one register reference,one memory reference and one ALU
operation is required to access the data.
Example:
Add R1,-(R2) //OR
R2 = R2-d
R1 = R1 + M[R2]
Auto decrement mode is same as auto increment mode. Both can also be
used to implement a stack as push and pop . Auto increment and Auto
decrement modes are useful for implementing “Last-In-First-Out” data
structures.
 Direct addressing/ Absolute addressing Mode (symbol [ ]): The
operand’s offset is given in the instruction as an 8 bit or 16 bit
displacement element. In this addressing mode the 16 bit effective
address of the data is the part of the instruction.
Here only one memory reference operation is required to access the
data.

Example:ADD AL,[0301] //add the contents of offset


address 0301 to AL
 Indirect addressing Mode (symbol @ or () ):In this mode address
field of instruction contains the address of effective address.Here two
references are required.
1st reference to get effective address.
2nd reference to access the data.
Based on the availability of Effective address, Indirect mode is of two
kind:
1. Register Indirect:In this mode effective address is in the register,
and corresponding register name will be maintained in the address
field of an instruction.
Here one register reference,one memory reference is required to
access the data.
2. Memory Indirect:In this mode effective address is in the memory,
and corresponding memory address will be maintained in the
address field of an instruction.
Here two memory reference is required to access the data.
 Indexed addressing mode: The operand’s offset is the sum of the
content of an index register SI or DI and an 8 bit or 16 bit
displacement.
Example:MOV AX, [SI +05]
 Based Indexed Addressing: The operand’s offset is sum of the
content of a base register BX or BP and an index register SI or DI.
Example: ADD AX, [BX+SI]
Based on Transfer of control, addressing modes are:
o PC relative addressing mode: PC relative addressing mode is
used to implement intra segment transfer of control, In this mode
effective address is obtained by adding displacement to PC.
o EA= PC + Address field value
PC= PC + Relative value.
o Base register addressing mode:Base register addressing
mode is used to implement inter segment transfer of control.In
this mode effective address is obtained by adding base register
value to address field value.
o EA= Base register + Address field value.
o PC= Base register + Relative value.
Note:
1. PC relative and based register both addressing modes are
suitable for program relocation at runtime.
2. Based register addressing mode is best suitable to write
position independent codes.
Advantages of Addressing Modes
6. To give programmers to facilities such as Pointers, counters for loop
controls, indexing of data and program relocation.
7. To reduce the number bits in the addressing field of the Instruction.
Sample GATE Question
Match each of the high level language statements given on the left hand
side with the most natural addressing mode from those listed on the right
hand side.
1. A[1] = B[J]; a. Indirect addressing
2. while [*A++]; b. Indexed addressing
3. int temp = *x; c. Autoincrement
(A) (1, c), (2, b), (3, a)
(B) (1, a), (2, c), (3, b)
(C) (1, b), (2, c), (3, a)
(D) (1, a), (2, b), (3, c)
Answer: (C)
Explanation:
List 1 List 2
1) A[1] = B[J]; b) Index addressing
Here indexing is used

2) while [*A++]; c) auto increment


The memory locations are automatically incremented

3) int temp = *x; a) Indirect addressing


Here temp is assigned the value of int type stored
at the address contained in X
Hence (C) is correct solution.
lease write comments if you find anything incorrect, or you want to share
more information about the topic discussed above.

Computer Registers
Registers are a type of computer memory used to quickly accept, store, and transfer
data and instructions that are being used immediately by the CPU. The registers used by
the CPU are often termed as Processor registers.

A processor register may hold an instruction, a storage address, or any data (such as bit
sequence or individual characters).

The computer needs processor registers for manipulating data and a register for holding
a memory address. The register holding the memory location is used to calculate the
address of the next instruction after the execution of the current instruction is completed.

Following is the list of some of the most common registers used in a


basic computer:

Register Symbol Number of bits Function

Data register DR 16 Holds memory operand

Address register AR 12 Holds address for the memory

Accumulator AC 16 Processor register

Instruction register IR 16 Holds instruction code

Program counter PC 12 Holds address of the instruction

Temporary register TR 16 Holds temporary data

Input register INPR 8 Carries input character


Output register OUTR 8 Carries output character

The following image shows the register and memory configuration for a basic computer.

o The Memory unit has a capacity of 4096 words, and each word contains 16
bits.
o The Data Register (DR) contains 16 bits which hold the operand read from the
memory location.
o The Memory Address Register (MAR) contains 12 bits which hold the address
for the memory location.
o The Program Counter (PC) also contains 12 bits which hold the address of
the next instruction to be read from memory after the current instruction is
executed.
o The Accumulator (AC) register is a general purpose processing register.
o The instruction read from memory is placed in the Instruction register (IR).
o The Temporary Register (TR) is used for holding the temporary data during
the processing.
o The Input Registers (IR) holds the input characters given by the user.
o The Output Registers (OR) holds the output after processing the input data.

Instruction Cycle
A program residing in the memory unit of a computer consists of a sequence of
instructions. These instructions are executed by the processor by going through a cycle
for each instruction.

In a basic computer, each instruction cycle consists of the following phases:

1. Fetch instruction from memory.


2. Decode the instruction.
3. Read the effective address from memory.
4. Execute the instruction.

Register Transfer
The term Register Transfer refers to the availability of hardware logic circuits that can
perform a given micro-operation and transfer the result of the operation to the same or
another register.

Most of the standard notations used for specifying operations on various registers are
stated below.

o The memory address register is designated by MAR.


o Program Counter PC holds the next instruction's address.
o Instruction Register IR holds the instruction being executed.
o R1 (Processor Register).
o We can also indicate individual bits by placing them in parenthesis. For instance, PC
(8-15), R2 (5), etc.
o Data Transfer from one register to another register is represented in symbolic form
by means of replacement operator. For instance, the following statement denotes a
transfer of the data of register R1 into register R2.
1. R2 ← R1

o Typically, most of the users want the transfer to occur only in a predetermined control
condition. This can be shown by following if-then statement:
If (P=1) then (R2 ← R1); Here P is a control signal generated in the control section.
o It is more convenient to specify a control function (P) by separating the control
variables from the register transfer operation. For instance, the following statement
defines the data transfer operation under a specific control function (P).
1. P: R2 ← R1
The following image shows the block diagram that depicts the transfer of data from R1 to
R2.
Bus and Memory Transfers
A digital system composed of many registers, and paths must be provided to transfer
information from one register to another. The number of wires connecting all of the
registers will be excessive if separate lines are used between each register and all other
registers in the system.

A bus structure, on the other hand, is more efficient for transferring information between
registers in a multi-register configuration system.

A bus consists of a set of common lines, one for each bit of register, through which
binary information is transferred one at a time. Control signals determine which register
is selected by the bus during a particular register transfer.

The following block diagram shows a Bus system for four registers. It is constructed with
the help of four 4 * 1 Multiplexers each having four data inputs (0 through 3) and two
selection inputs (S1 and S2).

Backward Skip 10sPlay VideoForward Skip 10s

We have used labels to make it more convenient for you to understand the input-output
configuration of a Bus system for four registers. For instance, output 1 of register A is
connected to input 0 of MUX1.
The two selection lines S1 and S2 are connected to the selection inputs of all four
multiplexers. The selection lines choose the four bits of one register and transfer them
into the four-line common bus.

When both of the select lines are at low logic, i.e. S1S0 = 00, the 0 data inputs of all four
multiplexers are selected and applied to the outputs that forms the bus. This, in turn,
causes the bus lines to receive the content of register A since the outputs of this register
are connected to the 0 data inputs of the multiplexers.

Similarly, when S1S0 = 01, register B is selected, and the bus lines will receive the
content provided by register B.

The following function table shows the register that is selected by the bus for each of the
four possible binary values of the Selection lines.
bus system can also be constructed using three-state gates instead of multiplexers.

Advertisement

The three state gates can be considered as a digital circuit that has three gates, two of
which are signals equivalent to logic 1 and 0 as in a conventional gate. However, the
third gate exhibits a high-impedance state.

The most commonly used three state gates in case of the bus system is a buffer gate.

The graphical symbol of a three-state buffer gate can be represented as:

The following diagram demonstrates the construction of a bus system with three-state
buffers.
o The outputs generated by the four buffers are connected to form a single bus line.
o Only one buffer can be in active state at a given point of time.
o The control inputs to the buffers determine which of the four normal inputs will
communicate with the bus line.
o A 2 * 4 decoder ensures that no more than one control input is active at any given
point of time.

Memory Transfer
Most of the standard notations used for specifying operations on memory transfer are
stated below.

o The transfer of information from a memory unit to the user end is called
a Read operation.
o The transfer of new information to be stored in the memory is called
a Write operation.
o A memory word is designated by the letter M.
o We must specify the address of memory word while writing the memory transfer
operations.
o The address register is designated by AR and the data register by DR.
o Thus, a read operation can be stated as:
1. Read: DR ← M [AR]
o The Read statement causes a transfer of information into the data register (DR) from
the memory word (M) selected by the address register (AR).
o And the corresponding write operation can be stated as:
1. Write: M [AR] ← R1

o The Write statement causes a transfer of information from register R1 into the
memory word (M) selected by address register (AR).

Arithmetic Micro-operations
In general, the Arithmetic Micro-operations deals with the operations performed on
numeric data stored in the registers.

The basic Arithmetic Micro-operations are classified in the following categories:

1. Addition
2. Subtraction
3. Increment
4. Decrement
5. Shift

Some additional Arithmetic Micro-operations are classified as:

1. Add with carry


2. Subtract with borrow
3. Transfer/Load, etc.

The following table shows the symbolic representation of various Arithmetic Micro-
operations.

Symbolic Representation Description

R3 ← R1 + R2 The contents of R1 plus R2 are transferred to R3.

R3 ← R1 - R2 The contents of R1 minus R2 are transferred to R3.

R2 ← R2' Complement the contents of R2 (1's complement)


R2 ← R2' + 1 2's complement the contents of R2 (negate)

R3 ← R1 + R2' + 1 R1 plus the 2's complement of R2 (subtraction)

R1 ← R1 + 1 Increment the contents of R1 by one

R1 ← R1 - 1 Decrement the contents of R1 by one

Logic operations are binary micro-operations implemented on the bits


saved in the registers. These operations treated each bit independently and
create them as binary variables.

For example, the exclusive-OR micro-operation with the contents of two


registers R1 and R2 is denoted by the statement

P: R1←R1⊕⊕R2

It determines a logic micro-operation to be implemented on the single bits of


the registers supported that the control variable P = 1. Consider that each
register has four bits. Let the content of R1 be 1010 and the content of R2 be
1100.

The exclusive-OR micro-operation stated above represent the following logic


computation −

1010 Content of R1
1100 Content of R2
0110 Content of R1 after P = 1

The content of R1, after the implementation of the micro-operation, is similar


to the bit-by-bit exclusive-OR operation on pairs of bits in R2 and previous
values of R1.
What are Shift Micro-Operations in Computer
Architecture?
Shift micro-operations are used when the data is stored in registers. These micro-
operations are used for the serial transmission of data. Here, the data bits are shifted
from left to right. These micro-operations are also combined with arithmetic and logic
micro-operations and data-processing operations.
There are three types of shift micro-operations-
1. Logical Shift
2. Arithmetic Shift
3. Circular Shift
Let’s start with logical shift micro-operation.
Logical Shift
The logical shift micro-operation moves the 0 through the serial input. There are two
ways to implement the logical shift.
1. Logical Shift Left
2. Logical Shift Right
Let’s discuss both of them one by one.
Logical Shift Left
Each bit in the register is shifted to the left one by one in this shift micro-operation.
The most significant bit (MSB) is moved outside the register, and the place of the
least significant bit (LSB) is filled with 0.
For example, in the below data, there are 8 bits 00001010. When we perform a
logical shift left on these bits, all these bits will be shifted towards the left. The MSB
or the leftmost bit i.e. 0 will be moved outside, and at the rightmost place or LSB, 0
will be inserted as shown below.

To implement the logical shift left micro-operation, we use the shl symbol.
For example, R1 -> shl R1.
This command means the 8 bits present in the R1 register will be logically shifted
left, and the result will be stored in register R1.
Moreover, the logical shift left microoperation denotes the multiplication of 2. The
example we’ve taken above when converted into decimal forms the number 10. And
the result after the logical shift operation when converted to decimal forms the
number 20.
Next, we will see the logical shift right micro-operation.
Logical Shift Right
Each bit in the register is shifted to the right one by one in this shift micro-operation.
The least significant bit (LSB) is moved outside the register, and the place of the
most significant bit (MSB) is filled with 0.
For example, in the below data, there are 8 bits 00000101. When we perform a
logical shift right on these bits, all these bits will be shifted towards the right. The
LSB or the rightmost bit i.e. 1 will be moved outside, and at the leftmost place or
MSB, 0 will be inserted as shown below.

To implement the logical shift right micro-operation, we use the shr symbol.
For example, R1 -> shr R1.
This command means the 8 bits present in the R1 register will be logically shifted
right, and the result will be stored in register R1.
Logical right shift micro-operation generally denotes division by 2. The inputted bits
when converted into decimal form the number 5. And the outcome when converted
into decimal forms the number 2.
Next, we will study arithmetic shift micro-operation.
Arithmetic Shift
The arithmetic shift micro-operation moves the signed binary number either to the
left or to the right position. There are two ways to implement the arithmetic shift.
1. Arithmetic Shift Left
2. Arithmetic Shift Right
Let’s discuss both of them one by one.
Arithmetic Shift Left
The arithmetic shift left micro-operation is the same as the logical shift left micro-
operation. Each bit in the register is shifted to the left one by one in this shift micro-
operation. The most significant bit (MSB) is moved outside the register, and the
place of the least significant bit (LSB) is filled with 0.
For example, in the below data, there are 8 bits 00100011. When we perform the
arithmetic shift left on these bits, all these bits will be shifted towards the left. The
MSB or the leftmost bit i.e. 0 will be moved outside, and at the rightmost place or
LSB, 0 will be inserted as shown below.

The given binary number (00100011) represents 35 in the decimal system. And the
binary number after logical shift left (01000110) represents 70 in a decimal system.
Since 35 * 2 = 70. Therefore, we can say that the arithmetic shift left multiplies the
number by 2.
To implement the arithmetic shift left micro-operation, we use the ashl symbol.
For example, R1 -> ashl R1.
This command means the 8 bits present in the R1 register will be arithmetic shifted
left, and the result will be stored in register R1.
Arithmetic Shift Right
Each bit in the register is shifted to the right one by one in this shift micro-operation.
The least significant bit (LSB) is moved outside the register, and the place of the
most significant bit (MSB) is filled with the previous value of MSB.
For example, in the below data, there are 8 bits 10100011. When we perform an
arithmetic shift right on these bits, all these bits will be shifted towards the right. The
LSB or the rightmost bit i.e. 1 will be moved outside, and at the leftmost place or
MSB, the previous MSB value, i.e. 1, will be inserted as shown below.
Arithmetic right shift divides the number by 2.
To implement the arithmetic shift right micro-operation, we use the ashr symbol.
For example, R1 -> ashr R1.
This command means the 8 bits present in the R1 register will be arithmetic shifted
right, and the result will be stored in register R1.
Next, we will study circular shift micro-operation.
Circular Shift
The circular shift, also known as the rotate shift, moves the bits in the register's
sequence around both ends, thus ensuring no loss of information. There are two
ways to implement the circular shift.
1. Circular Shift Left
2. Circular Shift Right
Let’s discuss both of them one by one.
Circular Shift Left
Each bit in the register is shifted to the left one by one in this shift micro-operation.
After shifting, the least significant bit (LSB) place becomes empty, so it is filled with
the value at the most significant bit (MSB).
For example, in the below data, there are 8 bits 00010100. When we perform a
circular shift left on these bits, all these bits will be shifted towards the left. The MSB
or the leftmost bit i.e. 0 will be placed at the rightmost place or LSB as shown below.
To implement the circular shift left micro-operation, we use the cil symbol.
For example, R1 -> cil R1.
This command means the 8 bits present in the R1 register will be circular shifted left,
and the result will be stored in register R1.
Next, we will discuss circular shift right micro-operation.
Circular Shift Right
Each bit in the register is shifted to the right one by one in this shift micro-operation.
After shifting, the most significant bit (MSB) place becomes empty, so it is filled with
the value at the least significant bit (LSB).
For example, in the below data, there are 8 bits 00010100. When we perform a
circular shift right on these bits, all these bits will be shifted towards the right. The
LSB or the leftmost bit, i.e. 0, will be placed at the rightmost place or MSB.
To implement the circular shift right micro-operation, we use the cir symbol.
For example, R1 -> cir R1.
This command means the 8 bits present in the R1 register will be circular shifted
right, and the result will be stored in register R1.

You might also like