You are on page 1of 33

Instruction set Architecture

DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY


FACULTY OF SCIENCE & TECHNOLOGY
UNIVERSITY OF UWA WELLASSA 1
Introduction
• The instruction set of a microprocessor is a list of all the software
instructions that the processor can execute.

• When an instruction expressed in machine code, it is encoding


using 0’s and 1’s(in hexadecimal format)

• A single machine instruction can take anywhere from 1 to 6 byte


code.

2
Instruction Format
Format of a typical microprocessor instruction

Op-code Operands

Identifies the action Identifies the data to


to be taken be operated

E.g. MOV AX,BX


ADD AX,BX
• Op-code are usually written in the form called mnemonic.
E.g. MOVE MOV
ADDITION ADD
INCREASE INC 3
Instruction Format
An instruction may have 0-3 number of operands
E.g.
No of operands Instruction Meaning

0 HLT Halt the processor

1 INC AX Add 1 to the value of register AX

2 MOV AX,BX Copy the value of BX to AX

3 SHLD DX,AX,4 Shift register AX 4 bits left into DX

4
Classes of 8086 instruction set
1. Data movement
– MOV,PUSH,POP
2. Conversion
– CBW,CWD
3. Arithmetic
– ADD,SUB,MUL,DIV,CMP
4. Logical,shift,rotate and bit instructions
– AND,OR,SHL,SHR,RCL,RCR
5. Input/output instructions
– IN,OUT
6. String instructions
– MOVS ,STOS,LODS
7. Program flow control
– JMP,CALL,RET,Conditional JUMP
8. Miscellaneous 5
Addressing modes of 8086
• Addressing mode refers to valid form of the operand or
operands of an instruction.

• The operands can be registers, memory locations(memory


variables) or constant values.

• There are 3 types of addressing modes

1. Register addressing mode


2. Immediate addressing mode
3. Memory Addressing mode

6
Register Addressing mode
• For an instruction if all the operands are internal registers of
8086 microprocessor then it is in register addressing mode.
E.g.
ADD AX,BX
MOV AX,BX
INC AX
• Not all register conditions are valid addressing mode.
There are some conditions.

• Conditions
1. The size of the operands should match.
Byte registers AL,BL,CL,DL,AH,BH,….(8
bits)
Word registers AX,BX,CX,DX….(16 bits)
7
Register Addressing mode…
ADD AL,BL Valid
ADD AX,BL Invalid
ADD AX,BX Valid
ADD AL,BX Invalid

2. Both operands cannot be in segment registers


e.g.
MOV DS,CS
If you need to move the value stored in CS register to DS
register have to use data registers in between.

MOV AX,CS
MOV DS,AX

8
Immediate Addressing mode
MOV AX,100
• Source is a constant value. It is a part of this instruction. Not
stored in a register or memory location. So operand is called as
an immediate operand.

• To accesses immediate operand immediate addressing mode is


used.
e.g.
MOV AX,100
MOV a,100 where a is a byte in memory
• The source value is immediately available in ALU and the
processor does not need to access any other register or a
memory location to fetch the data

• Therefore the operation will perform much faster 9


Immediate Addressing mode…
• Conditions
1. The size of two operands should be match.
Byte register can store only 0-255.

MOV AL,300
Invalid
MOV AX,300
Valid

2. We can define a constant and then use it as source operand.


This is also an immediate addressing mode.
But the size of defined constant and the destination
register or memory location should be matched.
e.g.
c EQU 20
MOV AL,c
10
Immediate Addressing mode…
• When defining a memory variable

a db 100

a dw 1000

a dd 100000

11
Memory Addressing mode
• If a memory location is used for an operand then it is in memory
addressing mode.

• There are 5 types of memory addressing modes.

1. Direct memory addressing mode


2. Register indirect memory addressing mode
3. Based memory addressing mode
4. Indexed memory addressing mode
5. Based Indexed addressing mode

12
Memory Addressing mode…
1. Direct memory addressing mode
one operand is refers to a memory location directly and
other operand refers to a register

e.g. a db 10 a 10 allocate a 1 byte

MOV AL,a
ADD AL,a
SUB AL,a

• All these instructions are directly accessing the memory


location(without using register)
• Size of memory location and size of registers must
match.
13
Memory Addressing mode…
Example
Suppose we define a double word memory variable with
the value 169,772,160(=0A1E8480H)

a dd 169772160

0A
Highest addressed word
1E
84
a Lowest addressed word
80
(refers to the 1st
byte)

14
Memory Addressing mode…
MOV AL,a AL=80H(AL store only the lowest
byte of a)

MOV AX, a AX=8480H(AX store only the


lowest word of a)
• If
value <=255; Store in a byte register(8 bit)
value <=65535; Store in a word register(16 bit)
value>65535 Store in 2 word register(32 bit)

• previous double word can be


– store as two words
– store as four bytes
in registers
15
Memory Addressing mode…
2. Register indirect memory addressing mode
offset is placed in a register and then use that register to
access the item pointed by the register

• Registers used
BX
SI with data segment
DI
BP - with stack segment

• In order to obtain the offset of a variable OFFSET


operator is used. To access data stored in that memory
location [] operator is used.

16
Memory Addressing mode…
Examples
1. a db 100

MOV BX,OFFSET a
MOV AL,[BX]

AL=100
a 100 1 byte
offset

DS

Physical Address =DS:BX


