0% found this document useful (0 votes)
8 views24 pages

Mpmc Notes 3

Uploaded by

dandusrinivas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views24 pages

Mpmc Notes 3

Uploaded by

dandusrinivas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

1|Page UNIT-2 GOGA SUBRAMANYAM

UNIT-II:
8086 PROGRAMMING: Program development steps, instructions, addressing modes,
assembler directives, writing simple programs with an assembler, assembly language program
development tools.
1.18086 Instruction Set
1. Data Transfer instructions: These instructions are used to transfer the data from source
operand to destination operand. All the store, move, load, exchange, input and output instructions
belong to this group.
General purpose byte or word transfer instructions:
1)MOV – MOV Destination, Source
The MOV instruction copies a word or byte of data from a specified source to a specified
destination. The destination can be a register or a memory location. The source can be a register,
a memory location or an immediate number. The source and destination cannot both be memory
locations. They must both be of the same type (bytes or words). MOV instruction does not affect
any flag.
 MOV CX, 037AH Put immediate number 037AH to CX
 MOV BL, [437AH] Copy byte in DS at offset 437AH to BL
 MOV AX, BX Copy content of register BX to AX
 MOV DL, [BX] Copy byte from memory at [BX] to DL
 MOV DS, BX Copy word from BX to DS register
2). PUSH – PUSH Source
The PUSH instruction decrements the stack pointer by 2 and copies a word from a
specified source to the location in the stack segment to which the stack pointer points. The
source of the word can be general-purpose register, segment register, or memory.This instruction
does not affect any flag.
 PUSH BX Decrement SP by 2, copy BX to stack.
 PUSH DS Decrement SP by 2, copy DS to stack.
 PUSH BL Illegal; must push a word
3).POP – POP Destination
The POP instruction copies a word from the stack location pointed to by the stack pointer to
a destination specified in the instruction. The destination can be a general-purpose register, a
segment register or a memory location. The data in the stack is not changed. After the word is
copied to the specified destination, the stack pointer is automatically incremented by 2 to point to
the next word on the stack. The POP instruction does not affect any flag.
 POP DX Copy a word from top of stack to DX; increment SP by 2
 POP DS Copy a word from top of stack to DS; increment SP by 2
4). PUSHA: Push all registers to the stack
Pushes the contents of the general-purpose registers onto the stack. The registers are
stored on the stack in the following order: AX, CX, DX, BX, SP (original value), BP, SI, and DI
(if the operand-size attribute is 16).
5). POPA: Pop the words from stack to all registers
POPS the contents from the stack into the general-purpose registers. The registers are
loaded in the following order: DI, SI, BP, BX, DX, CX, and AX (if the operand-size is 16).
6). XCHG – XCHG Destination, Source
The XCHG instruction exchanges the content of a register with the content of another
register or with the content of memory location(s). It cannot directly exchange the content of two
memory locations. The source and destination must both be of the same type (bytes or words).
The segment registers cannot be used in this instruction. This instruction does not affect any flag.
 XCHG AX, DX Exchange word in AX with word in DX
 XCHG BL, CH Exchange byte in BL with byte in CH
2|Page UNIT-2 GOGA SUBRAMANYAM

Simple input and output port transfer instructions


1).IN – IN Accumulator, Port
The IN instruction copies data from a port(Input device) to the AL or AX register. If an
8-bit port is read, the data will go to AL. If a 16-bit port is read, the data will go to AX.
The IN instruction has two possible formats, fixed port and variable port. For fixed port
type, the 8-bit address of a port is specified directly in the instruction. With this form, any one of
256 possible ports can be addressed.
 IN AL, OC8H Input a byte from port OC8H to AL
 IN AX, 34H Input a word from port 34H to AX
For the variable-port(16-bit) form of the IN instruction, the port address is loaded into the
DX register before the IN instruction. Since DX is a 16-bit register, the port address can be any
number between 0000H and FFFFH. Therefore, up to 65,536 ports are addressable in this mode.
 MOV DX, 0FF78H Initialize DX to point to port
 IN AL, DX Input a byte from 8-bit port 0FF78H to AL
 IN AX, DX Input a word from 16-bit port 0FF78H to AX
2). OUT – OUT Port, Accumulator
The OUT instruction copies a byte from AL or a word from AX to the specified port. The
OUT instruction has two possible forms, fixed port and variable port. For the fixed port form, the
8-bit port address is specified directly in the instruction. With this form, any one of 256 possible
ports can be addressed.
 OUT 3BH, AL Copy the content of AL to port 3BH
 OUT 2CH, AX Copy the content of AX to port 2CH
For variable port form of the OUT instruction, the content of AL or AX will be copied to the port
at an address contained in DX. Therefore, the DX register must be loaded with the desired port
address before this form of the OUT instruction is used.
 MOV DX, 0FFF8H Load desired port address in DX
 OUT DX, AL Copy content of AL to port FFF8H
 OUT DX, AX Copy content of AX to port FFF8H
NOTE:The OUT instruction does not affect any flag.
Special address transfer instructions
1). LEA – LEA Register, Source
This instruction determines the offset of the variable or memory location named as the
source and puts this offset Address in the indicated 16-bit register. LEA does not affect any flag.
 LEA BX, PRICES Load BX with offset of PRICE in DS
2). LDS – LDS Register, Memory address of the first word
This instruction loads new values into the specified register and into the DS register from
four successive memory locations. The word from two memory locations is copied into the
specified register and the word from the next two memory locations is copied into the DS
registers. LDS does not affect any flag.
 LDS BX, [4326] Copy content of memory at displacement 4326H in DS
to BL,content of 4327H to BH. Copy content at
displacement of 4328H and 4329H in DS to DS register.
3). LES – LES Register, Memory address of the first word
This instruction loads new values into the specified register and into the ES register from
four successive memory locations. The word from the first two memory locations is copied into
the specified register, and the word from the next two memory locations is copied into the ES
register. LES does not affect any flag.
 LES BX, [789AH] Copy content of memory at displacement 789AH in DS to BL,content of
789BH to BH, content of memory at displacement 789CH and 789DH in
DS is copied to ES register.
3|Page UNIT-2 GOGA SUBRAMANYAM

Flag transfer registers


1).LAHF (COPY LOW BYTE OF FLAG REGISTER TO AH REGISTER)
The LAHF instruction copies the low-byte of the 8086 flag register to AH register. It can
then be pushed onto the stack along with AL by a PUSH AX instruction. LAHF does not affect
any flag.
2).SAHF (COPY AH REGISTER TO LOW BYTE OF FLAG REGISTER)
The SAHF instruction replaces the low-byte of the 8086 flag register with a byte from the
AH register. SAHF changes the flags in lower byte of the flag register.
3).PUSHF (PUSH FLAG REGISTER TO STACK)
The PUSHF instruction decrements the stack pointer by 2 and copies a word in the flag
register to two memory locations in stack pointed to by the stack pointer. The stack segment
register is not affected. This instruction does to affect any flag.
4).POPF (POP WORD FROM TOP OF STACK TO FLAG REGISTER)
The POPF instruction copies a word from two memory locations at the top of the stack to
the flag register and increments the stack pointer by 2. The stack segment register and word on
the stack are not affected. This instruction does to affect any flag.
2. Arithmetic instructions: These instructions are used to perform various
Mathematical operations like addition, subtraction, multiplication and division etc….
Addition instructions
1).ADD – ADD Destination, Source
2).ADC – ADC Destination, Source
These instructions add a number from some source to a number in some destination and
put the result in the specified destination. The ADC also adds the status of the carry flag to the
result. The source may be an immediate number, a register, or a memory location. The
destination may be a register or a memory location. The source and the destination in an
instruction cannot both be memory locations. The source and the destination must be of the same
type (bytes or words). If you want to add a byte to a word, you must copy the byte to a word
location and fill the upper byte of the word with 0’s before adding. Flags affected: AF, CF, OF,
SF, ZF.
 ADD AL, 74H ;Add immediate number 74H to content of AL. Result in AL
 ADC CL, BL ;Add content of BL plus carry status to content of CL
