You are on page 1of 58

ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD

LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)


Version #: NT-2301)

Introduction to Assembly Language Programming

Table of Contents

What is assembly language?................................................................................................................. 2

Advantages of Assembly language: ............................................................................................................. 2

Cons of Assembly language: ......................................................................................................................... 2

General Purpose Registers................................................................................................................ 3

Segment Registers ............................................................................................................................... 3

Variables ................................................................................................................................................. 4

Arrays ...................................................................................................................................................... 4

Memory ................................................................................................................................................... 5

Computer's Memory: .......................................................................................................................... 5

Memory Models..................................................................................................................................... 6

Getting the Address of a Variable .................................................................................................... 6

BIOS Interrupts ..................................................................................................................................... 6

Arithmetic and Logic Instructions ................................................................................................... 7

All 8086 Assembly Instructions in alphabetical Order: .................................................................. 8

Challenging Programming tasks for students ............................................................................................48

Installation and setting-up Environment ...................................................................................................54

Format of a machine instruction ............................................................................................................55

Template of an assembly program in MASM for DOS ..........................................................................56

IMCB H-9, Islamabad____________( Page 1 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

What is Assembly Language?


Assembly language is a low level programming language. You need to get better knowledge
about computer structure for better understanding. x86 series Processors (also known as 80x86
or the 8086 family) is a family of complex instruction set computer (CISC) instruction set
architectures, initially developed by Intel based on the Intel 8086 microprocessor and its 8088
variant. The 8086 was introduced in 1978 as a fully 16-bit extension of Intel's 8-bit 8080
microprocessor, with memory segmentation as a solution for addressing more memory than can
be covered by a plain 16-bit address. The term "x86" came into being because the names of
several successors to Intel's 8086 processor end in "86", including the 80186, 80286, 80386 and
80486 processors.

Advantages of Assembly language:


 It allows complex jobs to run in a simpler way.
 It is memory efficient
 It is architecture dependent
 It is faster in speed
 It is hardware-oriented.
 It is used for critical jobs and fine tuning of complex programs.
 It is a low-level embedded system.

Cons of Assembly language:


 It takes a lot of time and effort to write the code.
 Complex and difficult to understand.
 It has a lack of portability of programs between different computer architectures.
 It needs more size or memory of the computer to run the long programs

Here is a simple computer model (Left) and registers inside a 8086 CPU (Right)

IMCB H-9, Islamabad____________( Page 2 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

General Purpose Registers

8086 CPU has 8 general purpose registers, each register has its own name:
AX - the accumulator register (divided into AH / AL).
BX - the base address register (divided into BH / BL).
CX - the count register (divided into CH / CL).
DX - the data register (divided into DH / DL).
SI - source index register.
DI - destination index register.
BP - base pointer.
SP - stack pointer.

NOTE: 32Bit Architecture has EAX, EBX, ECX, EDX whereas 64 Bit has RAX, RBx, RCX, RDX
Despite the name of a register, it's the programmer who determines the usage for each general
purpose register. The main purpose of a register is to keep a number (variable). The size of the
above registers is 16 bit, it's something like: 0011000000111001b (in binary form), or 12345 in
decimal (human) form. 4 general purpose registers (AX, BX, CX, DX) are made of two separate
8bit registers, for example if AX= 0011000000111001b, then AH=00110000b and
AL=00111001b. Therefore, when you modify any of the 8 bit registers 16 bit register is also
updated, and vice-versa. The same is for other 3 registers, "H" is for high and "L" is for low part.

Because registers are located inside the CPU, they are much faster than memory. Accessing a
memory location requires the use of a system bus, so it takes much longer. Accessing data in a
register usually takes no time. Therefore, you should try to keep variables in the registers. Register
sets are very small and most registers have special purposes which limit their use as variables,
but they are still an excellent place to store temporary data of calculations.

Segment Registers
CS - points at the segment containing the current program.
DS - generally points at segment where variables are defined.
ES - extra segment register, it's up to a coder to define its usage.
SS - points at the segment containing the stack.
Although it is possible to store any data in the segment registers, this is never a good idea. The
segment registers have a very special purpose - pointing at accessible blocks of memory.
Segment registers work together with general purpose register to access any memory value.

IMCB H-9, Islamabad____________( Page 3 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

For example if we would like to access memory at the physical address 12345h (hexadecimal),
we should set the DS = 1230h and SI = 0045h. This is good, since this way we can access
much more memory than with a single register that is limited to 16 bit values. CPU makes a
calculation of physical address by multiplying the segment register by 10h and adding general
purpose register to it (1230h * 10h + 45h = 12345h):

The address formed with 2 registers is called an effective address. By default BX, SI and
DI registers work with DS segment register; BP and SP work with SS segment register.
Other general purpose registers cannot form an effective address! Also, although BX can form
an effective address, BH and BL cannot! SPECIAL PURPOSE REGISTERS
IP - the instruction pointer.
Flags Register - determines the current state of the processor.

Variables
Variable is a memory location. For a programmer it is much easier to have some value be kept in
a variable named "var1" then at the address 5A73:235B, especially when you have 10 or more
variables. Compiler supports two types of variables: BYTE and WORD (DB,DW,DD,DQ,DT)

ORG 100h is a compiler directive (it tells compiler how to handle the source code). This directive
is very important when you work with variables. It tells compiler that the executable file will be
loaded at the offset of 100h (256 bytes), so compiler should calculate the correct address for all
variables when it replaces the variable names with their offsets.

Directives are never converted to any real machine code.


Why executable file is loaded at offset of 100h?
Operating system keeps some data about the program in the first 256 bytes of the CS
(code segment), such as command line parameters and etc. This is true for COM files only.

Arrays
Arrays can be seen as chains of variables. A text string is an example of a byte array,
each character is presented as an ASCII code value (0..255). Here are some array definition
examples: a DB 48h, 65h, 6Ch, 6Ch, 6Fh, 00h b DB 'Hello', 0
You can access the value of any element in array using square brackets, for example:
MOV AL, a[3] You can also use any of the memory index registers BX, SI, DI, BP,
for example:
MOV SI, 3
MOV AL, a[SI]

IMCB H-9, Islamabad____________( Page 4 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

If you need to declare a large array you can use DUP operator. The syntax for DUP:
number DUP ( value(s) )

number - number of duplicate to make (any constant value). value - expression that DUP will
duplicate.
for example:
c DB 5 DUP(9)
is an alternative way of declaring:
c DB 9, 9, 9, 9, 9

Memory
An original IBM PC could contain 1 Megabyte of byte-addressable memory. "Byte-addressable"
means that each byte has its own unique address. Addresses always start at zero and go up in steps
of one; so every number from zero up to 1 "Meg" is an identifier or "address" of a unique storage
location.
1 Megabyte is two to the power of 20 (220) bytes or 1,048,576 bytes. Another way of looking at it
is to say, 1 Megabyte is the number of locations that can be uniquely addressed by 20 bits.

CPU used in the IBM PC uses a 16-bit address bus. With a 16-bit address, we can only access a
range of 64K bytes within the full 1M bytes of the computer's memory. However, by using those
16 bits as an "offset" or distance from some arbitrarily selectable beginning location, the 64K
"segment" which we can address may be anywhere within the full 1M byte.
Computer's Memory:
+-------------------------------+ ___
| | .
| | .
| | .
| | .
| | .
| | .
| | .
| | .
| | .
| | .
| | .
start | |
of -->+-------------------------------+ 1M Memory
segment | |
| 64K Segment | 20-bit addressable
| | space
| 16-bit addressable | .
| space | .
| | .
+-------------------------------+ .
| | .
| | .
| | .
| | .
| | .
| | .
| | .
+-------------------------------+ ___

IMCB H-9, Islamabad____________( Page 5 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

In practice, a program may use several segments, each up to 64K bytes long and each with its own
initial "segment address". A segment can begin at any address which is a multiple of 10h (16d)
within the computer's 1 Megabyte range. Any address that is a multiple of 10h is called a
"paragraph" address. "Paragraph" or "segment" addresses are stored as 4 hexadecimal digits and
represent a physical byte address which is 10h times larger than their value.
For example, a segment that starts at segment address 1B37h, actually starts at byte address
1B370h.
"Segment" and "offset" addresses which are both 16-bit numbers can therefore be
combined to form a 20-bit (5-hex. digit) address.
For example, a byte located at an offset of 29D4h within a segment at segment address
1B37h, would have an "absolute" or physical address of:
1B37- segment
+ 29D4 offset
------
1DD44h absolute

Memory Models

The following table summarizes the use of models and the number and sizes of physical
segments that are used with each of the models.

Memory Model Size of Code Size of Data


TINY Code + Data < 64KB Code + data < 64KB
SMALL Less than 64KB Less than 64KB
MEDIUM Can be more than 64KB Less than 64 KB
COMPACT Less than 64KB Can be more than 64KB
LARGE Can be more than 64K Can be more than 64KB
HUGE Can be more than 64K Can be more than 64KB

Getting the Address of a Variable


There is LEA (Load Effective Address) instruction and alternative OFFSET operator. Both
OFFSET and LEA can be used to get the offset address of the variable. LEA is more powerful
because it also allows you to get the address of an indexed variables.

BIOS Interrupts
Interrupts can be seen as a number of functions. These functions make the programming much
easier, instead of writing a code to print a character you can simply call the interrupt and it will do
everything for you. There are also interrupt functions that work with disk drive and other hardware.

IMCB H-9, Islamabad____________( Page 6 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

We call such functions software interrupts. Interrupts are also triggered by different hardware,
these are called hardware interrupts. Currently we are interested in software interrupts only.

Arithmetic and Logic Instructions

Most Arithmetic and Logic Instructions affect the processor status register (or Flags)
A flag and can take a value of 1 or 0.
Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For example when you
add bytes 255 + 1 (result is not in range 0...255). When there is no overflow this flag is set to 0.
Zero Flag (ZF) - set to 1 when result is zero. For none zero result this flag is set to 0.
Sign Flag (SF) - set to 1 when result is negative. When result is positive it is set to 0. Actually this
flag take the value of the most significant bit.

Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add
bytes 100 + 50 (result is not in range -128...127).
Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in result, and to 0
when there is odd number of one bits. Even if result is a word only 8 low bits are analyzed!
Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low nibble (4 bits)

Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts from external
devices.
Direction Flag (DF) - this flag is used by some instructions to process data chains, when this
flag is set to
0 - the processing is done forward, when this flag is set to
1 the processing is done backward.

Complete 8086 instruction set


Operand types:
REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.
SREG: DS, ES, SS, and only as second operand: CS.
memory: [BX], [BX+SI+7], variable, etc
immediate: 5, -24, 3Fh, 10001101b, etc.

 Notes:
When two operands are required for an instruction they are separated by
comma. For example: REG, memory
 When there are two operands, both operands must have the same size
(except shift and rotate instructions). For example: MOV AL, DL
MOV DX, AX
m1 DB ?

IMCB H-9, Islamabad____________( Page 7 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

MOV AL, m1
m2 DW ?
MOV AX, m2
 Some instructions allow several operand combinations. For example:
memory, immediate
REG, immediate
memory, REG
REG, SREG
 These marks are used to show the state of the flags:
1 - instruction sets this flag to 1.
0 - instruction sets this flag to 0.
r - flag value depends on result of the instruction.
? - flag value is undefined (maybe 1 or 0).

IP register always works together with CS segment register and it points to currently executing
instruction.
Flags Register is modified automatically by CPU after mathematical operations, this allows to
determine the type of the result, and to determine conditions to transfer control to other parts of
the program. Generally you cannot access these registers directly

All 8086 Assembly Instructions in alphabetical Order:

IMCB H-9, Islamabad____________( Page 8 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

Instructions in alphabetical order:

Mnemonics Operands Remarks


AAA No operands ASCII Adjust after Addition.
Corrects result in AH and AL after addition when working
with BCD values.
Flags Effected It works according to the following Algorithm:
C Z S O P A if low nibble of AL > 9 or AF = 1 then:
r ? ? ? ? r AL = AL + 6
AH = AH + 1
AF = 1
CF = 1
else
AF = 0
CF = 0
in both cases:
clear the high nibble of AL.
Example:
MOV AX, 15 ; AH = 00, AL = 0Fh
AAA ; AH = 01, AL = 05
AAD No operands ASCII Adjust before Division.
Prepares two BCD values for division.
Algorithm:
Flags Effected AL = (AH * 10) + AL
C Z S O P A AH = 0
? r r ? r ? Example:
MOV AX, 0105h ; AH = 01, AL = 05
AAD ; AH = 00, AL = 0Fh (15)
AAM No operands ASCII Adjust after Multiplication.
Corrects the result of multiplication of two BCD values.
Algorithm:
Flags Effected AH = AL / 10
C Z S O P A AL = remainder
? r r ? r ? Example:
MOV AL, 15 ; AL = 0Fh
AAM ; AH = 01, AL = 05
AAS No operands ASCII Adjust after Subtraction.
Corrects result in AH and AL after subtraction when
working with BCD values.
Flags Effected Algorithm:
C Z S O P A if low nibble of AL > 9 or AF = 1 then:
r ? ? ? ? r AL = AL - 6
AH = AH - 1
AF = 1
CF = 1
else

IMCB H-9, Islamabad____________( Page 9 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

AF = 0
CF = 0
in both cases:
clear the high nibble of AL.
Example:
MOV AX, 02FFh ; AH = 02, AL = 0FFh
AAS ; AH = 01, AL = 09
ADC REG, memory Add with Carry.
memory, REG Algorithm:
REG, REG operand1 = operand1 + operand2 + CF
memory, immediate Example:
REG, immediate STC ; set CF = 1
MOV AL, 5 ; AL = 5
Flags Effected ADC AL, 1 ; AL = 7
C Z S O P A
r r r r r r
ADD REG, memory Add.
memory, REG Algorithm:
REG, REG operand1 = operand1 + operand2
memory, immediate Example:
REG, immediate MOV AL, 5 ; AL = 5
ADD AL, -3 ; AL = 2
Flags Effected
C Z S O P A
r r r r r r
AND REG, memory Logical AND between all bits of two operands. Result is
memory, REG stored in operand1.
REG, REG These rules apply:
memory, immediate 1 AND 1 = 1
REG, immediate 1 AND 0 = 0
0 AND 1 = 0
Flags Effected 0 AND 0 = 0
C Z S O P A Example:
0 r r 0 r MOV AL, 'a' ; AL = 01100001b
AND AL, 11011111b ; AL = 01000001b ('A')
CALL procedure name Transfers control to procedure, return address is (IP) is
label pushed to stack. 4-byte address may be entered in this form:
4-byte address 1234h:5678h, first value is a segment second value is an
offset (this is a far call, so CS is also pushed to stack).
Example:
ORG 100h ; for COM file.
CALL p1
ADD AX, 1
; return to OS.

IMCB H-9, Islamabad____________( Page 10 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

p1 PROC ; procedure declaration.


MOV AX, 1234h
; return to caller.
p1 ENDP
CBW No operands Convert byte into word.
Algorithm:
if high bit of AL = 1 then:
AH = 255 (0FFh)
else
AH = 0
Example:
MOV AX, 0 ; AH = 0, AL = 0
MOV AL, -5 ; AX = 000FBh (251)
CBW ; AX = 0FFFBh (-5)
CLC No operands Clear Carry flag.
Algorithm:
CF = 0
CLD No operands Clear Direction flag. SI and DI will be incremented by
chain instructions: CMPSB, CMPSW, LODSB, LODSW,
MOVSB, MOVSW, STOSB, STOSW.
Algorithm:
DF = 0
CLI No operands Clear Interrupt enable flag. This disables hardware
interrupts.
Algorithm:
IF = 0
CMC No operands Complement Carry flag. Inverts value of CF.
Algorithm:
if CF = 1 then CF = 0
if CF = 0 then CF = 1
CMP No operands Compare.
Algorithm:
operand1 - operand2
Flags Effected result is not stored anywhere, flags are set (OF, SF, ZF, AF,
C Z S O P A PF, CF) according to result.
r r r r r r Example:
MOV AL, 5
MOV BL, 5
CMP AL, BL ; AL = 5, ZF = 1 (so equal!)
CMPSB No operands Compare bytes: ES:[DI] from DS:[SI].
Algorithm:
DS:[SI] - ES:[DI]
Flags Effected set flags according to result:
C Z S O P A OF, SF, ZF, AF, PF, CF
r r r r r r if DF = 0 then
SI = SI + 1

IMCB H-9, Islamabad____________( Page 11 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

DI = DI + 1
else
SI = SI - 1
DI = DI - 1
CMPSW No operands Compare words: ES:[DI] from DS:[SI].
Algorithm:
DS:[SI] - ES:[DI]
Flags Effected set flags according to result:
C Z S O P A OF, SF, ZF, AF, PF, CF
r r r r r r if DF = 0 then
SI = SI + 2
DI = DI + 2
else
SI = SI - 2
DI = DI - 2
CWD No operands Convert Word to Double word.
Algorithm:
if high bit of AX = 1 then:
Flags Effected DX = 65535 (0FFFFh)
C Z S O P A else
No Change DX = 0
Example:
MOV DX, 0 ; DX = 0
MOV AX, 0 ; AX = 0
MOV AX, -5 ; DX AX = 00000h:0FFFBh
CWD ; DX AX = 0FFFFh:0FFFBh
DAA No operands Decimal adjust After Addition.
Corrects the result of addition of two packed BCD values.
Algorithm:
Flags Effected if low nibble of AL > 9 or AF = 1 then:
C Z S O P A AL = AL + 6
r r r r r r AF = 1
if AL > 9Fh or CF = 1 then:
AL = AL + 60h
CF = 1
Example:
MOV AL, 0Fh ; AL = 0Fh (15)
DAA ; AL = 15h
DAS No operands Decimal adjust After Subtraction.
Corrects the result of subtraction of two packed BCD
values.
Flags Effected Algorithm:
C Z S O P A if low nibble of AL > 9 or AF = 1 then:
r r r r r r AL = AL - 6
AF = 1
if AL > 9Fh or CF = 1 then:

IMCB H-9, Islamabad____________( Page 12 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

AL = AL - 60h
CF = 1
Example:
MOV AL, 0FFh ; AL = 0FFh (-1)
DAS ; AL = 99h, CF = 1
DEC REG Decrement.
memory Algorithm:
operand = operand - 1
Flags Effected Example:
C Z S O P A MOV AL, 255 ; AL = 0FFh (255 or -1)
r r r r r r DEC AL ; AL = 0FEh (254 or -2)
DIV REG Unsigned divide.
memory Algorithm:
when operand is a byte:
Flags Effected AL = AX / operand
C Z S O P A AH = remainder (modulus)
? ? ? ? ? ? when operand is a word:
AX = (DX AX) / operand
DX = remainder (modulus)
Example:
MOV AX, 203 ; AX = 00CBh
MOV BL, 4
DIV BL ; AL = 50 (32h), AH = 3
HLT No operands Halt the System.
Example:
MOV AX, 5
HLT
IDIV REG Signed divide.
memory Algorithm:
when operand is a byte:
Flags Effected AL = AX / operand
C Z S O P A AH = remainder (modulus)
? ? ? ? ? ? when operand is a word:
AX = (DX AX) / operand
DX = remainder (modulus)
Example:
MOV AX, -203 ; AX = 0FF35h
MOV BL, 4
IDIV BL ; AL = -50 (0CEh), AH = -3 (0FDh)
IMUL REG Signed multiply.
memory Algorithm:
when operand is a byte:
CF=OF=0 when result fits AX = AL * operand.
into operand of IMUL when operand is a word:
Flags Effected (DX AX) = AX * operand.
Example:

IMCB H-9, Islamabad____________( Page 13 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

C Z S O P A MOV AL, -2
r ? ? r ? ? MOV BL, -4
IMUL BL ; AX = 8
IN AL, im.byte Input from port into AL or AX.
AL, DX Second operand is a port number. If required to access port
AX, im.byte number over 255 - DX register should be used.
AX, DX Example:
IN AX, 4 ; get status of device from port 4.
IN AL, 7 ; get status of device from port 7.
INC No operands Increment.
Algorithm:
operand = operand + 1
Flags Effected Example:
C Z S O P A MOV AL, 4
r r r r r r INC AL ; AL = 5

CS UNCHANGED
INT immediate byte Interrupt numbered by immediate byte (0..255).
FI ? Algorithm:
Flags Effected Push to stack:
C Z S O P I m flags register
0 m CS
m IP
IF = 0
Transfer control to interrupt procedure
Example:
MOV AH, 2h ; teletype.
MOV AL, 'A'
INT 21h ; BIOS interrupt.
INTO No operands Interrupt 4 if Overflow flag is 1.
Algorithm:
if OF = 1 then INT 4
Example:
; -5 - 127 = -132 (not in -128..127)
; the result of SUB is wrong (124),
; so OF = 1 is set:
MOV AL, -5
SUB AL, 127 ; AL = 7 Ch (124)
INTO ; process error.
IRET No operands Interrupt Return.
Algorithm:
Pop from stack:
m IP
m CS
m flags register

IMCB H-9, Islamabad____________( Page 14 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

JA Label Short Jump if first operand is Above second operand (as set
by CMP instruction). Unsigned.
Algorithm:
Flags Effected if (CF = 0) and (ZF = 0) then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 250
CMP AL, 5
JA label1
;Suitable action/message
JMP exit
label1:
;Suitable action/message
exit:
;code here to exit
JAE Label Short Jump if first operand is Above or Equal to second
operand (as set by CMP instruction). Unsigned.
Algorithm:
Flags Effected if CF = 0 then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 5
CMP AL, 5
JAE label1
;Suitable action/message
JMP exit
label1:
;Suitable action/message
exit:
;code here to exit
JB Label Short Jump if first operand is Below second operand (as set
by CMP instruction). Unsigned.
Algorithm:
Flags Effected if CF = 1 then jump
C Z S O P A Example:

NO CHANGE ORG 100h


MOV AL, 1
CMP AL, 5
JB label1
;SUITABLE ACTION/MESSAGE
JMP exit
label1:
;SUITABLE ACTION/MESSAGE
exit:
;code here to exit

IMCB H-9, Islamabad____________( Page 15 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

JBE Label Short Jump if first operand is Below or Equal to second


operand (as set by CMP instruction). Unsigned.
Algorithm:
Flags Effected if CF = 1 or ZF = 1 then jump
C Z S O P A Example:

NO CHANGE ORG 100h


MOV AL, 5
CMP AL, 5
JBE label1
;SUITABLE ACTION/MESSAGE
JMP exit
label1:
;SUITABLE ACTION/MESSAGE
exit:
;code here to exit
JC Label Short Jump if Carry flag is set to 1.
Algorithm:
if CF = 1 then jump
Flags Effected Example:
C Z S O P A
ORG 100h
NO CHANGE MOV AL, 255
ADD AL, 1
JC label1
;SUITABLE ACTION/MESSAGE 'no carry.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'has carry.'
exit:
;code here to exit
JCXZ Label Short Jump if CX register is 0.
Algorithm:
if CX = 0 then jump
Flags Effected Example:
C Z S O P A
ORG 100h
NO CHANGE MOV CX, 0
JCXZ label1
;SUITABLE ACTION/MESSAGE 'CX is not zero.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'CX is zero.'
exit:
;code here to exit

IMCB H-9, Islamabad____________( Page 16 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

JE Label Short Jump if first operand is Equal to second operand (as


set by CMP instruction). Signed/Unsigned.
Algorithm:
Flags Effected if ZF = 1 then jump
C Z S O P A Example:

NO CHANGE ORG 100h


MOV AL, 5
CMP AL, 5
JE label1
;SUITABLE ACTION/MESSAGE 'AL is not equal to 5.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'AL is equal to 5.'
exit:
;code here to exit
JG Label Short Jump if first operand is Greater then second operand
(as set by CMP instruction). Signed.
Algorithm:
Flags Effected if (ZF = 0) and (SF = OF) then jump
C Z S O P A Example:

NO CHANGE ORG 100h


MOV AL, 5
CMP AL, -5
JG label1
;SUITABLE ACTION/MESSAGE 'AL is not greater -5.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'AL is greater -5.'
exit:
;code here to exit
JGE Label Short Jump if first operand is Greater or Equal to second
operand (as set by CMP instruction). Signed.
Algorithm:
Flags Effected if SF = OF then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 2
CMP AL, -5
JGE label1
;SUITABLE ACTION/MESSAGE 'AL < -5'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'AL >= -5'

IMCB H-9, Islamabad____________( Page 17 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

exit:

JL Label Short Jump if first operand is Less then second operand (as
set by CMP instruction). Signed.
Algorithm:
Flags Effected if SF <> OF then jump
C Z S O P A Example
ORG 100h
NO CHANGE MOV AL, -2
CMP AL, 5
JL label1
;SUITABLE ACTION/MESSAGE 'AL >= 5.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'AL < 5.'
exit:
;code here to exit
JLE Label Short Jump if first operand is Less or Equal to second
operand (as set by CMP instruction). Signed.
Algorithm:
Flags Effected if SF <> OF or ZF = 1 then jump
C Z S O P A Example:
[ORG 100h]
NO CHANGE MOV AL, -2
CMP AL, 5
JLE label1
;SUITABLE ACTION/MESSAGE 'AL > 5.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'AL <= 5.'
exit:
;code here to exit
JMP Label Unconditional Jump. Transfers control to another part of the
4-byte address program. 4-byte address may be entered in this form:
1234h:5678h, first value is a segment second value is an
offset.
Flags Effected Algorithm:
C Z S O P A always jump
Example:
NO CHANGE ORG 100h
MOV AL, 5
JMP label1 ; jump over 2 lines!
;SUITABLE ACTION/MESSAGE 'Not Jumped!'
MOV AL, 0
label1:

IMCB H-9, Islamabad____________( Page 18 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

;SUITABLE ACTION/MESSAGE 'Got Here!'

JNA Label Short Jump if first operand is Not Above second operand
(as set by CMP instruction). Unsigned.
Algorithm:
Flags Effected if CF = 1 or ZF = 1 then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 2
CMP AL, 5
JNA label1
;SUITABLE ACTION/MESSAGE 'AL is above 5.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'AL is not above 5.'
exit:
;code here to exit
JNAE Label Short Jump if first operand is Not Above and Not Equal to
second operand (as set by CMP instruction). Unsigned.
Algorithm:
Flags Effected if CF = 1 then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 2
CMP AL, 5
JNAE label1
;SUITABLE ACTION/MESSAGE 'AL >= 5.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'AL < 5.'
exit:
;code here to exit
JNB Label Short Jump if first operand is Not Below second operand (as
set by CMP instruction). Unsigned.
Algorithm:
Flags Effected if CF = 0 then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 7
CMP AL, 5
JNB label1
;SUITABLE ACTION/MESSAGE 'AL < 5.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'AL >= 5.'

IMCB H-9, Islamabad____________( Page 19 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

exit:
;code here to exit
JNBE Label Short Jump if first operand is Not Below and Not Equal to
second operand (as set by CMP instruction). Unsigned.
Algorithm:
Flags Effected if (CF = 0) and (ZF = 0) then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 7
CMP AL, 5
JNBE label1
;SUITABLE ACTION/MESSAGE 'AL <= 5.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'AL > 5.'
exit:
;code here to exit
JNC Label Short Jump if Carry flag is set to 0.
Algorithm:
if CF = 0 then jump
Flags Effected Example:
C Z S O P A ORG 100h
MOV AL, 2
NO CHANGE ADD AL, 3
JNC label1
;SUITABLE ACTION/MESSAGE 'has carry.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'no carry.'
exit:
;code here to exit
JNE Label Short Jump if first operand is Not Equal to second operand
(as set by CMP instruction). Signed/Unsigned.
Algorithm:
Flags Effected if ZF = 0 then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 2
CMP AL, 3
JNE label1
;SUITABLE ACTION/MESSAGE 'AL = 3.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'Al <> 3.'
exit:
;code here to exit

IMCB H-9, Islamabad____________( Page 20 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

JNG Label Short Jump if first operand is Not Greater then second
operand (as set by CMP instruction). Signed.
Algorithm:
Flags Effected if (ZF = 1) and (SF <> OF) then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 2
CMP AL, 3
JNG label1
;SUITABLE ACTION/MESSAGE 'AL > 3.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'Al <= 3.'
exit:
;code here to exit
JNGE Label Short Jump if first operand is Not Greater and Not Equal to
second operand (as set by CMP instruction). Signed.
Algorithm:
Flags Effected if SF <> OF then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 2
CMP AL, 3
JNGE label1
;SUITABLE ACTION/MESSAGE 'AL >= 3.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'Al < 3.'
exit:
;code here to exit
JNL Label Short Jump if first operand is Not Less then second operand
(as set by CMP instruction). Signed.
Algorithm:
Flags Effected if SF = OF then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 2
CMP AL, -3
JNL label1
;SUITABLE ACTION/MESSAGE 'AL < -3.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'Al >= -3.'
exit:
;code here to exit

IMCB H-9, Islamabad____________( Page 21 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

JNLE Label Short Jump if first operand is Not Less and Not Equal to
second operand (as set by CMP instruction). Signed.
Algorithm:
Flags Effected if (SF = OF) and (ZF = 0) then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 2
CMP AL, -3
JNLE label1
;SUITABLE ACTION/MESSAGE 'AL <= -3.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'Al > -3.'
exit:
;code here to exit
JNO Label Short Jump if Not Overflow.
Algorithm:
if OF = 0 then jump
Flags Effected Example:
C Z S O P A ; -5 - 2 = -7 (inside -128..127)
; the result of SUB is correct,
NO CHANGE ; so OF = 0:
ORG 100h
MOV AL, -5
SUB AL, 2 ; AL = 0F9h (-7)
JNO label1
;SUITABLE ACTION/MESSAGE 'overflow!'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'no overflow.'
exit:
;code here to exit
JNP Label Short Jump if No Parity (odd). Only 8 low bits of result are
checked. Set by CMP, SUB, ADD, TEST, AND, OR, XOR
instructions.
Flags Effected Algorithm:
C Z S O P A if PF = 0 then jump
Example:
NO CHANGE ORG 100h
MOV AL, 00000111b ; AL = 7
OR AL, 0 ; just set flags.
JNP label1
;SUITABLE ACTION/MESSAGE 'parity even.'
JMP exit
label1:

IMCB H-9, Islamabad____________( Page 22 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

;SUITABLE ACTION/MESSAGE 'parity odd.'


exit:
;code here to exit
JNS Label Short Jump if Not Signed (if positive). Set by CMP, SUB,
ADD, TEST, AND, OR, XOR instructions.
Algorithm:
Flags Effected if SF = 0 then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 00000111b ; AL = 7
OR AL, 0 ; just set flags.
JNS label1
;SUITABLE ACTION/MESSAGE 'signed.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'not signed.'
exit:
;code here to exit
JNZ Label Short Jump if Not Zero (not equal). Set by CMP, SUB,
ADD, TEST, AND, OR, XOR instructions.
Algorithm:
Flags Effected if ZF = 0 then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 00000111b ; AL = 7
OR AL, 0 ; just set flags.
JNZ label1
;SUITABLE ACTION/MESSAGE 'zero.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'not zero.'
exit:
;code here to exit
JO Label Short Jump if Overflow.
Algorithm:
if OF = 1 then jump
Flags Effected Example:
C Z S O P A ; -5 - 127 = -132 (not in -128..127)
; the result of SUB is wrong (124),
NO CHANGE ; so OF = 1 is set:
[org 100h]
MOV AL, -5
SUB AL, 127 ; AL = 7Ch (124)
JO label1
;SUITABLE ACTION/MESSAGE 'no overflow.'
JMP exit

IMCB H-9, Islamabad____________( Page 23 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

label1:
;SUITABLE ACTION/MESSAGE 'overflow!'
exit:
;code here to exit
JP Label Short Jump if Parity (even). Only 8 low bits of result are
checked. Set by CMP, SUB, ADD, TEST, AND, OR, XOR
instructions.
Flags Effected Algorithm:
C Z S O P A if PF = 1 then jump
Example:
NO CHANGE ORG 100h
MOV AL, 00000101b ; AL = 5
OR AL, 0 ; just set flags.
JP label1
;SUITABLE ACTION/MESSAGE 'parity odd.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'parity even.'
exit:
;code here to exit
JPE Label Short Jump if Parity Even. Only 8 low bits of result are
checked. Set by CMP, SUB, ADD, TEST, AND, OR, XOR
instructions.
Flags Effected Algorithm:
C Z S O P A if PF = 1 then jump
Example:
NO CHANGE ORG 100h
MOV AL, 00000101b ; AL = 5
OR AL, 0 ; just set flags.
JPE label1
;SUITABLE ACTION/MESSAGE 'parity odd.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'parity even.'
exit:
;code here to exit
JPO Label Short Jump if Parity Odd. Only 8 low bits of result are
checked. Set by CMP, SUB, ADD, TEST, AND, OR, XOR
instructions.
Flags Effected Algorithm:
C Z S O P A if PF = 0 then jump
Example:
NO CHANGE ORG 100h
MOV AL, 00000111b ; AL = 7
OR AL, 0 ; just set flags.
JPO label1

IMCB H-9, Islamabad____________( Page 24 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

;SUITABLE ACTION/MESSAGE 'parity even.'


JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'parity odd.'
exit:
;code here to exit
JS Label Short Jump if Signed (if negative). Set by CMP, SUB,
ADD, TEST, AND, OR, XOR instructions.
Algorithm:
Flags Effected if SF = 1 then jump
C Z S O P A Example:
ORG 100h
NO CHANGE MOV AL, 10000000b ; AL = -128
OR AL, 0 ; just set flags.
JS label1
;SUITABLE ACTION/MESSAGE 'not signed.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'signed.'
exit:
;code here to exit
JZ Label Short Jump if Zero (equal). Set by CMP, SUB, ADD,
TEST, AND, OR, XOR instructions.
Algorithm:
Flags Effected if ZF = 1 then jump
C Z S O P A Example:
[ORG 100h]
NO CHANGE MOV AL, 5
CMP AL, 5
JZ label1
;SUITABLE ACTION/MESSAGE 'AL is not equal to 5.'
JMP exit
label1:
;SUITABLE ACTION/MESSAGE 'AL is equal to 5.'
exit:
;code here to exit
LAHF Label Load AH from 8 low bits of Flags register.
Algorithm:
AH = flags register
Flags Effected AH bit: 7 6 5 4 3 2 1 0
C Z S O P A [SF] [ZF] [0] [AF] [0] [PF] [1] [CF]
bits 1, 3, 5 are reserved
NO CHANGE
LDS REG, memory Load memory double word into word register and DS.
Algorithm:
Flags Effected REG = first word

IMCB H-9, Islamabad____________( Page 25 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

C Z S O P A DS = second word
Example:
NO CHANGE ORG 100h
LDS AX, m
m DW 1234h
DW 5678h
AX is set to 1234h, DS is set to 5678h.
LEA REG, memory Load Effective Address.
Algorithm:
Flags Effected REG = address of memory (offset)
C Z S O P A Generally this instruction is replaced by MOV when
assembling when possible.
NO CHANGE Example:
ORG 100h
LEA AX, m
m DW 1234h
AX is set to: 0104h.
LEA instruction takes 3 bytes, takes 1 byte, we start at 100h,
so the address of 'm' is 104h.
LES REG, memory Load memory double word into word register and ES.
Algorithm:
REG = first word
Flags Effected ES = second word
C Z S O P A Example:
ORG 100h
NO CHANGE LES AX, m
m DW 1234h
DW 5678h
AX is set to 1234h, ES is set to 5678h.
LODSB Label Load byte at DS:[SI] into AL. Update SI.
Algorithm:
AL = DS:[SI]
Flags Effected if DF = 0 then
C Z S O P A SI = SI + 1
else
NO CHANGE SI = SI - 1
Example:
ORG 100h
LEA SI, a1
MOV CX, 5
MOV AH, 0Eh
m: LODSB
INT 10h
LOOP m
a1 DB 'H', 'e', 'l', 'l', 'o'

IMCB H-9, Islamabad____________( Page 26 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

LODSW Label Load word at DS:[SI] into AX. Update SI.


Algorithm:
AX = DS:[SI]
Flags Effected if DF = 0 then
C Z S O P A SI = SI + 2
else
NO CHANGE SI = SI - 2
Example:
[ORG 100h]
LEA SI, a1
MOV CX, 5
REP LODSW ; finally there will be 555h in AX.
MOV AX, 4c00
INT 21H
a1 dw 111h, 222h, 333h, 444h, 555h
LOOP Label Decrease CX, jump to label if CX not zero.
Algorithm:
CX = CX - 1
Flags Effected if CX <> 0 then
C Z S O P A jump
else
NO CHANGE no jump, continue
Example:
ORG 100h
MOV CX, 5
label1:
;SUITABLE ACTION/MESSAGE N 'loop!'
LOOP label1

LOOPE Label Decrease CX, jump to label if CX not zero and Equal (ZF =1).
Algorithm:
CX = CX - 1
Flags Effected if (CX <> 0) and (ZF = 1) then
C Z S O P A m jump
else
NO CHANGE m no jump, continue
Example:
; Loop until result fits into AL alone,
; or 5 times. The result will be over 255
; on third loop (100+100+100),
; so loop will exit.
ORG 100h
MOV AX, 0
MOV CX, 5
label1:
PUTC '*'

IMCB H-9, Islamabad____________( Page 27 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

ADD AX, 100


CMP AH, 0
LOOPE label1

LOOPNE Label Decrease CX, jump to label if CX not zero and Not Equal
(ZF = 0).
Algorithm:
Flags Effected CX = CX - 1
C Z S O P A if (CX <> 0) and (ZF = 0) then
m jump
NO CHANGE else
m no jump, continue
Example:
; Loop until '7' is found,
; or 5 times.

ORG 100h
MOV SI, 0
MOV CX, 5
label1:
PUTC '*'
MOV AL, v1[SI]
INC SI ; next byte (SI=SI+1).
CMP AL, 7
LOOPNE label1

v1 db 9, 8, 7, 6, 5
LOOPNZ Label Decrease CX, jump to label if CX not zero and ZF = 0.
Algorithm:
CX = CX - 1
Flags Effected if (CX <> 0) and (ZF = 0) then
C Z S O P A m jump
else
NO CHANGE m no jump, continue
Example:
; Loop until '7' is found,
; or 5 times.
ORG 100h
MOV SI, 0
MOV CX, 5
label1:
PUTC '*'
MOV AL, v1[SI]
INC SI ; next byte (SI=SI+1).
CMP AL, 7

IMCB H-9, Islamabad____________( Page 28 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

LOOPNZ label1
v1 db 9, 8, 7, 6, 5
LOOPZ Label Decrease CX, jump to label if CX not zero and ZF = 1.
Algorithm:
CX = CX - 1
Flags Effected if (CX <> 0) and (ZF = 1) then
C Z S O P A m jump
else
NO CHANGE m no jump, continue
Example:
; Loop until result fits into AL alone,
; or 5 times. The result will be over 255
; on third loop (100+100+100),
; so loop will exit.

ORG 100h
MOV AX, 0
MOV CX, 5
label1:
PUTC '*'
ADD AX, 100
CMP AH, 0
LOOPZ label1

MOV REG, memory Copy operand2 to operand1.


memory, REG The MOV instruction cannot:
REG, REG set the value of the CS and IP registers.
memory, immediate copy value of one segment register to another
REG, immediate segment register (should copy to general register
SREG, memory first).
memory, SREG copy immediate value to segment register (should
REG, SREG copy to general register first).
SREG, REG Algorithm:
operand1 = operand2
Flags Effected Example:
C Z S O P A
ORG 100h
NO CHANGE MOV AX, 0B800h ; set AX = B800h (VGA memory).
MOV DS, AX ; copy value of AX to DS.
MOV CL, 'A' ; CL = 41h (ASCII code).
MOV CH, 01011111b ; CL = color attribute.
MOV BX, 15Eh ; BX = position on screen.
MOV [BX], CX ; w.[0B800h:015Eh] = CX.
; returns to operating system.
MOVSB No operands Copy byte at DS:[SI] to ES:[DI]. Update SI and DI.
Algorithm:

IMCB H-9, Islamabad____________( Page 29 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

Flags Effected ES:[DI] = DS:[SI]


C Z S O P A if DF = 0 then
SI = SI + 1
NO CHANGE DI = DI + 1
else
SI = SI - 1
DI = DI - 1
Example:
ORG 100h
LEA SI, a1
LEA DI, a2
MOV CX, 5
REP MOVSB
a1 DB 1,2,3,4,5
a2 DB 5 DUP(0)
MOVSW Label Copy word at DS:[SI] to ES:[DI]. Update SI and DI.
Algorithm:
ES:[DI] = DS:[SI]
Flags Effected if DF = 0 then
C Z S O P A SI = SI + 2
DI = DI + 2
NO CHANGE else
SI = SI - 2
DI = DI - 2
Example:
ORG 100h
LEA SI, a1
LEA DI, a2
MOV CX, 5
REP MOVSW
a1 DW 1,2,3,4,5
a2 DW 5 DUP(0)
MUL Label Unsigned multiply.
Algorithm:
when operand is a byte:
Flags Effected AX = AL * operand.
C Z S O P A when operand is a word:
r ? ? r ? ? (DX AX) = AX * operand.
CF=OF=0 when high section Example:
of the result is zero MOV AL, 200 ; AL = 0C8h
MOV BL, 4
MUL BL ; AX = 0320h (800)

NEG REG Negate. Makes operand negative (two's complement).


memory Algorithm:
Invert all bits of the operand

IMCB H-9, Islamabad____________( Page 30 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

Flags Effected Add 1 to inverted operand


C Z S O P A Example:
r r r r r r MOV AL, 5 ; AL = 05h
NO CHANGE NEG AL ; AL = 0FBh (-5)
NEG AL ; AL = 05h (5)
NOP REG No Operation.
memory Algorithm:
Do nothing
Flags Effected Example:
C Z S O P A ; do nothing, 3 times:
NOP
NO CHANGE NOP
NOP
NOT Label Invert each bit of the operand.
Algorithm:
if bit is 1 turn it to 0.
Flags Effected if bit is 0 turn it to 1.
C Z S O P A Example:
MOV AL, 00011011b
NO CHANGE NOT AL ; AL = 11100100b
OR REG, memory Logical OR between all bits of two operands. Result is
memory, REG stored in first operand.
REG, REG These rules apply:
memory, immediate 1 OR 1 = 1
REG, immediate 1 OR 0 = 1
0 OR 1 = 1
Flags Effected 0 OR 0 = 0
C Z S O P A Example:
0 r r 0 r ? MOV AL, 'A' ; AL = 01000001b
NO CHANGE OR AL, 00100000b ; AL = 01100001b ('a')
OUT im.byte, AL Output from AL or AX to port.
im.byte, AX First operand is a port number. If required to access port
DX, AL number over 255 - DX register should be used.
DX, AX Example:
MOV AX, 0FFFh ; Turn on all
Flags Effected OUT 4, AX ; traffic lights.
C Z S O P A MOV AL, 100b ; Turn on the third
OUT 7, AL ; magnet of the stepper-motor.
NO CHANGE
POP REG Get 16 bit value from the stack.
SREG Algorithm:
memory operand = SS:[SP] (top of the stack)
SP = SP + 2
Flags Effected Example:
C Z S O P A MOV AX, 1234h

IMCB H-9, Islamabad____________( Page 31 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

PUSH AX
NO CHANGE POP DX ; DX = 1234h
POPA Label Pop all general purpose registers DI, SI, BP, SP, BX, DX,
CX, AX from the stack.
SP value is ignored, it is Popped but not set to SP register).
Flags Effected Note: this instruction works only on 80186 CPU and later!
C Z S O P A Algorithm:
POP DI
NO CHANGE POP SI
POP BP
POP xx (SP value ignored)
POP BX
POP DX
POP CX
POP AX
POPF Label Get flags register from the stack.
Algorithm:
flags = SS:[SP] (top of the stack)
Flags Effected SP = SP + 2
C Z S O P A

NO CHANGE
PUSH REG Store 16 bit value in the stack.
SREG Note: PUSH immediate works only on 80186 CPU and
memory later!
immediate Algorithm:
SP = SP - 2
Flags Effected SS:[SP] (top of the stack) = operand
C Z S O P A Example:
MOV AX, 1234h
NO CHANGE PUSH AX
POP DX ; DX = 1234h
PUSHA Label Push all general purpose registers AX, CX, DX, BX, SP,
BP, SI, DI in the stack.
Original value of SP register (before PUSHA) is used.
Flags Effected Note: this instruction works only on 80186 CPU and later!
C Z S O P A Algorithm:
PUSH AX
NO CHANGE PUSH CX
PUSH DX
PUSH BX
PUSH SP
PUSH BP
PUSH SI
PUSH DI

IMCB H-9, Islamabad____________( Page 32 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

PUSHF Label Store flags register in the stack.


Algorithm:
SP = SP - 2
Flags Effected SS:[SP] (top of the stack) = flags
C Z S O P A

NO CHANGE
RCL memory, immediate Rotate operand1 left through Carry Flag. The number of
REG, immediate rotates is set by operand2.
memory, CL When immediate is greater then 1, assembler generates
REG, CL several RCL xx, 1 instructions because 8086 has machine
code only for this instruction (the same principle works for
Flags Effected all other shift/rotate instructions).
C Z S O P A Algorithm:
r r shift all bits left, the bit that goes off is set to CF and
OF=0 if first operand keeps previous value of CF is inserted to the right-most
original sign. position.
Example:
STC ; set carry (CF=1).
MOV AL, 1Ch ; AL = 00011100b
RCL AL, 1 ; AL = 00111001b, CF=0.
RCR memory, immediate Rotate operand1 right through Carry Flag. The number of
REG, immediate rotates is set by operand2.
memory, CL Algorithm:
REG, CL shift all bits right, the bit that goes off is set to CF
and previous value of CF is inserted to the left-most
Flags Effected position.
C Z S O P A Example:
r r STC ; set carry (CF=1).
OF=0 if first operand keeps MOV AL, 1Ch ; AL = 00011100b
original sign. RCR AL, 1 ; AL = 10001110b, CF=0.
REP chain instruction Repeat following MOVSB, MOVSW, LODSB, LODSW,
STOSB, STOSW instructions CX times.
Flags Effected Algorithm:
C Z S O P A check_cx:
r if CX <> 0 then
NO CHANGE do following chain instruction
CX = CX - 1
go back to check_cx
else
exit from REP cycle
REPE chain instruction Repeat following CMPSB, CMPSW, SCASB, SCASW
instructions while ZF = 1 (result is Equal), maximum CX
Flags Effected times.
C Z S O P A Algorithm:

IMCB H-9, Islamabad____________( Page 33 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

r check_cx:
NO CHANGE if CX <> 0 then
do following chain instruction
CX = CX - 1
if ZF = 1 then:
go back to check_cx
else
exit from REPE cycle
else
exit from REPE cycle
REPNE chain instruction Repeat following CMPSB, CMPSW, SCASB, SCASW
instructions while ZF = 0 (result is Not Equal), maximum
Flags Effected CX times.
C Z S O P A Algorithm:
r check_cx:
NO CHANGE if CX <> 0 then
do following chain instruction
CX = CX - 1
if ZF = 0 then:
go back to check_cx
else
exit from REPNE cycle
else
exit from REPNE cycle
REPNZ chain instruction Repeat following CMPSB, CMPSW, SCASB, SCASW
instructions while ZF = 0 (result is Not Zero), maximum
Flags Effected CX times.
C Z S O P A Algorithm:
r check_cx:
NO CHANGE if CX <> 0 then
do following chain instruction
CX = CX - 1
if ZF = 0 then:
go back to check_cx
else
exit from REPNZ cycle
else
exit from REPNZ cycle
REPZ chain instruction Repeat following CMPSB, CMPSW, SCASB, SCASW
instructions while ZF = 1 (result is Zero), maximum CX
Flags Effected times.
C Z S O P A Algorithm:
r check_cx:
NO CHANGE if CX <> 0 then
do following chain instruction
CX = CX - 1

IMCB H-9, Islamabad____________( Page 34 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

if ZF = 1 then:
go back to check_cx
else
exit from REPZ cycle
else
exit from REPZ cycle
RET No operands Return from near procedure.
or even immediate Algorithm:
Pop from stack:
Flags Effected IP
C Z S O P A if immediate operand is present: SP = SP + operand
Example:
NO CHANGE [ORG 100h] ;
CALL p1
ADD AX, 1
; return to OS.
p1 PROC ; procedure declaration.
MOV AX, 1234h
; return to caller.
p1 ENDP
ROL memory, immediate Rotate operand1 left. The number of rotates is set by
REG, immediate operand2.
memory, CL Algorithm:
REG, CL shift all bits left, the bit that goes off is set to CF and
the same bit is inserted to the right-most position.
Flags Effected Example:
C Z S O P A MOV AL, 1Ch ; AL = 00011100b
r r ROL AL, 1 ; AL = 00111000b, CF=0.
OF=0 if first operand keeps
original sign
ROR memory, immediate Rotate operand1 right. The number of rotates is set by
REG, immediate operand2.
memory, CL Algorithm:
REG, CL shift all bits right, the bit that goes off is set to CF
and the same bit is inserted to the left-most position.
Flags Effected Example:
C Z S O P A MOV AL, 1Ch ; AL = 00011100b
r r ROR AL, 1 ; AL = 00001110b, CF=0.
OF=0 if first operand keeps
original sign
SAHF No operands Store AH register into low 8 bits of Flags register.
Algorithm:
Flags Effected flags register = AH
C Z S O P A AH bit: 7 6 5 4 3 2 1 0
r r r r r r

IMCB H-9, Islamabad____________( Page 35 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

NO CHANGE [SF] [ZF] [0] [AF] [0] [PF] [1] [CF]


bits 1, 3, 5 are reserved.
SAL memory, immediate Shift Arithmetic operand1 Left. The number of shifts is set
REG, immediate by operand2.
memory, CL Algorithm:
REG, CL Shift all bits left, the bit that goes off is set to CF.
Zero bit is inserted to the right-most position.
Flags Effected Example:
C Z S O P A MOV AL, 0E0h ; AL = 11100000b
r r SAL AL, 1 ; AL = 11000000b, CF=1.
OF=0 if first operand keeps
original sign.
SAR memory, immediate Shift Arithmetic operand1 Right. The number of shifts is set
REG, immediate by operand2.
memory, CL Algorithm:
REG, CL Shift all bits right, the bit that goes off is set to CF.
The sign bit that is inserted to the left-most position
Flags Effected has the same value as before shift.
C Z S O P A Example:
r r MOV AL, 0E0h ; AL = 11100000b
NO CHANGE SAR AL, 1 ; AL = 11110000b, CF=0.
MOV BL, 4Ch ; BL = 01001100b
SAR BL, 1 ; BL = 00100110b, CF=0.

SBB memory, immediate Subtract with Borrow.


REG, immediate Algorithm:
memory, CL operand1 = operand1 - operand2 - CF
REG, CL Example:
STC
Flags Effected MOV AL, 5
C Z S O P A SBB AL, 3 ; AL = 5 - 3 - 1 = 1
r r r r r r
NO CHANGE
SCASB No operands Compare bytes: AL from ES:[DI].
Algorithm:
Flags Effected ES:[DI] - AL
C Z S O P A set flags according to result:
r r r r r r OF, SF, ZF, AF, PF, CF
NO CHANGE if DF = 0 then
DI = DI + 1
else
DI = DI - 1
SCASW No operands Compare words: AX from ES:[DI].
Algorithm:
Flags Effected ES:[DI] - AX

IMCB H-9, Islamabad____________( Page 36 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

C Z S O P A set flags according to result:


r r r r r r OF, SF, ZF, AF, PF, CF
NO CHANGE if DF = 0 then
DI = DI + 2
else
DI = DI - 2
SHL memory, immediate Shift operand1 Left. The number of shifts is set by
REG, immediate operand2.
memory, CL Algorithm:
REG, CL Shift all bits left, the bit that goes off is set to CF.
Zero bit is inserted to the right-most position.
Flags Effected Example:
C Z S O P A MOV AL, 11100000b
r r SHL AL, 1 ; AL = 11000000b, CF=1.
OF=0 if first operand keeps
original sign
SHR memory, immediate Shift operand1 Right. The number of shifts is set by
REG, immediate operand2.
memory, CL Algorithm:
REG, CL Shift all bits right, the bit that goes off is set to CF.
Zero bit is inserted to the left-most position.
Flags Effected Example:
C Z S O P A MOV AL, 00000111b
r r SHR AL, 1 ; AL = 00000011b, CF=1.
OF=0 if first operand keeps
original sign.
STC No operands Set Carry flag.
Algorithm:
Flags Effected CF = 1
C Z S O P A
1
STD No operands Set Direction flag. SI and DI will be decremented by chain
instructions: CMPSB, CMPSW, LODSB, LODSW,
Flags Effected MOVSB, MOVSW, STOSB, STOSW.
C Z S O P A Algorithm:
1 DF = 1

STI No operands Set Interrupt enable flag. This enables hardware interrupts.
Algorithm:
Flags Effected IF = 1
C Z S O P A

STOSB No operands Store byte in AL into ES:[DI]. Update DI.


Algorithm:
Flags Effected ES:[DI] = AL

IMCB H-9, Islamabad____________( Page 37 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

C Z S O P A if DF = 0 then
r r DI = DI + 1
OF=0 if first operand keeps else
original sign. DI = DI - 1
Example:
REP STOSB
a1 DB 5 dup(0)
STOSW No operands Store word in AX into ES:[DI]. Update DI.
Algorithm:
Flags Effected ES:[DI] = AX
C Z S O P A if DF = 0 then
r r DI = DI + 2
OF=0 if first operand keeps else
original sign. DI = DI - 2
Example:
ORG 100h
LEA DI, a1
MOV AX, 1234h
MOV CX, 5
REP STOSW
a1 DW 5 dup(0)
SUB memory, immediate Subtract.
REG, immediate Algorithm:
memory, CL operand1 = operand1 - operand2
REG, CL Example:
MOV AL, 5
Flags Effected SUB AL, 1 ; AL = 4
C Z S O P A
r r r r r r
TEST memory, immediate Logical AND between all bits of two operands for flags
REG, immediate only. These flags are effected: ZF, SF, PF. Result is not
memory, CL stored anywhere.
REG, CL These rules apply:
1 AND 1 = 1
Flags Effected 1 AND 0 = 0
C Z S O P A 0 AND 1 = 0
0 r r 0 r r 0 AND 0 = 0
NO CHANGE Example:
MOV AL, 00000101b
TEST AL, 1 ; ZF = 0.
TEST AL, 10b ; ZF = 1.
XCHG REG, memory Exchange values of two operands.
memory, REG Algorithm:
REG, REG operand1 < - > operand2
Example:
Flags Effected MOV AL, 5

IMCB H-9, Islamabad____________( Page 38 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

C Z S O P A MOV AH, 2
XCHG AL, AH ; AL = 2, AH = 5
NO CHANGE XCHG AL, AH ; AL = 5, AH = 2
XLATB No operands Translate byte from table.
Copy value of memory byte at DS:[BX + unsigned AL] to
AL register.
Flags Effected Algorithm:
C Z S O P A AL = DS:[BX + unsigned AL]
Example:
NO CHANGE [ORG 100h]
LEA BX, dat
MOV AL, 2
XLATB ; AL = 33h

XOR REG, memory Logical XOR (Exclusive OR) between all bits of two
memory, REG operands. Result is stored in first operand.
REG, REG These rules apply:
memory, immediate 1 XOR 1 = 0
REG, immediate 1 XOR 0 = 1
0 XOR 1 = 1
Flags Effected 0 XOR 0 = 0
C Z S O P A Example:
0 r r 0 r ? MOV AL, 00000111b
NO CHANGE XOR AL, 00000010b ; AL = 00000101b

IMCB H-9, Islamabad____________( Page 39 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

; Program to Print number in AX in Binary.


[ORG 100h] ; this directive required.
MOV AX, 12800 ; set AX to hexadecimal value of B800h.
[ORG 100H]
MOV AL, 5
MOV BL, 10
ADD BL, AL
SUB BL, 1
;PRINTCH - PRINT RESULT IN BINARY:
MOV CX, 8 ; Loop to repeat for CX times

PRINTCH:
MOV AH, 2 ; PRINTCH FUNCTION.
MOV DL, '0'
TEST BL, 10000000B ; TEST LEFTMOST BIT.
JZ ZERO
MOV DL, '1'

ZERO: INT 21H


SHL BL, 1
LOOP PRINTCH

MOV DL, 'B'


INT 21H ; PRINTCH BINARY SUFFIX:
MOV AH, 0
INT 16H ; WAIT FOR ANY KEY PRESS:
RET ; RETURN

Setting various types of Values in Registers

IMCB H-9, Islamabad____________( Page 40 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

; A Program To Add Three Numbers Using Registers


[org 0x0100]
mov ax, 5 ; load first number in ax
mov bx, 10 ; load second number in bx
add ax, bx ; accumulate sum in ax
mov bx, 15 ; load third number in bx
add ax, bx ; accumulate sum in ax
mov ax, 0x4c00 ; terminate program
int 0x21

Remember Little Endian and Big Endian formats. For each of the following words identify the
byte that is stored at lower memory address and the byte that is stored at higher memory
address
in a little endian computer.
a. 1234
b. ABFC
c. B100
d. B800

; A Program To Add Three Numbers Using Memory Variables


[org 0x0100]
mov ax, [num1] ; load first number in ax
mov bx, [num2] ; load second number in bx
add ax, bx ; accumulate sum in ax
mov bx, [num3] ; load third number in bx
add ax, bx ; accumulate sum in ax
mov [num4], ax ; store sum in num4
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data
num1: dw 5
num2: dw 10
num3: dw 15
num4: dw 0

; A Program To Add Three Numbers Accessed Using A Single Label


[org 0x0100]
mov ax, [num1] ; load first number in ax
mov bx, [num1+2] ; load second number in bx
add ax, bx ; accumulate sum in ax

IMCB H-9, Islamabad____________( Page 41 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

mov bx, [num1+4] ; load third number in bx


add ax, bx ; accumulate sum in ax
mov [num1+6], ax ; store sum at num1+6
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data
num1: dw 5
dw 10
dw 15
dw 0

; A PROGRAM TO ADD THREE NUMBERS ACCESSED USING A SINGLE LABEL


[org 0x0100]
mov ax, [num1] ; load first number in ax
mov bx, [num1+2] ; load second number in bx
add ax, bx ; accumulate sum in ax
mov bx, [num1+4] ; load third number in bx
add ax, bx ; accumulate sum in ax
mov [num1+6], ax ; store sum at num1+6
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data
num1: dw 5, 10, 15, 0

; A Program To Add Three Numbers Directly In Memory


[org 0x0100]
mov ax, [num1] ; load first number in ax
mov [num1+6], ax ; store first number in result
mov ax, [num1+2] ; load second number in ax
add [num1+6], ax ; add second number to result
mov ax, [num1+4] ; load third number in ax
add [num1+6], ax ; add third number to result
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data
num1: dw 5, 10, 15, 0

; A Program To Add Three Numbers Using Indirect Addressing


[org 0x100]
mov bx, num1 ; point bx to first number

IMCB H-9, Islamabad____________( Page 42 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

mov ax, [bx] ; load first number in ax


add bx, 2 ; advance bx to second number
add ax, [bx] ; add second number to ax
add bx, 2 ; advance bx to third number
add ax, [bx] ; add third number to ax
add bx, 2 ; advance bx to result
mov [bx], ax ; store sum at num1+6
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data
num1: dw 5, 10, 15, 0

; A Program To Add Ten Numbers


[org 0x0100]
mov bx, num1 ; point bx to first number
mov cx, 10 ; load count of numbers in cx
mov ax, 0 ; initialize sum to zero
l1: add ax, [bx] ; add number to ax
add bx, 2 ; advance bx to next number
sub cx, 1 ; numbers to be added reduced
jnz l1 ; if numbers remain add next
mov [total], ax ; write back sum in memory
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data
num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50
total: dw 0

; A Program To Add Ten Numbers Using Register + Offset Addressing


[org 0x0100]
mov bx, 0 ; initialize array index to zero
mov cx, 10 ; load count of numbers in cx
mov ax, 0 ; initialize sum to zero
l1: add ax, [num1+bx] ; add number to ax
add bx, 2 ; advance bx to next index
sub cx, 1 ; numbers to be added reduced
jnz l1 ; if numbers remain add next
mov [total], ax ; write back sum in memory
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data
num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50
total: dw 0

IMCB H-9, Islamabad____________( Page 43 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

; Conditional Jump - A Program To Add Ten Numbers Without A Separate Counter


[org 0x0100]
mov bx, 0 ; initialize array index to zero
mov ax, 0 ; initialize sum to zero
l1: add ax, [num1+bx] ; add number to ax
add bx, 2 ; advance bx to next index
cmp bx, 20 ; are we beyond the last index
jne l1 ; if not add next number
mov [total], ax ; write back sum in memory
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data
num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50
total: dw 0

; Conditional Jump - A Program To Add Ten Numbers Without A Separate Counter


[org 0x0100]
jmp start ; unconditionally jump over data
start: mov bx, 0 ; initialize array index to zero
mov ax, 0 ; initialize sum to zero
l1: add ax, [num1+bx] ; add number to ax
add bx, 2 ; advance bx to next index
cmp bx, 20 ; are we beyond the last index
jne l1 ; if not add next number
mov [total], ax ; write back sum in memory
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data

num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50
total: dw 0

; bubble sort subroutine using a local variable


[org 0x0100]
jmp start
data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0
data2: dw 328, 329, 898, 8923, 8293, 2345, 10, 877, 355, 98
dw 888, 533, 2000, 1020, 30, 200, 761, 167, 90, 5
bubblesort: push bp ; save old value of bp
mov bp, sp ; make bp our reference point
sub sp, 2 ; make two byte space on stack
push ax ; save old value of ax

IMCB H-9, Islamabad____________( Page 44 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

push bx ; save old value of bx


push cx ; save old value of cx
push si ; save old value of si
mov bx, [bp+6] ; load start of array in bx
mov cx, [bp+4] ; load count of elements in cx
dec cx ; last element not compared
shl cx, 1 ; turn into byte count
mainloop: mov si, 0 ; initialize array index to zero
mov word [bp-2], 0 ; reset swap flag to no swaps
innerloop: mov ax, [bx+si] ; load number in ax
cmp ax, [bx+si+2] ; compare with next number
jbe noswap ; no swap if already in order
xchg ax, [bx+si+2] ; exchange ax with second number
mov [bx+si], ax ; store second number in first
mov word [bp-2], 1 ; flag that a swap has been done
noswap: add si, 2 ; advance si to next index
cmp si, cx ; are we at last index
jne innerloop ; if not compare next two
cmp word [bp-2], 1 ; check if a swap has been done
je mainloop ; if yes make another pass
pop si ; restore old value of si
pop cx ; restore old value of cx
pop bx ; restore old value of bx
pop ax ; restore old value of ax
mov sp, bp ; remove space created on stack
pop bp ; restore old value of bp
ret 4 ; go back and remove two params
start: mov ax, data
push ax ; place start of array on stack
mov ax, 10
push ax ; place element count on stack
call bubblesort ; call our subroutine
mov ax, data2
push ax ; place start of array on stack
mov ax, 20
push ax ; place element count on stack
call bubblesort ; call our subroutine again
mov ax, 0x4c00 ; terminate program
int 0x21

; Sorting A List Of Ten Numbers Using Bubble Sort


[org 0x0100]
jmp start
start: mov bx, 0 ; initialize array index to zero
mov byte [swap], 0 ; rest swap flag to no swaps

IMCB H-9, Islamabad____________( Page 45 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

loop1: mov ax, [data+bx] ; load number in ax


cmp ax, [data+bx+2] ; compare with next number
jbe noswap ; no swap if already in order
mov dx, [data+bx+2] ; load second element in dx
mov [data+bx+2], ax ; store first number in second
mov [data+bx], dx ; store second number in first
mov byte [swap], 1 ; flag that a swap has been done
noswap: add bx, 2 ; advance bx to next index
cmp bx, 18 ; are we at last index
jne loop1 ; if not compare next two
cmp byte [swap], 1 ; check if a swap has been done
je bsort ; if yes make another pass
mov ax, 0x4c00 ; terminate program
int 0x21

Section .DATA

data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0
swap: db 0

; 4bit Multiplication Algorithm


[org 0x100]
jmp start
start: mov cl, 4 ; initialize bit count to four
mov bl, [multiplicand] ; load multiplicand in bl
mov dl, [multiplier] ; load multiplier in dl
checkbit: shr dl, 1 ; move right most bit in carry
jnc skip ; skip addition if bit is zero
add [result], bl ; accumulate result
skip: shl bl, 1 ; shift multiplicand left
dec cl ; decrement bit count
jnz checkbit ; repeat if bits left
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data

multiplicand: db 13 ; 4bit multiplicand (8bit space)


multiplier: db 5 ; 4bit multiplier
result: db 0 ; 8bit result

Subroutines CALL and RET


In every processor, instructions are available to divert temporarily and to divert
permanently. The instructions for permanent diversion in 8088 are the jump instructions,

IMCB H-9, Islamabad____________( Page 46 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

while the instruction for temporary diversion is the CALL instruction. The word call must be
familiar to the readers from subroutine call in higher level languages. The CALL instruction
allows temporary diversion and therefore reusability of code.

; bubble sort algorithm Using subroutine


[org 0x0100]
jmp start

bubblesort: dec cx ; last element not compared


shl cx, 1 ; turn into byte count
mainloop: mov si, 0 ; initialize array index to zero
mov byte [swap], 0 ; reset swap flag to no swaps
innerloop: mov ax, [bx+si] ; load number in ax
cmp ax, [bx+si+2] ; compare with next number
jbe noswap ; no swap if already in order
mov dx, [bx+si+2] ; load second element in dx
mov [bx+si], dx ; store first number in second
mov [bx+si+2], ax ; store second number in first
mov byte [swap], 1 ; flag that a swap has been done
noswap: add si, 2 ; advance si to next index
cmp si, cx ; are we at last index
jne innerloop ; if not compare next two
cmp byte [swap], 1 ; check if a swap has been done
je mainloop ; if yes make another pass
ret ; go back to where we came from
start: mov bx, data ; send start of array in bx
mov cx, 10 ; send count of elements in cx
call bubblesort ; call our subroutine
mov ax, 0x4c00 ; terminate program
int 0x21

Section .data

data: dw 60, 55, 45, 50, 40, 35, 25, 30, 10, 0
swap: db 0

; clear the screen


[org 0x0100]
mov ax, 0xb800 ; load video base in ax
mov es, ax ; point es to video base
mov di, 0 ; point di to top left column
nextchar: mov word [es:di], 0x0720 ; clear next char on screen
add di, 2 ; move to next screen location
cmp di, 4000 ; has the whole screen cleared

IMCB H-9, Islamabad____________( Page 47 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

jne nextchar ; if no clear next position


mov ax, 0x4c00 ; terminate program
int 0x21

; Print String Using INT / BIOS Service


[org 0x0100]
jmp start
start: mov ah, 0x13 ; service 13 - print string
mov al, 1 ; subservice 01 – update cursor
mov bh, 0 ; output on page 0
mov bl, 7 ; normal attrib
mov dx, 0x0A0A ; row 10 column 3
mov cx, 14 ; length of string
push cs
pop es ; segment of string
mov bp, message ; offset of string
int 0x10 ; call BIOS video service
mov ax, 0x4c00 ; terminate program
int 0x21

Section .DATA

message: db 'Hello Pakistan’

Challenging Programming tasks for students


1. DISPLAY LOWERCASE ALPHABETS z-a IN REVERSE ORDER,
SEPARATED BY SPACE (USE CX AND LOOP TO ITERATE)
Assignment: Display Uppercase letters now Z-A
Assignment: Display Uppercase letters from A to Z
Assignment: Display Decimal Digits 0 to 9
[ORG 0X0100]
SECTION .TEXT
MAIN:
MOV DX, MSG_1
MOV AH, 9
INT 21H
MOV CL, 26
REPT:
MOV AH, 2
MOV BL,0X60
ADD BL,CL

IMCB H-9, Islamabad____________( Page 48 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

MOV AH, 2
MOV DL, BL
INT 21H
MOV DL, 0XFF
INT 21H
LOOP REPT
MOV DX, MSG_2
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
MOV AH, 4CH
INT 21H
SECTION .DATA
MSG_1 DB 'PRINTING ALPHABETS :',0DH,0AH,'$'
MSG_2 DB 0DH,0AH,'PRESS ANY KEY TO QUIT : $':

2. ADD TWO DIGITS RECEIVED FROM USER


(Limits: Add digits resulting sum as a digit)
Assignment: Change it to Find Difference of Values
[ORG 0X0100]
SECTION .TEXT
MAIN:
MOV DX, MSG_1
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
SUB AL, 30H ;ASCII EQUIVALENT
MOV [VAL_1],AL
MOV AH, 2
MOV DL, 0DH
INT 21H
MOV DL, 0AH
INT 21H
MOV DX, MSG_2
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
SUB AL, 30H
MOV [VAL_2],AL
MOV AH, 2
MOV DL, 0DH
INT 21H

IMCB H-9, Islamabad____________( Page 49 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

MOV DL, 0AH


INT 21H
MOV DX, MSG_3
MOV AH, 9
INT 21H
MOV AL, [VAL_1]
ADD AL, [VAL_2]
ADD AL, 30H
MOV AH, 2
MOV DL, AL
INT 21H
MOV AX, 4C22H
INT 21H
SECTION .DATA
MSG_1 DB 'ENTER THE FIRST DIGIT : $'
MSG_2 DB 'ENTER THE SECOND DIGIT : $'
MSG_3 DB 'SUM OF FIRST AND SECOND DIGIT : $'
VAL_1 DB 0
VAL_2 DB 0

3. CONVERT USER GIVEN UPPERCASE LETTER TO LOWERCASE


(Limits: Use digits resulting answer a digit)
Assignment: Change it to convert Lowercase to uppercase
Assignment: Allow Only Lower or Uppercase letters and the
convert

[ORG 0X0100]
SECTION .TEXT
MAIN:
MOV DX, MSG_1
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
MOV BL, AL
MOV DX, MSG_2
MOV AH, 9
INT 21H
OR BL, 20H ; convert a upper case letter to lower case letter
MOV AH, 2
MOV DL, BL
INT 21H
MOV AX, 4C22H ; return control to DOS
INT 21H
SECTION .DATA

IMCB H-9, Islamabad____________( Page 50 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

MSG_1 DB 'Enter the Upper Case Letter : $'


MSG_2 DB 0DH,0AH,'The Lower Case Letter is : $'

4. INITIALIZE AN ARRAY OF 10 CHARACTERS ACCEPTING FROM THE


USER. DISPLAY IT AS A STRING.
Assignment: Display string in Reverse Order
Assignment: Show n <= 10 characters from beginning of the string
Assignment: Show n <= 10 characters from End of the string
(Limits: Use digits resulting answer a digit)

[ORG 0X0100]
SECTION .TEXT
MAIN:
MOV SI, CHARS
MOV DX, MSG_1
MOV AH, 9
INT 21H
MOV CL, 10
REPT:
MOV AH, 1
INT 21H
MOV [SI], AL
INC SI
LOOP REPT
MOV DX, MSG_2
MOV AH, 9
INT 21H
MOV DX, CHARS
MOV AH, 9
INT 21H
MOV SI,CHARS+10
MOV DX, MSG_3
MOV AH, 9
INT 21H
MOV CL, 10
REPT2:
MOV AH, 2
MOV DL,[SI-1]
INT 21H
DEC SI
LOOP REPT2
MOV DX, MSG_4
MOV AH, 9
INT 21H
MOV AH, 1

IMCB H-9, Islamabad____________( Page 51 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

INT 21H
MOV AH, 4CH
INT 21H
SECTION .DATA
MSG_1 DB 'ENTER ANY TEN ALPHABETS :',0DH,0AH,'$'
MSG_2 DB 0DH,0AH,'STRING OF TEN CHARACTERS, YOU HAVE PROVIDED IS :
',0DH,0AH,'$'
MSG_3 DB 0DH,0AH,'STRING OF TEN CHARACTERS, YOU HAVE PROVIDED IS :
',0DH,0AH,'$'
MSG_4 DB 0DH,0AH,'PRESS ANY KEY TO QUIT : $'
CHARS TIMES 11 DB '$'

5. Display Register Value in Decimal or any desired base


(Limits: Use digits resulting answer a digit)
Assignment: Convert given numbers in Bin, Oct, Dec

[ORG 0X0100]
SECTION .TEXT
MOV AX,[D1]
CALL PRINT
MOV AH,4CH
INT 21H
PRINT:
MOV CX,0 ;INITIALIZE COUNTERS
MOV DX,0
PARA1:
CMP AX,0
JE PRINTDIGITS ; JUMP IF AX IS ZERO
MOV BX,10 ;INITIALIZE BX TO BASE AS DIVISOR
DIV BX ; DIV GIVES QUOTIENT AND REMAINDER EXTRACT THE MSD
PUSH DX ;PUSH IT IN THE STACK
INC CX ;INCREMENT THE COUNTER
XOR DX,DX ;SET PREVIOUSLY USED DX TO 0
JMP PARA1 ;REPEATEDLY FIND DIGITS OF ANSWER AND STORE THEM IN
STACK
PRINTDIGITS:
CMP CX,0
JE EXIT ;CHECK AND EXIT IF NO DIGITS TO SHOW
POP DX ;POP THE TOP DIGIT FROM THE STACK
ADD DX, 0x30 ;ADD 48 SO THAT IT REPRESENTS THE ASCII VALUE OF DIGITS
MOV AH,02H
INT 21H ; PRINT THAT CHARACTER
DEC CX ;DECREASE THE COUNTER
JMP PRINTDIGITS ; REPEATEDLY PRINT ALL DIGITS
EXIT:

IMCB H-9, Islamabad____________( Page 52 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

RET
SECTION .DATA
D1 DW 1237D ; NUMBER TO BE CONVERTED

6. SUBTRACT DIGIT FROM ANOTHER DIGIT RECEIVED FROM USER


(Limits: USE APPROPRIATE VALUES)
Assignment: Display Factorial Answer in desired base

[ORG 0X0100]
MOV CX, 0
MOV CX, [NM]
MOV AX,1
MOV DX, 0
L1:
IMUL CX
LOOP L1
; LOWER WORD IS IN AX
; HIGHER WORD IS IN DX
MOV AX,0X4C22
INT 0X21
SECTION .DATA
NM DW 4

IMCB H-9, Islamabad____________( Page 53 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

Installation and setting-up Environment


NASM + AFD Netwide Assembler and Advance FullScreen Debugger
• Install DOSBox 0.74-3
• Download NASM+ADF.ZIP File from your MS-TEAMS class
• Extract NASM and AFD files to a folder say NASM
• (Any accessible location, Preferably D:\NASM)
• Configure Dosbox to refer to NASM folder as drive. Use Commands at Z:\>
• MOUNT K D:\NASM <Enter> // K is any unused Virtual Drive Letter
• K: <Enter> // Change to Drive having NASM files
• Test AFD using command: AFD <Press Enter>
• Use NOTEPAD or EDIT or any other text editor to Write your program

An assembler program creates object code by translating combinations of mnemonics and syntax
for operations and addressing modes into their numerical equivalents. Source Code is .asm and
assembled file is .com and Listing File has extension .lst

HOW TO Assemble Source Code: Assemble above code using Command


> NASM test.asm –o test.com -l test.lst
> AFD test.com (to RUN in Debugger
> test.com (to RUN as applet)

Source Code (TEST.ASM) Contents of the Listing File for Source Code
(TEST.LST)
Human readable text file This is also human readable
 Type test.asm  Type test.lst
[ORG 0x100] ; Start/Loading address 1 [ORG 0x100]
mov ax , 0x0004 2 00000000 B80400 mov ax , 0x0004
mov bx , 2 3 00000003 BB0200 mov bx , 2
mov cx , 0 4 00000006 B90000 mov cx , 0
mov dx, 0 5 00000009 BA0000 mov dx, 0
add ax, bx 6 0000000C 01D8 add ax, bx
sub ax, bx 7 0000000E 29D8 sub ax, bx
mul bx 8 00000010 F7E3 mul bx
div bx 9 00000012 F7F3 div bx
mov ax, 0x4c00 10 00000014 B8004C mov ax, 0x4c00
int 0x21 11 00000017 CD21 int 0x21

IMCB H-9, Islamabad____________( Page 54 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

Assembled Code (TEST.COM)


Machine readable file NOTE: Size of the assembled/executable file is just a
 Type test.com few bytes long and is not human readable even if
Contents of the executable File you view it by using TYPE command.
It is meaningful in debugger and executable.
» ¹ º Ø)Ø÷ã÷ó¸ LÍ!
Snapshot of the assembled code in action in AFD

Format of a machine instruction


[Label:] Mnemonic [Operand, Operand] [; Comments]
• Brackets indicate that a field is optional
• Label is an identifier that is assigned the address of the first byte of the instruction in which it
appears. It must be followed by “:” Usually used to transfer controls
• Inclusion of spaces is arbitrary, except that at least one space must be inserted; no space would
lead to an ambiguity.
• Comment / Remarks field begins with a semicolon “ ; ”

IMCB H-9, Islamabad____________( Page 55 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

Template of an assembly program in MASM for DOS


(Install DOXBOX and configure Drive/Path etc similar to that of NASM (Netwide Assembler). Use any
TEXT Editor / IDE or even COPY CON <filename> command to create file. Assemble with appropriate
assembler and run.

Once the executable file is ready you can run from Command Prompt or see internal working using
debugger.

(Errors and omissions if any are accepted and shall be rectified accordingly)

IMCB H-9, Islamabad____________( Page 56 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

Pages intentionally left blank for Notes


_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

IMCB H-9, Islamabad____________( Page 57 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)
ISLAMABAD MODEL COLLEGE FOR BOYS H -9, ISLAMABAD
LAB MANUAL - Introduction to Assembly Language (8086 Instruction Set)
Version #: NT-2301)

Pages intentionally left blank for Notes

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

_________________________________________________________________________________

________________________________________________________________________________

IMCB H-9, Islamabad____________( Page 58 of 58 )____________Nadeem Taj-2022-23 (Version 2301)


(LAB Manual - 8086 Assembly Language Instruction Set for NASM / MASM Assemblers with Minor adjustments.)

You might also like