Use this method to access a memory location of an array
or character string 17
Memory Addressing mode…
ARR db 1,2,3,4,5
MOV BX,OFFSET ARR
MOV CX,5

NEXT: MOV AL,[BX] 4

INC BX 3
LOOP NEXT 2
ARR
1
Offset

DS

18
Memory Addressing mode…
3. Base memory addressing mode
This is similar to register indirect memory addressing
mode, except that the displacement can be added to the
register value, forming the offset to be used as the memory
address.

e.g. 4
MOV BX,OFFSET ARR 3
Displacement
MOV AL,[BX+3] 2
ARR
1
AL=4 Offset

DS

19
Memory Addressing mode…
The displacement can be specified
MOV AX,[reg+disp]
MOV AX,[reg][disp]
MOV AX,disp[reg]
MOV AX,[reg]+disp

Example

ARR db 1,2,3,4,5
MOV BX,OFFSET ARR
MOV AL,[BX+2]
MOV AL,[BX][2]
MOV AL,2[BX]
MOV AL,[BX]+2
20
Memory Addressing mode…
4. Index memory addressing mode
Index addressing works in a similar manner to base
addressing except the displacement is placed in a register and
the offset of the data structure specified in the name itself.

SI and DI registers are typically used for the displacement


although BX and BP can be used
4
e.g. 3
Displacement
ARR db 1,2,3,4,5 2
ARR
MOV SI,3 1
MOV AL,ARR[SI] Offset

MOV AL,ARR[SI+1] DS

21
Memory Addressing mode…
Calculate the sum of two byte arrays

ARR1 db 1,2,3,4,5
ARR2 db 2,4,6,8,10

MOV SI,0
MOV CX,5

NEXT:MOV AL,ARR1[SI]
ADD ARR2[SI],AL
INC SI
LOOP NEXT

22
Memory Addressing mode…
5. Base Index memory addressing mode
This addressing mode is a combination of both base and
index addressing modes.

Here both offset and displacement are store in registers


offset=BX/BI
displacement=SI/DI

Either BX or BP in combination with SI or DI is used.


neither BX and BP nor SI and DI can be used together

MOV DI,OFFSET ARR Invalid


MOV SI,7

MOV BX,OFFSET ARR Invalid 23


MOV BP,5
Memory Addressing mode…
e.g.
ARR db 1,2,3,4,5
MOV BX,OFFSET ARR
MOV SI,3

MOV AL,[BX+SI]
MOV AL,[BX][SI]
MOV AL,[BX]+[SI]
MOV AL,[SI][BX]

24
Stack Segment
The stack segment is a special area of memory designed for quick
temporary storage of program data and the subroutine return
addresses. SP
Register
It is a LIFO (Last In First Out) memory.
BP
Register
SS
Register
SP Register – Points to the top of the stack. Contains the offset of
next memory location to be access in the stack segment.
 
SS Register – Points to the base of the stack.

BP Register – Contains the offset from the base any other memory
location in stack segment. 25
PUSH and POP instructions
In Assembly programming data is push on to the stack by the
PUSH instruction and data is pop out from the stack by POP
instruction.
Operands must be 16 bit registers.

PUSH <Operand> Operands must be 16 bit registers


POP <Operand>

In the stack segment the data define type should be in word


type and therefore the operands must be 16 bit registers.

26
PUSH and POP instructions…
AH AL
Example –
MOV AX, 100 00 64

  AH comes first
PUSH AX AH AL
AH
SP Register AL

AL comes first
SP Register AH AL
POP AX AH
AL

27
PUSH and POP instructions…
In Assembly programming we should allocate memory space to
stack segment.
db 100 dup(?) ; Allocate 100 bytes for the stack segment
Example
MOV AX, 100
PUSH AX
MOV BX, 200
PUSH BX
MOV CX, 300
PUSH CX
POP CX
POP BX

After each PUSH and POP instruction show the content


of the stack segment 28
PUSH and POP instructions…
AH AL
AH
MOV AX, 100
SP Register AL
PUSH AX

 
AH
MOV BX, 200 AL BH BL
PUSH BX BH
SP Register BL

29
PUSH and POP instructions…

AH
MOV CX, 300 AL
PUSH CX BH
BL CH CL
CH
SP Register CL

 
POP CX AH
AL CH CL
BH
SP Register BL

30
PUSH and POP instructions…

BH BL
POP BX
AH
SP Register AL

31
Use of stack segment
• Can use as a stack data structure

• We can use stack segment as a normal stack when we want to


perform some operations using a stack data structure.

• When interrupt is requested before transferring the control to the


ISR (Interrupt Service Routine), the processor save the current
program addresses and data on to the stack (using PUSH
operation).

• When the ISR finishes its execution by using IRET instruction


processor will pop the current program data. (Original values)

32
Use of stack segment…
In Assembly language program, before ‘INT21H’ instruction we have
different values in registers (SS, CS, DS and AX).

When we execute ‘INT21H’ instruction what will happen is, it delete all
the contents in these registers and use them to perform operations
within the ‘INT21H’.

Suppose we have to execute the ‘INT21H’ instruction in the middle of


our program. Then already kept data and instructions in SS, CS, DS and
AX registers should be saved.

In a situation like this the processor uses stack segment. Processors


push these values into stack segment and then free the registers.
After performing the operations within ‘INT21H’, the original data
should keep in the current registers. 33
Processor use IRET instruction to do this.

You might also like