3).INC – INC Destination
The INC instruction adds 1 to a specified register or to a memory location. AF, OF, PF,
SF, and ZF are updated, but CF is not affected. This means that if an 8-bit destination containing
FFH or a 16-bit destination containing FFFFH is incremented, the result will be all 0’s with no
carry.

4).AAA (ASCII ADJUST FOR ADDITION)


Numerical data coming into a computer from a terminal is usually in ASCII code. In this
code, the numbers 0 to 9 are represented by the ASCII codes 30H to 39H. The 8086 allows you
to add the ASCII codes for two decimal digits without masking off the “3” in the upper nibble of
each. After the addition, the AAA instruction is used to make sure the result is the correct
unpacked BCD.
 Let AL = 0011 0101 (ASCII 5), and BL = 0011 1001 (ASCII 9)
 ADD AL, BL AL = 0110 1110 (6EH, which is incorrect BCD)
 AAA AL = 0000 0100 (unpacked BCD 4)
CF = 1 indicates answer is 14 decimal.
4|Page UNIT-2 GOGA SUBRAMANYAM

The AAA instruction works only on the AL register. The AAA instruction updates AF
and CF; but OF, PF, SF and ZF are left undefined.
5). DAA (DECIMAL ADJUST AFTER BCD ADDITION)
This instruction is used to make sure the result of adding two packed BCD numbers is
adjusted to be a legal BCD number. The result of the addition must be in AL for DAA to work
correctly. If the lower nibble in AL after an addition is greater than 9 or AF was set by the
addition, then the DAA instruction will add 6 to the lower nibble in AL. If the result in the upper
nibble of AL in now greater than 9 or if the carry flag was set by the addition or correction, then
the DAA instruction will add 60H to AL.
Let AL = 59 BCD, and BL = 35 BCD

 ADD AL, BL AL = 8EH; lower nibble > 9, add 06H to AL


 DAA AL = 94 BCD, CF = 0
Let AL = 88 BCD, and BL = 49 BCD
 ADD AL, BL AL = D1H; AF = 1, add 06H to AL
 DAA AL = D7H; upper nibble > 9, add 60H to AL
AL = 37 BCD, CF = 1
The DAA instruction updates AF, CF, SF, PF, and ZF; but OF is undefined.
Subtraction instructions
1).SUB – SUB Destination, Source
2).SBB – SBB Destination, Source
These instructions subtract the number in some source from the number in some
destination and put the result in the destination. The SBB instruction also subtracts the content of
carry flag from the destination. The source may be an immediate number, a register or memory
location. The destination can also be a register or a memory location. However, the source and
the destination cannot both be memory location. The source and the destination must both be of
the same type (bytes or words). If you want to subtract a byte from a word, you must first move
the byte to a word location such as a 16-bit register and fill the upper byte of the word with 0’s.
Flags affected: AF, CF, OF, PF, SF, ZF.
– BX; Result in CX

Result in CH
;Subtract immediate number 3427H from AX
3). DEC – DEC Destination
This instruction subtracts 1 from the destination word or byte. The destination can be a
register or a memory location. AF, OF, SF, PF, and ZF are updated, but CF is not affected. This
means that if an 8-bit destination containing 00H or a 16-bit destination containing 0000H is
decremented, the result will be FFH or FFFFH with no carry (borrow).
 DEC CL ;Subtract 1 from content of CL register
 DEC BP ;Subtract 1 from content of BP register
 DEC BYTE PTR [BX] ;Subtract 1 from byte at offset [BX] in DS.
4). NEG – NEG Destination
This instruction replaces the number in a destination with its 2’s complement. The
destination can be a register or a memory location. It gives the same result as the invert each bit
and add one algorithm. The NEG instruction updates AF, AF, PF, ZF, and OF.
 NEG AL ;Replace number in AL with its 2’s complement
 NEG BX ;Replace number in BX with its 2’s complement
5|Page UNIT-2 GOGA SUBRAMANYAM

5). CMP – CMP Destination, Source


This instruction compares a byte / word in the specified source with a byte / word in the
specified destination. The source can be an immediate number, a register, or a memory location.
The destination can be a register or a memory location. However, the source and the destination
cannot both be memory locations. The comparison is actually done by subtracting the source
byte or word from the destination byte or word. The source and the destination are not changed,
but the flags are set to indicate the results of the comparison. AF, OF, SF, ZF, PF, and CF are
updated by the CMP instruction. For the instruction CMP CX, BX, the values of CF, ZF, and SF
will be as follows:
CF ZF SF
CX = BX 0 1 0 Result of subtraction is 0
CX > BX 0 0 0 No borrow required, so CF = 0
CX < BX 1 0 1 Subtraction requires borrow, so CF = 1
 CMP AL, 01H Compare immediate number 01H with byte in AL
 CMP BH, CL Compare byte in CL with byte in BH
6). AAS (ASCII ADJUST FOR SUBTRACTION)
Numerical data coming into a computer from a terminal is usually in an ASCII code. In
this code the numbers 0 to 9 are represented by the ASCII codes 30H to 39H. The 8086 allows
you to subtract the ASCII codes for two decimal digits without masking the “3” in the upper
nibble of each. The AAS instruction is then used to make sure the result is the correct unpacked
BCD.
Let AL = 00111001 (39H or ASCII 9), and BL = 00110101 (35H or ASCII 5)
 SUB AL, BL AL = 00000100 (BCD 04), and CF = 0
 AAS AL = 00000100 (BCD 04), and CF = 0 (no borrow required)
Let AL = 00110101 (35H or ASCII 5), and BL = 00111001 (39H or ASCII 9)
 SUB AL, BL AL = 11111100 (– 4 in 2’s complement form), and CF = 1
 AAS AL = 00000100 (BCD 06), and CF = 1 (borrow required)
The AAS instruction works only on the AL register. It updates ZF and CF; but OF, PF, SF, AF
are left undefined.
7). DAS (DECIMAL ADJUST AFTER BCD SUBTRACTION)
This instruction is used after subtracting one packed BCD number from another packed
BCD number, to make sure the result is correct packed BCD. The result of the subtraction must
be in AL for DAS to work correctly. If the lower nibble in AL after a subtraction is greater than
9 or the AF was set by the subtraction, then the DAS instruction will subtract 6 from the lower
nibble AL. If the result in the upper nibble is now greater than 9 or if the carry flag was set, the
DAS instruction will subtract 60 from AL.
Let AL = 49 BCD, and BH = 72 BCD
 SUB AL, BH AL = D7H; upper nibble > 9, subtract 60H from AL
 DAS AL = 77 BCD, CF = 1 (borrow is needed)
