Chapter 4
Chapter 4
1
Introduction
❑ An instruction is a basic command given to a microprocessor to perform a
specified operation with given data.
❑ Each instruction has two groups of bits.
❑ One group of bits is known as operation code (opcode), which defines what
operation will be performed by the instruction.
❑ The other field is called operand, which specifies data that will be used in
operations.
❑ The addressing mode is used to locate the operand or data.
❑ There are different types of addressing modes depending upon the location
of data in the 8086 processor. 2
8086 Addressing mode
3
Instruction Set of 8086
17
Instruction Set of 8086
❑ An instruction is a binary pattern designed inside a microprocessor to
perform a specific function.
❑ It’s a command given to the microprocessor to perform a specific task on a
given data.
18
Classification of Instruction Set
❑ The 8086 microprocessor supports 6 types of instruction set
2. Arithmetic Instructions
19
1. Data Transfer Instructions
❑ They are used for movement of the data from one location to another
location.
❑ They provides the ability to move data either between its internal
registers or between register to/from memory or I/O.
❑ These instructions are used to transfer data from source to destination.
20
Data Transfer Instructions
21
Data Transfer Instructions
❑ PUSH Src:
❑ It pushes the data from src operand into top of stack
❑ E.g.:
PUSH BX
❑ POP Des:
❑ It pops the operand from top of stack to Des operand.
❑ Des can be a general purpose register, segment register (except CS) or memory
location.
❑ E.g.:
POP AX
22
Data Transfer Instructions
23
Data Transfer Instructions
❑ IN Accumulator, PortAddress:
❑ It transfers the operand from specified port to accumulator register.
❑ E.g.:
IN AX, 0028 H
❑ E.g.:
OUT 0028 H, AX
24
Data Transfer Instructions
❑ E.g.:
LEABX, [DI]
25
Data Transfer Instructions
27
Data Transfer Instructions
❑ LAHF:
❑ It copies the lower byte of flag register to AH.
❑ SAHF:
❑ It copies the contents of AH to lower byte of flag register.
❑ PUSHF:
❑ Pushes flag register to top of stack.
❑ POPF:
❑ Pops the stack from top to flag register.
28
2. Arithmetic Instructions
❑ These instructions are used to perform arithmetic operations like
addition, subtraction, multiplication, division, etc.
❑ E.g.:
ADD AL, 74H
ADD DX, AX
ADC DX, AX
30
Arithmetic Instructions
31
Arithmetic Instructions
32
Arithmetic Instructions
❑ INC Src:
❑ It increments the byte or word by one.
❑ The operand can be a register or memory location.
❑ It effects AF, OF, PF, SF, ZF flags.
❑ CF is not effected.
❑ E.g.:
INC AX
33
Arithmetic Instructions
❑ DEC Src:
❑ It decrements the byte or word by one.
❑ The operand can be a register or memory location.
❑ It effects AF, OF, PF, SF, ZF flags.
❑ CF is not effected.
❑ E.g.:
DEC AX
34
Arithmetic Instructions
35
Arithmetic Instructions
36
Arithmetic Instructions
❑ NEG Src:
❑ E.g.:
NEG AL
37
Arithmetic Instructions
38
Arithmetic Instructions
❑ MUL Src:
❑ It is an unsigned multiplication instruction.
❑ It multiplies two bytes to produce a word or two words to produce a double
word.
AX = AL * Src
DX : AX = AX * Src
❑ This instruction assumes one of the operand in AL or AX.
IMUL Src:
❑ It is a signed multiplication instruction.
39
Arithmetic Instructions
❑ DIV Src:
❑ It is an unsigned division instruction.
❑ IDIV Src:
❑ It is a signed division instruction.
40
Arithmetic Instructions
41
3. Bit Manipulation Instructions
❑ These instructions are used at the bit level.
❑ These instructions can be used for:
❑ Testing a zero bit
42
Bit Manipulation Instructions
❑ NOT Src:
❑ It complements each bit of Src to produce 1’s complement of
the specified operand.
❑ The operand can be a register or memory location.
❑ E.g.:
NOT AX
43
Bit Manipulation Instructions
❑ AND Des, Src:
❑ It performs AND operation of Des and Src.
44
Bit Manipulation Instructions
❑ OR Des, Src:
❑ It performs OR operation of Des and Src.
45
Bit Manipulation Instructions
46
Bit Manipulation Instructions
47
Bit Manipulation Instructions
48
Bit Manipulation Instructions
49
Bit Manipulation Instructions
50
4. Program Execution Transfer Instructions
51
Program Execution Transfer Instructions
❑ CALLDes:
❑ This instruction is used to call a subroutine or function or
procedure.
❑ The address of next instruction after CALL is saved onto stack.
❑ RET:
❑ It returns the control from procedure to calling program.
52
Program Execution Transfer Instructions
❑ JMP Des:
❑ This instruction is used for unconditional jump from one place
to another.
53
Program Execution Transfer Instructions
Conditional Jump instruction table
54
Program Execution Transfer Instructions
Conditional Jump instruction table
55
Program Execution Transfer Instructions
❑ Loop Des:
56
5. String Instructions
❑ String in assembly language is just a sequentially stored
bytes or words.
57
String Instructions
❑ SCAS String:
❑ It scans a string and
58
String Instructions
index.
59
String Instructions
❑ REP (Repeat):
❑ This is an instruction prefix (label).
attached.
61
Processor Control Instructions
❑ STC:
❑ It sets the carry flag to 1.
❑ CLC:
❑ It clears the carry flag to 0.
❑ CMC:
❑ It complements the carry flag.
62
Processor Control Instructions
❑ STD:
❑ It sets the direction flag to 1.
❑ CLD:
❑ It clears the direction flag to 0.
64
65
66
67
68
69
70
Assembly language programming
71
Assembly language programming
❑ A program is a set of instructions arranged in the specific sequence to
do the specific task.
❑ The process of writing the set of instructions which tells the
microprocessor what to do is called programming.
❑ To do this the programmer must speak to the microprocessor in a
language which processor can understand.
❑ Steps involving in programing:-
❑ Specifying the problem
❑ Designing the problem solution
❑ Coding and
❑ Debugging
72
❑ Specifying the problem:
✓ the first step in the programming is to find out which task is to be
performed.
❑ Designing the problem-solution:
✓ during designing, the exact step by step process that is to be followed is
developed and written down.
❑ Coding:
✓ Implementation begins with the process of coding the program.
✓ It means, to tell the processer the exact step by step process in its language.
✓ Programmer has to choose proper instructions from the instruction set to
build the program.
❑ Debugging:
✓ It is the process of testing the code to see if it dose the given task properly.
✓ If program is not working properly, debugging process helps in finding and
correcting errors. 73
Flow chart
❑ To develop and design the problem-solution programmer has to write
down various actions which are to be performed in proper sequence.
74
Oval: It indicates start or stop of operation.
Arrow: It indicates flow with direction.
78
❑ Mnemonic: which is mandatory, all instructions must contain a
mnemonic which is the opcode (operation code) .
❑ Operands: the presence of operands depends on the instruction.
❑ Some instructions have no operand, some have one and some have
two. If there are two operands, they are separated by comma.
❑ Comment: they starts with a semicolon and continuous to the end of
the line. They tell us what the program is trying to accomplish.
79
Comparison between machine level and assembly language
No. Machine language Assembly language
1 Consists of binary codes which Consists of mnemonics which specify
specifies the operations the operations
2 Processor dependent and hence Processor dependent and hence
requires knowledge of internal details requires knowledge of internal details
of processors to write a program of processors to write a program
3 Programs require less memory Programs require less memory
4 Programs have less execution time Programs have less execution time
5 Program development is difficult Program development is simpler than
machine language
6 It is not user friendly It is less user friendly
80
Assembly language programming tips
❑ To writing a program for specific task, programmer may find a number
of solutions (instruction sequences).
81
❑ What is an optimum solution ? :
❑ When we say memory space for the program we consider space for
program storage (program length), space for data storage and space
used by the stack.
82
❑ Use of proper instructions :
❑ Many time we come across the situation where more than one set of instructions
are available to perform particular functions.
❑ For example, if the function is add 01 in the BX register of 8086 we have two
options : ADD BX, 0001H or INC BX.
❑ In such situations we must check the space and time for both the options and then
select the option which requires less space and time.
❑ ADD BX, 0001H is four byte instruction, hence requires 4 clock cycle to execute it.
❑ INC BX is two byte instruction hence requires 2 clock cycle to execute it.
❑ The instruction INC BX requires less memory space and execution time than
ADD BX, 0001H.
83
❑ Use of advanced instructions:
❑ We must optimally utilize the processor capability.
❑ For example, when it is necessary to write a program to move a block of data
from the source to destination location, a programmer may initialize a pointer
to indicate source location, pointer to indicate destination location and a
counter to count the number of data elements to be transferred.
❑ After transfer of one data element from source to destination location
programmer may use INC, DEC and JNZ instructions to increment source
and destination pointers, decrement counter and to check whether all data
elements are transferred or not, respectively.
❑ The same task can be implemented by MOVS instructions supported by 8086.
85
Part listing of program with MOVSB instruction:
❑ From the two programmes we can easily notice that the MOVSB instruction needes
not neither counter decrement and jump back nor pointer update instructions.
❑ All these functions are done authomatically, becouse MOVSB instructions copies
multiple bytes from source to destination.
86
❑ After each byte transfers it automatically increments SI and DI
pointers by 1 (since DF = 0) and decrements count in CX register and
it repeats this process until CX = 0.
90
❑ Assembling process : assembler translates a source file that
was created using the editor in to machine language such as
binary or object code.