Mpmc Notes 3
Mpmc Notes 3
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
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
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
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.
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.
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
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. 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
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