The DAS instruction updates AF, CF, SF, PF, and ZF; but OF is undefined
Multiplication instructions:
1).MUL – MUL Source
This instruction multiplies an unsigned byte in some source with an unsigned byte in AL
register or an unsigned word in some source with an unsigned word in AX register. The source
can be a register or a memory location. When a byte is multiplied by the content of AL, the result
(product) is put in AX. When a word is multiplied by the content of AX, the result is put in DX
and AX registers. If the most significant byte of a 16-bit result or the most significant word of a
32-bit result is 0, CF and OF will both be 0’s. AF, PF, SF and ZF are undefined after a MUL
instruction.
6|Page UNIT-2 GOGA SUBRAMANYAM

Multiply AL with BH; result in AX


Multiply AX with CX; result high word in DX, low word in AX
2). IMUL – IMUL Source
This instruction multiplies a signed byte from source with a signed byte in AL or a signed
word from some source with a signed word in AX. The source can be a register or a memory
location. When a byte from source is multiplied with content of AL, the signed result (product)
will be put in AX. When a word from source is multiplied by AX, the result is put in DX and
AX. If the magnitude of the product does not require all the bits of the destination, the unused
byte / word will be filled with copies of the sign bit. If the upper byte of a 16-bit result or the
upper word of a 32-bit result contains only copies of the sign bit (all 0’s or all 1’s), then CF and
the OF will both be 0; If it contains a part of the product, CF and OF will both be 1. AF, PF, SF
and ZF are undefined after IMUL.
Multiply signed byte in AL with signed byte in BH; result in AX.
Multiply AX times AX; result in DX and AX
3). AAM (BCD ADJUST AFTER MULTIPLY)
Before you can multiply two ASCII digits, you must first mask the upper 4 bit of each.
This leaves unpacked BCD (one BCD digit per byte) in each byte. After the two unpacked BCD
digits are multiplied, the AAM instruction is used to adjust the product to two unpacked BCD
digits in AX. AAM works only after the multiplication of two unpacked BCD bytes, and it works
only the operand in AL. AAM updates PF, SF and ZF but AF; CF and OF are left undefined.
Let AL = 00000101 (unpacked BCD 5), and BH = 00001001 (unpacked BCD 9)
 MUL BH AL x BH: AX = 00000000 00101101 = 002DH
 AAM AX = 00000100 00000101 = 0405H (unpacked BCD for 45)
Division instructions:
1). DIV – DIV Source
This instruction is used to divide an unsigned word by a byte or to divide an unsigned
double word (32 bits) by a word. When a word is divided by a byte, the word must be in the AX
register. The divisor can be in a register or a memory location. After the division, AL will
contain the 8-bit quotient, and AH will contain the 8-bit remainder. When a double word is
divided by a word, the most significant word of the double word must be in DX, and the least
significant word of the double word must be in AX. After the division, AX will contain the 16-
bit quotient and DX will contain the 16-bit remainder. If an attempt is made to divide by 0 or if
the quotient is too large to fit in the destination (greater than FFH / FFFFH), the 8086 will
generate a type 0 interrupt. All flags are undefined after a DIV instruction.
;Divide word in AX by byte in BL; Quotient in AL, remainder in AH
;Divide down word in DX and AX by word in CX;Quotient in AX, and
remainder in DX.
2). IDIV – IDIV Source
This instruction is used to divide a signed word by a signed byte, or to divide a signed
double word by a signed word. When dividing a signed word by a signed byte, the word must be
in the AX register. The divisor can be in an 8-bit register or a memory location. After the
division, AL will contain the signed quotient, and AH will contain the signed remainder. The
sign of the remainder will be the same as the sign of the dividend. If an attempt is made to divide
by 0, the quotient is greater than 127 (7FH) or less than –127 (81H), the 8086 will automatically
generate a type 0 interrupt.
When dividing a signed double word by a signed word, the most significant word of the
dividend (numerator) must be in the DX register, and the least significant word of the dividend
must be in the AX register. The divisor can be in any other 16-bit register or memory location.
After the division, AX will contain a signed 16-bit quotient, and DX will contain a signed 16-bit
7|Page UNIT-2 GOGA SUBRAMANYAM

remainder. The sign of the remainder will be the same as the sign of the dividend. Again, if an
attempt is made to divide by 0, the quotient is greater than +32,767 (7FFFH) or less than –32,767
(8001H), the 8086 will automatically generate a type 0 interrupt.
All flags are undefined after an IDIV.
Signed word in AX/signed byte in BL
Signed double word in DX and AX/signed word in BP
3).AAD (BCD-TO-BINARY CONVERT BEFORE DIVISION)
AAD converts two unpacked BCD digits in AH and AL to the equivalent binary number
in AL. This adjustment must be made before dividing the two unpacked BCD digits in AX by an
unpacked BCD byte. After the BCD division, AL will contain the unpacked BCD quotient and
AH will contain the unpacked BCD remainder. AAD updates PF, SF and ZF; AF, CF and OF are
left undefined.
Let AX = 0607 (unpacked BCD for 67 decimal), and CH = 09H
 AAD AX = 0043 (43H = 67 decimal)
 DIV CH AL = 07; AH = 04; Flags undefined after DIV
If an attempt is made to divide by 0, the 8086 will generate a type 0 interrupt.
4). CBW (CONVERT SIGNED BYTE TO SIGNED WORD)
This instruction copies the sign bit of the byte in AL to all the bits in AH. AH is then said
to be the sign extension of AL. CBW does not affect any flag.
Let AX = 00000000 10011011 (–155 decimal)
 CBW Convert signed byte in AL to signed word in AX
AX = 11111111 10011011 (–155 decimal)
5).CWD (CONVERT SIGNED WORD TO SIGNED DOUBLE WORD)
This instruction copies the sign bit of a word in AX to all the bits of the DX register. In
other words, it extends the sign of AX into all of DX. CWD affects no flags.
Let DX = 00000000 00000000, and AX = 11110000 11000111 (–3897 decimal)
 CWD Convert signed word in AX to signed double word in DX:AX
DX = 11111111 11111111
AX = 11110000 11000111 (–3897 decimal)
3. Bit Manipulation instructions or Logical instructions:
These instructions include logical , shift and rotate instructions in which a bit of the data
is involved.
Logical instructions
1). NOT – NOT Destination
The NOT instruction inverts each bit (forms the 1’s complement) of a byte or word in the
specified destination. The destination can be a register or a memory location. This instruction
does not affect any flag.
 NOT BX ;Complement content or BX register
 NOT BYTE PTR [BX] ; Complement memory byte at offset [BX] in data segment.

2). AND – AND Destination, Source


This instruction ANDs each bit in a source byte or word with the same numbered bit in a
destination byte or word. The result is put in the specified destination. The content of the
specified source is not changed.
The source can be an immediate number, the content of a register, or the content of a memory
location. The destination can be a register or a memory location. The source and the destination
cannot both be memory locations. CF and OF are both 0 after AND. PF, SF, and ZF are updated
by the AND instruction. AF is undefined. PF has meaning only for an 8-bit operand.
8|Page UNIT-2 GOGA SUBRAMANYAM

 AND CX, [SI] ;AND word in DS at offset [SI] with word in CX register; Result in CX
register
 AND BH, CL ;AND byte in CL with byte in BH; Result in BH
3). OR – OR Destination, Source
This instruction ORs each bit in a source byte or word with the same numbered bit in a
destination byte or word. The result is put in the specified destination. The content of the
specified source is not changed.
The source can be an immediate number, the content of a register, or the content of a
memory location. The destination can be a register or a memory location. The source and
destination cannot both be memory locations. CF and OF are both 0 after OR. PF, SF, and ZF are
updated by the OR instruction. AF is undefined. PF has meaning only for an 8-bit operand.
 OR AH, CL ;CL ORed with AH, result in AH, CL not changed
 OR BP, SI ;SI ORed with BP, result in BP, SI not changed
 OR SI, BP ; BP ORed with SI, result in SI, BP not changed
4). XOR – XOR Destination, Source
This instruction Exclusive-ORs each bit in a source byte or word with the same numbered
bit in a destination byte or word. The result is put in the specified destination. The content of the
specified source is not changed.
The source can be an immediate number, the content of a register, or the content of a
memory location. The destination can be a register or a memory location. The source and
destination cannot both be memory locations. CF and OF are both 0 after XOR. PF, SF, and ZF
are updated. PF has meaning only for an 8-bit operand. AF is undefined.
 XOR CL, BH ;Byte in BH exclusive-ORed with byte in CL.
Result in CL. BH not changed.
 XOR BP, DI Word in DI exclusive-ORed with word in BP.
Result in BP. DI not changed.

5). TEST – TEST Destination, Source


This instruction ANDs the byte / word in the specified source with the byte / word in the
specified destination. Flags are updated, but neither operand is changed. The test instruction is
often used to set flags before a Conditional jump instruction.
The source can be an immediate number, the content of a register, or the content of a
memory location. The destination can be a register or a memory location. The source and the
destination cannot both be memory locations. CF and OF are both 0’s after TEST. PF, SF and ZF
will be updated to show the results of the destination. AF is be undefined.
 TEST AL, BH AND BH with AL. No result stored; Update PF, SF, ZF.
 TEST CX, 0001H AND CX with immediate number 0001H;
No result stored; Update PF, SF, ZF
Shift instructions
1).SAL – SAL Destination, Count
2).SHL – SHL Destination, Count
SAL and SHL are two mnemonics for the same instruction. This instruction shifts each
bit in the specified destination some number of bit positions to the left. As a bit is shifted out of
the LSB operation, a 0 is put in the LSB position. The MSB will be shifted into CF. In the case
of multi-bit shift, CF will contain the bit most recently shifted out from the MSB. Bits shifted
into CF previously will be lost.
9|Page UNIT-2 GOGA SUBRAMANYAM

The destination operand can be a byte or a word. It can be in a register or in a memory


location. If you want to shift the operand by one bit position, you can specify this by putting a 1
in the count position of the instruction. For shifts of more than 1 bit position, load the desired
number of shifts into the CL register, and put “CL” in the count position of the instruction.
Shift word in BX 1 bit position left, 0 in LSB
Load desired number of shifts in CL
SAL BP, CL Shift word in BP left CL bit positions, 0 in LSBs
3). SAR – SAR Destination, Count
This instruction shifts each bit in the specified destination some number of bit positions
to the right. As a bit is shifted out of the MSB position, a copy of the old MSB is put in the MSB
position. In other words, the sign bit is copied into the MSB. The LSB will be shifted into CF. In
the case of multiple-bit shift, CF will contain the bit most recently shifted out from the LSB. Bits
shifted into CF previously will be lost.

The destination operand can be a byte or a word. It can be in a register or in a memory


location. If you want to shift the operand by one bit position, you can specify this by putting a 1
in the count position of the instruction. For shifts of more than 1 bit position, load the desired
number of shifts into the CL register, and put “CL” in the count position of the instruction
Shift word in DI one bit position right, new MSB = old MSB
Load desired number of shifts in CL
4).SHR – SHR Destination, Count
This instruction shifts each bit in the specified destination some number of bit positions
to the right. As a bit is shifted out of the MSB position, a 0 is put in its place. The bit shifted out
of the LSB position goes to CF. In the case of multi-bit shifts, CF will contain the bit most
recently shifted out from the LSB. Bits shifted into CF previously will be lost.

The destination operand can be a byte or a word in a register or in a memory location. If


you want to shift the operand by one bit position, you can specify this by putting a 1 in the count
position of the instruction. For shifts of more than 1 bit position, load the desired number of
shifts into the CL register, and put “CL” in the count position of the instruction.
Shift word in BP one bit position right, 0 in MSB
Rotate instructions
1).ROL – ROL Destination, Count
This instruction rotates all the bits in a specified word or byte to the left some number of
bit positions. The data bit rotated out of MSB is circled back into the LSB. It is also copied into
CF. In the case of multiple-bit rotate, CF will contain a copy of the bit most recently moved out
of the MSB.

The destination can be a register or a memory location. If you to want rotate the operand
by one bit position, you can specify this by putting 1 in the count position in the instruction. To
rotate more than one bit position, load the desired number into the CL register and put “CL” in
the count position of the instruction.
Rotate the word in AX 1 bit position left, MSB to LSB and CF
Load number of bits to rotate in CL
10 | P a g e UNIT-2 GOGA SUBRAMANYAM

ROL BL, CL Rotate BL 4 bit positions


2). ROR – ROR Destination, Count
This instruction rotates all the bits in a specified word or byte some number of bit
positions to right. The operation is desired as a rotate rather than shift, because the bit moved out
of the LSB is rotated around into the MSB. The data bit moved out of the LSB is also copied into
CF. In the case of multiple bit rotates, CF will contain a copy of the bit most recently moved out
of the LSB.

The destination can be a register or a memory location. If you want to rotate the operand
by one bit position, you can specify this by putting 1 in the count position in the instruction. To
rotate by more than one bit position, load the desired number into the CL register and put “CL”
in the count position of the instruction.
ROR BL, 1 Rotate all bits in BL right 1 bit position LSB to MSB and to
CF
MOV CL, 08H Load CL with number of bit positions to be rotated
ROR WORD PTR [BX], CL Rotate word in DS at offset [BX] 8 bit position
right
3). RCL – RCL Destination, Count
This instruction rotates all the bits in a specified word or byte some number of bit
positions to the left. The operation circular because the MSB of the operand is rotated into the
carry flag and the bit in the carry flag is rotated around into LSB of the operand.

The destination can be a register or a memory location. If you want to rotate the operand
by one bit position, you can specify this by putting a 1 in the count position of the instruction. To
rotate by more than one bit position, load the desired number into the CL register and put “CL”
in the count position of the instruction
RCL DX, 1 Word in DX 1 bit left, MSB to CF, CF to LSB
4). RCR – RCR Destination, Count
This instruction rotates all the bits in a specified word or byte some number of bit
positions to the right. The operation circular because the LSB of the operand is rotated into the
carry flag and the bit in the carry flag is rotate around into MSB of the operand.

The destination can be a register or a memory location. If you want to rotate the operand
by one bit position, you can specify this by putting a 1 in the count position of the instruction. To
rotate more than one bit position, load the desired number into the CL register and put “CL” in
the count position of the instruction.
RCR BX, 1 Word in BX right 1 bit, CF to MSB, LSB to CF
4. String instructions: A string is a series of bytes or a series of words in sequential
memory locations. A string often consists of ASCII character codes.
1).MOVS – MOVS Destination String Name, Source String Name
2).MOVSB – MOVSB Destination String Name, Source String Name
3).MOVSW – MOVSW Destination String Name, Source String Name
This instruction copies a byte or a word from location in the data segment to a location in
the extra segment. The offset of the source in the data segment must be in the SI register. The
11 | P a g e UNIT-2 GOGA SUBRAMANYAM

offset of the destination in the extra segment must be in the DI register. For multiple-byte or
multiple-word moves, the number of elements to be moved is put in the CX register so that it can
function as a counter. After the byte or a word is moved, SI and DI are automatically adjusted to
point to the next source element and the next destination element. If DF is 0, then SI and DI will
incremented by 1 after a byte move and by 2 after a word move. If DF is 1, then SI and DI will
be decremented by 1 after a byte move and by 2 after a word move. MOVS does not affect any
flag.
 MOV SI, OFFSET SOURCE Load offset of start of source string in DS
into SI
 MOV DI, OFFSET DESTINATION Load offset of start of destination string in
ES into DI
 MOV CX, 04H Load length of string into CX as counter
 REP MOVSB Move string byte until CX = 0
4). LODS / LODSB / LODSW (LOAD STRING BYTE INTO AL OR STRING WORD
INTO AX)
This instruction copies a byte from a string location pointed to by SI to AL, or a word from a
string location pointed to by SI to AX. If DF is 0, SI will be automatically incremented (by 1 for
a byte string, and 2 for a word string) to point to the next element of the string. If DF is 1, SI will
be automatically decremented (by 1 for a byte string, and 2 for a word string) to point to the
previous element of the string. LODS does not affect any flag.
 CLD Clear direction flag so that SI is auto-incremented
 MOV SI, OFFSET SOURCE Point SI to start of string
 LODS SOURCE Copy a byte or a word from string to AL or AX
5). STOS / STOSB / STOSW (STORE STRING BYTE OR STRING WORD)
This instruction copies a byte from AL or a word from AX to a memory location in the extra
segment pointed to by DI. In effect, it replaces a string element with a byte from AL or a word
from AX. After the copy, DI is automatically incremented or decremented to point to next or
previous element of the string. If DF is cleared, then DI will automatically incremented by 1 for
a byte string and by 2 for a word string. If DI is set, DI will be automatically decremented by 1
for a byte string and by 2 for a word string. STOS does not affect any flag.
MOV DI, OFFSET TARGET
 STOS TARGET
6). CMPS / CMPSB / CMPSW (COMPARE STRING BYTES OR STRING WORDS)
This instruction can be used to compare a byte / word in one string with a byte / word in
another string. SI is used to hold the offset of the byte or word in the source string, and DI is
used to hold the offset of the byte or word in the destination string.
The AF, CF, OF, PF, SF, and ZF flags are affected by the comparison, but the two
operands are not affected. After the comparison, SI and DI will automatically be incremented or
decremented to point to the next or previous element in the two strings.
 MOV SI, OFFSET FIRST Point SI to source string
 MOV DI, OFFSET SECOND Point DI to destination string
 CLD DF cleared, SI and DI will auto-increment after compare
 MOV CX, 100 Put number of string elements in CX
 REPE CMPSB Repeat the comparison of string bytes
12 | P a g e UNIT-2 GOGA SUBRAMANYAM

7). SCAS / SCASB / SCASW (SCAN A STRING BYTE OR A STRING WORD)


SCAS compares a byte in AL or a word in AX with a byte or a word in ES pointed to by
DI. Therefore, the string to be scanned must be in the extra segment, and DI must contain the
offset of the byte or the word to be compared. If DF is cleared, then DI will be incremented by 1
for byte strings and by 2 for word strings. If DF is set, then DI will be decremented by 1 for byte
strings and by 2 for word strings. SCAS affects AF, CF, OF, PF, SF, and ZF, but it does not
change either the operand in AL (AX) or the operand in the string.
 MOV DI, OFFSET STRING
 MOV AL, 0DH Byte to be scanned for into AL
 MOV CX, 80 CX used as element counter
 CLD Clear DF, so that DI auto increments
 REPNE SCAS STRING Compare byte in string with byte in AL
8). REP / REPE / REPZ / REPNE / REPNZ (PREFIX)
(REPEAT STRING INSTRUCTION UNTIL SPECIFIED CONDITIONS EXIST)
REP is a prefix, which is written before one of the string instructions. It will cause the
CX register to be decremented and the string instruction to be repeated until CX = 0. The
instruction REP MOVSB, for example, will continue to copy string bytes until the number of
bytes loaded into CX has been copied.
REPE and REPZ are two mnemonics for the same prefix. They stand for repeat if equal
and repeat if zero, respectively. They are often used with the Compare String instruction or with
the Scan String instruction. They will cause the string instruction to be repeated as long as the
compared bytes or words are equal (ZF = 1) and CX is not yet counted down to zero. In other
words, there are two conditions that will stop the repetition: CX = 0 or string bytes or words not
equal.
 REPE CMPSB Compare string bytes until end of string or until string bytes not
equal.
5.Program Execution Transfer instructions
These instructions are similar to branching or looping instructions.
These instructions include conditional & unconditional jump or loop instructions.
Unconditional transfer instructions
1). CALL (CALL A PROCEDURE)
The CALL instruction is used to transfer execution to a subprogram or a procedure. There two
basic type of calls near and far.
1. A near call is a call to a procedure, which is in the same code segment as the CALL
instruction. When the 8086 executes a near CALL instruction, it decrements the stack pointer by
2 and copies the offset of the next instruction after the CALL into the stack. This offset saved in
the stack is referred to as the return address, because this is the address that execution will return
to after the procedure is executed. A near CALL instruction will also load the instruction pointer
with the offset of the first instruction in the procedure. A RET instruction at the end of the
procedure will return execution to the offset saved on the stack which is copied back to IP.
2. A far call is a call to a procedure, which is in a different segment from the one that
contains the CALL instruction. When the 8086 executes a far call, it decrements the stack pointer
by 2 and copies the content of the CS register to the stack. It then decrements the stack pointer by
2 again and copies the offset of the instruction after the CALL instruction to the stack. Finally, it
loads CS with the segment base of the segment that contains the procedure, and loads IP with the
offset of the first instruction of the procedure in that segment. A RET instruction at the end of the
procedure will return execution to the next instruction after the CALL by restoring the saved
values of CS and IP from the stack.
 CALL MULT
13 | P a g e UNIT-2 GOGA SUBRAMANYAM

2).RET (RETURN EXECUTION FROM PROCEDURE TO CALLING PROGRAM)


The RET instruction will return execution from a procedure to the next instruction after
the CALL instruction which was used to call the procedure. If the procedure is near procedure
(in the same code segment as the CALL instruction), then the return will be done by replacing
the IP with a word from the top of the stack. The word from the top of the stack is the offset of
the next instruction after the CALL. This offset was pushed into the stack as part of the operation
of the CALL instruction. The stack pointer will be incremented by 2 after the return address is
popped off the stack
3). JMP (UNCONDITIONAL JUMP TO SPECIFIED DESTINATION)
This instruction will fetch the next instruction from the location specified in the
instruction rather than from the next location after the JMP instruction. If the destination is in the
same code segment as the JMP instruction, then only the instruction pointer will be changed to
get the destination location. This is referred to as a near jump. If the destination for the jump
instruction is in a segment with a name different from that of the segment containing the JMP
instruction, then both the instruction pointer and the code segment register content will be
changed to get the destination location. This referred to as a far jump. The JMP instruction does
not affect any flag.
Conditional transfer instructions
1. JA/JNBE : Jump if above / jump if not below or equal
2. JAE/JNB : Jump if above /jump if not below
3. JBE/JNA : Jump if below or equal/ Jump if not above
4. JC : jump if carry flag CF=1
5. JE/JZ : jump if equal/jump if zero flag ZF=1
6. JG/JNLE : Jump if greater/ jump if not less than or equal
7. JGE/JNL : jump if greater than or equal/ jump if not less than
8. JL/JNGE : jump if less than/ jump if not greater than or equal
9. JLE/JNG : jump if less than or equal/ jump if not greater than
10.JNC : jump if no carry (CF=0)
11.JNE/JNZ : jump if not equal/ jump if not zero(ZF=0)
12.JNO : jump if no overflow(OF=0)
13.JNP/JPO : jump if not parity/ jump if parity odd(PF=0)
14.JNS : jump if not sign(SF=0)
15.JO : jump if overflow flag(OF=1)
16.JP/JPE : jump if parity/jump if parity even(PF=1)
17.JS : jump if sign(SF=1)
6. Iteration control instructions:
1. LOOP :Loop through a sequence of instructions until CX=0
2. LOOPE/LOOPZ : Loop through a sequence of instructions while ZF=1 and CX = 0
LOOPE / LOOPZ (LOOP WHILE CX 0 AND ZF = 1)
3. LOOPNE/LOOPNZ : Loop through a sequence of instructions while ZF=0 and CX =0
LOOPNE / LOOPNZ (LOOP WHILE CX 0 AND ZF = 0)
LOOP (JUMP TO SPECIFIED LABEL IF CX != 0 AFTER AUTO DECREMENT)
This instruction is used to repeat a series of instructions some number of times. The
number of times the instruction sequence is to be repeated is loaded into CX. Each time the
LOOP instruction executes, CX is automatically decremented by 1. If CX is not 0, execution will
jump to a destination specified by a label in the instruction. If CX = 0 after the auto decrement,
execution will simply go on to the next instruction after LOOP. The destination address for the
jump must be in the range of –128 bytes to +127 bytes from the address of the instruction after
the LOOP instruction. This instruction does not affect any flag.
14 | P a g e UNIT-2 GOGA SUBRAMANYAM

7. Interrupt instructions
1. INT : Interrupt program execution, call service procedure
2. INTO : Interrupt program execution if OF=1
3. IRET : Return from interrupt service procedure to main program
INT – INT TYPE
The term type in the instruction format refers to a number between 0 and 255, which identify the
interrupt. When an 8086 executes an INT instruction, it will
1. Decrement the stack pointer by 2 and push the flags on to the stack.
2. Decrement the stack pointer by 2 and push the content of CS onto the stack.
3. Decrement the stack pointer by 2 and push the offset of the next instruction after the INT
number instruction on the stack.
4. Get a new value for IP from an absolute memory address of 4 times the type specified in the
instruction. For an INT 8 instruction, for example, the new IP will be read from address 00020H.
5. Get a new for value for CS from an absolute memory address of 4 times the type specified in
the instruction plus 2, for an INT 8 instruction, for example, the new value of CS will be read
from address 00022H.
6. Reset both IF and TF. Other flags are not affected.
008Eh
8.Processor control instructions
Flag set/clear instructions
1. STC : Set carry flag CF to 1
2. CLC : Clear carry flag CF to 0
3. CMC : Complement the state of the carry flag CF
4. STD : Set direction flag DF to 1 (decrement string pointers)
5. CLD : Clear direction flag DF to 0
6. STI : Set interrupt enable flag to 1(enable INTR input)
7. CLI : Clear interrupt enable Flag to 0 (disable INTR input)
9). External Hardware synchronization instructions
1).HLT (HALT PROCESSING)
The HLT instruction causes the 8086 to stop fetching and executing instructions. The 8086 will
enter a halt state. The different ways to get the processor out of the halt state are with an interrupt
signal on the INTR pin, an interrupt signal on the NMI pin, or a reset signal on the RESET input.
2).NOP (PERFORM NO OPERATION)
This instruction simply uses up three clock cycles and increments the instruction pointer to point
to the next instruction. The NOP instruction can be used to increase the delay of a delay loop.
When hand coding, a NOP can also be used to hold a place in a program for an instruction that
will be added later. NOP does not affect any flag.
3).ESC (ESCAPE)
This instruction is used to pass instructions to a coprocessor, such as the 8087 Math coprocessor,
which shares the address and data bus with 8086. Instructions for the coprocessor are represented
by a 6-bit code embedded in the ESC instruction.
4). WAIT – WAIT FOR SIGNAL OR INTERRUPT SIGNAL
When this instruction is executed, the 8086 enters an idle condition in which it is doing no
processing. The 8086 will stay in this idle state until the 8086 test input pin is made low or until
an interrupt signal is received on the INTR or the NMI interrupt input pins.
15 | P a g e UNIT-2 GOGA SUBRAMANYAM

1.2ASSEMBLER DIRECTIVES:
Assembler directives are the directions to the assembler which indicate how an operand or
section of the program is to be processed. These are also called pseudo operations which are not
executable by the microprocessor. The various directives are explained below.
1. ASSUME : The ASSUME directive is used to inform the assembler the name of the logical
segment it should use for a specified segment. Ex: ASSUME DS: DATA tells the assembler that
for any program instruction which refers to the data segment ,it should use the logical segment
called DATA.
2.DB -Define byte. It is used to declare a byte variable or set aside one or more storage locations
of type byte in memory. For example, CURRENT_VALUE DB 36H tells the assembler to
reserve 1 byte of memory for a variable named CURRENT_ VALUE and to put the value 36 H
in that memory location when the program is loaded into RAM .
3. DW -Define word. It tells the assembler to define a variable of type word or to reserve storage
locations of type word in memory.
4. DD(define double word) :This directive is used to declare a variable of type double word or
restore memory locations which can be accessed as type double word.
5.DQ (define quadword) :This directive is used to tell the assembler to declare a variable 4
words in length or to reserve 4 words of storage in memory .
6.DT (define ten bytes):It is used to inform the assembler to define a variable which is 10 bytes
in length or to reserve 10 bytes of storage in memory.
7. EQU –Equate It is used to give a name to some value or symbol. Every time the assembler
finds the given name in the program, it will replace the name with the value or symbol we have
equated with that name
8.ORG -Originate : The ORG statement changes the starting offset address of the data.
It allows to set the location counter to a desired value at any point in the program.For example
the statement ORG 3000H tells the assembler to set the location counter to 3000H.
9 .PROC- Procedure: It is used to identify the start of a procedure or subroutine.
10. END- End program .This directive indicates the assembler that this is the end of the program
module.The assembler ignores any statements after an END directive.
11. ENDP- End procedure: It indicates the end of the procedure (subroutine) to the assembler.
12.ENDS-End Segment: This directive is used with the name of the segment to indicate the end
of that logical segment.
Ex: CODE SEGMENT : Start of logical segment containing Code
CODE ENDS : End of the segment named CODE.
13. GLOBAL (DECLARE SYMBOLS AS PUBLIC OR EXTRN)
The GLOBAL directive can be used in place of a PUBLIC directive or in place of an
EXTRN directive. For a name or symbol defined in the current assembly module, the GLOBAL
directive is used to make the symbol available to other modules. The statement GLOBAL
DIVISOR, for example, makes the variable DIVISOR public so that it can be accessed from
other assembly modules
14. PUBLIC
Large program are usually written as several separate modules. Each module is
individually assembled, tested, and debugged. When all the modules are working correctly, their
object code files are linked together to form the complete program. In order for the modules to
link together correctly, any variable name or label referred to in other modules must be declared
PUBLIC in the module in which it is defined. The PUBLIC directive is used to tell the assembler
that a specified name or label will be accessed from other modules.
16 | P a g e UNIT-2 GOGA SUBRAMANYAM

15. EXTRN
The EXTRN directive is used to tell the assembler that the name or labels following the
directive are in some other assembly module. For example, if you want to call a procedure,
which in a program module assembled at a different time from that which contains the CALL
instruction, you must tell the assembler that the procedure is external. The assembler will then
put this information in the object code file so that the linker can connect the two modules
together. For a reference to externally named variable, you must specify the type of the variable,
as in the statement EXTRN DIVISOR: WORD.
16. EVEN (ALIGN ON EVEN MEMORY ADDRESS)
As an assembler assembles a section of data declaration or instruction statements, it uses
a location counter to keep track of how many bytes it is from the start of a segment at any time.
The EVEN directive tells the assembler to increment the location counter to the next even
address,
17. PTR (POINTER)
The PTR operator is used to assign a specific type to a variable or a label. It is necessary
to do this in any instruction where the type of the operand is not clear. When the assembler reads
the instruction INC [BX], for example, it will not know whether to increment the byte pointed to
by BX. We use the PTR operator to clarify how we want the assembler to code the instruction.
The statement INC BYTE PTR [BX] tells the assembler that we want to increment the byte
pointed to by BX. The statement INC WORD PTR [BX] tells the assembler that we want to
increment the word pointed to by BX. The PTR operator assigns the type specified before PTR
to the variable specified after PTR.
18. OFFSET
OFFSET is an operator, which tells the assembler to determine the offset or displacement
of a named data item (variable), a procedure from the start of the segment, which contains it.
When the assembler reads the statement MOV BX, OFFSET PRICES, for example, it will
determine the offset of the variable PRICES from the start of the segment in which PRICES is
defined and will load this value into BX.
19. SEGMENT
The SEGMENT directive is used to indicate the start of a logical segment. Preceding the
SEGMENT directive is the name you want to give the segment. For example, the statement
CODE SEGMENT indicates to the assembler the start of a logical segment called CODE. The
SEGMENT and ENDS directive are used to “bracket” a logical segment containing code of data.
20. LABEL
As an assembler assembles a section of a data declarations or instruction statements, it
uses a location counter to be keep track of how many bytes it is from the start of a segment at
any time. The LABEL directive is used to give a name to the current value in the location
counter. The LABEL directive must be followed by a term that specifics the type you want to
associate with that name. If the label is going to be used as the destination for a jump or a call,
then the label must be specified as type near or type far.
17 | P a g e UNIT-2 GOGA SUBRAMANYAM

1.3Model Programs
Program 2.1 Write a program for addition of two numbers.
Solution
Program

Program 2.2 A program to find out the largest number, from a given unordered array of a 8-bit
numbers, stored in the locations starting from a known address.
18 | P a g e UNIT-2 GOGA SUBRAMANYAM

Program 2.3 A program to find out the number of even and odd numbers from a given series of
16-bit hexadecimal numbers.

Program 2.4 Write a program to find out the number of positive numbers and negative numbers
from given series of signed numbers
Solution :Take the ith number in any of the registers. Rotate it left through carry. The status of
carry flag i.e. the most significant bit of the number will give the information about the sign of
the number. if CF is 1, the number is negative; otherwise, it is positive.
19 | P a g e UNIT-2 GOGA SUBRAMANYAM

Program 2.5 Write a program to move a string of data words from offset 2000H to offset 3000H
the length of the string is OFH.
Solution To write this program, we will use an important facility, available in the 8086
instruction set, i.e move string byte/word instruction. We will also study the flexibility imparted
by this instructions to the 8086 assembly language program. Due to the assembler directives and
the syntax, one may feel that the program is lengthy, though it eliminates four instructions for a
MOVSW instruction.

Program 2.6 Write an assembly language program to arrange a given series of hexadecimal
bytes in ascending order.
20 | P a g e UNIT-2 GOGA SUBRAMANYAM

With a similar approach, the reader may write a program to arrange the string in descending
order. Just instead of the JL instruction in the above program, one will have to use a JG
instruction.
1.4Assembly Language Program Development Tools:
EDITOR
An editor is a program, which allows you to create a file containing the assembly
language statements for your program. As you type in your program, the editor stores the
ASCII codes for the letters and numbers in successive RAM locations. When you have typed
in all of your programs, you then save the file on a floppy of hard disk. This file is called
source file. The next step is to process the source file with an assembler. In the TASM
assembler, you should give your source file name the extension, .ASM
ASSEMBLER
An assembler program is used to translate the assembly language mnemonics for
instructions to the corresponding binary codes. When you run the assembler, it reads the
source file of your program the disk, where you saved it after editing on the first pass
through the source program the assembler determines the displacement of named data
items, the offset of labels and pails this information in a symbol table. On the second
pass through the source program, the assembler produces the binary code for each
instruction and inserts the offset etc that is calculated during the first pass. The assembler
generates two files on floppy or hard disk. The first file called the object file is given the
extension. OBJ. The object file contains the binary codes for the instructions and
information about the addresses of the instructions.
LINKER
A linker is a program used to join several object files into one large object file and
convert to an exe file. The linker produces a link file, which contains the binary codes for
all the combined modules. The linker however doesn’t assign absolute addresses to the
program, it assigns is said to be relocatable because it can be put anywhere in memory to
be run. In TASM, TLINK source filename is used to link the file.
DEBUGGER
A debugger is a program which allows you to load your object code program into
system memory, execute the program and troubleshoot are debug it the debugger allows you
to look at the contents of registers and memory locations after your program runs. It
allows you to change the contents of register and memory locations after your program
runs. It allows you to change the contents of register and memory locations and return the
program. A debugger also allows you to set a break point at any point in the program. If you
inset a breakpoint the debugger will run the program upto the instruction where the
breakpoint is set and stop execution. You can then examine register and memory contents
to see whether the results are correct at that point. In TASM, td filename is issued to debug
the file.
Before staring the process ensure that all the files namely, TASM, .EXE, LINK .EXE,
DEBUG. EXE
Are available in the same directory which is working .
Edit: Edit the assembler to enter the program
Save the files with. .ASM.
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
OPR1 DW 1234H
OPR DW 0002H
RESULT DW 01H DUP ?
21 | P a g e UNIT-2 GOGA SUBRAMANYAM

DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV AX, OPR1
MOV BX, OPR2
CLC
ADD AX, BX
MOV DI, OFFSET RESULT
MOV DI, AX
MOV AH, 4CH
INT 03H
CODE ENDS.
END START.
 The TASM accepts the file names only with the extension .ASM and generate OBJ file.
 The TASM linking program LINK.EXE .links the different object modules of a source
program and function library routines to generate an integrated executable code of the source
program. The main input to the linker is the .OBJ file that contains the object modules of the
source program.
 Debug .Exe facilitates the debugging and trouble shooting of assembly language program. The
debug utility enables to have the control these resources unto some extent.
TASM file name. ASM
TLINK file name.OBJ
Debug file name.EXE
1.5Addressing Modes OF 8086:
 Addressing mode provide different ways for access an address to given data to a
processor.
 When 8086 executes an instruction, it performs the specified function on data. Operated
data is stored in the memory location. There are various techniques to specify address of
data. These techniques are called Addressing Modes.
Addressing Modes: Definition and classification Classification of Addressing Modes:
1).Data-Addressing Modes:
This mode is related to data transfer operation, that is, data is transferred either from the memory
to internal registers of 8086 processors or from one register to another register.
Example: MOV AX, DX
 Register Addressing
 Immediate Addressing
 Direct Addressing
 Register Indirect Addressing
 Base–Plus–Index Addressing
 Register Relative Addressing
 Base Relative–Plus–Index Addressing
2).Program Memory addressing Modes:
This mode involves program memory addresses during various operations.
Example: JMP AX, in this instruction, the code execution control jumps to the current code
segment location addressed by the contents of AX register.
3).Stack memory addressing Modes:
This mode involves stack registry operations.
Example: PUSH AX, this instruction copies the contents of AX register to the stack.
22 | P a g e UNIT-2 GOGA SUBRAMANYAM

1.Register addressing

 Register addressing transfers a copy of a byte or word from the source register to
destination register. Register addressing is the most common form of data addressing and
once the register names are learned, is the easiest to apply.
 8-bit register names with register addressing: AH, AL, BH, BL, CH, CL, DH, DL.
 16-bit register names: AX, BX, CX, DX, SP, BP, SI ,DI, IP, CS, SS, DS and ES.
 Never mix an 8-bit register with 16-bit, it is not allowed in microprocessor.
 Code segment register (CS) is never used as destination.
 Segment to segment MOV instruction is not allowed.
Example: MOV AL, BL ; Copies 8-bit content of BL into AL
MOV AX, CX ; Copies 16-bit content of CX into AX
MOV EX, DS ; Not allowed (segment to segment)
MOV BL, DX ; Not allowed (mixed size)
MOV CS, AX ; Not allowed (Code segment register may not be destination
register)
2. Immediate addressing
 Immediate addressing transfers the source, an immediate byte or word data, into the
destination register.
 Immediate data means constant data, whereas data transferred from a register or memory
location are variable data.
 Immediate addressing mode can be used to load information into any of the registers
except the segment registers and flag registers..
Example: MOV BL, 44 ; Copies 44 decimal (2CH) into BL
MOV AX, 44H ; Copies 0044H into AX
MOV AL, ‘A’ ; Copies ASCII A into AL

3. Direct data addressing


 Direct addressing moves a byte or word between a data segment memory location and
register.
 The instruction set does not support a memory to memory transfer except with the MOVS
instruction.
 This address is the offset address
 The physical address is calculated by combining the contents of offset location 2400 with
DS
Example: MOV AX,, [2400] ; move contents of DS:2400H into AX
4.Register Indirect addressing
 Register addressing transfers a byte or word between a register and memory location
addressed by an index or base register.
 The index and base registers are BP, BX, DI and SI. These registers hold the offset
address of the memory location.
 The data segment is used by default with register indirect addressing or any other
addressing modes that uses BX, DI or, SI to address memory.
 If BP register addresses memory, the stack segment is used by default.
23 | P a g e UNIT-2 GOGA SUBRAMANYAM

 The [ ] symbol denote memory addressing in assembly language.


 Example: MOV CL, [BX] ; Copies the byte contents of the data segment memory
location addressed by BX into CL.

Operation of MOV AX, [BX] instruction

5. Base-Plus-Index addressing
 Base-plus-index addressing transfer a byte or word between a register and a memory
location addressed by a base register (BP or BX) plus an index register (DI or SI).
 The base register often holds the beginning location of a memory array, whereas the
index register holds the relative position of an element in the array.
 When BP addresses memory, stack segment is selected by default and when BX
addresses memory data segment is selected by default.
Example: MOV CX, [BX+DI] ; Copies the word content of the data segment memory
location addressed by BX plus DI into CX.
MOV [BP+DI], AH ; Copies AH into stack segment memory location addressed by BP
plus DI

Operation of MOV AX, [BX+DI] instruction


24 | P a g e UNIT-2 GOGA SUBRAMANYAM

6.Register Relative addressing


 Register relative addressing moves a byte or word between a register and the memory
location addressed by an index or base register (BP, BX, DI or SI) plus a displacement.
 Remember that BX, DI or SI addresses data segment and BP addresses the stack segment.
Example: MOV AX, [DI+100H] ; Copies the word content of the data segment memory location
addressed by DI plus 100H into AX.
MOV ARRAY[SI], BL ; Copies BL into the data segment memory location addressed
by ARRAY plus SI

Operation of MOV AX, [BX+07H] instruction

7.Base Relative plus Index addressing


 Base relative plus index addressing transfers a byte or word between a register and a
memory location addressed by a base and an index register plus displacement.
 It is similar to base plus index addressing, but it adds a displacement beside using a base
register and an index register.
 This type of addressing mode often addresses a two-dimensional array of memory data.
Example: MOV DH, [BX+DI+20H] ; Copies the byte content of data segment memory location
addressed by the sum of BX, DI and 20H into DH.
MOV LIST[BP+DI], CL ; Copies CL into the stack segment memory location
addressed by the sum of LIST, BP, SI and 4.

You might also like