You are on page 1of 46

Module 2

Instruction Set And Programming


• The 8086 Instruction 8086 Instruction Format vary from 1 to 6 bytes in length. Fig. 6.8 shows the
instruction formats for 1 to 6 bytes instructions. As shown in the Fig. 6.8, displacements and
operands may be either 8-bits or 16-bits long depending on the instruction. The opcode and the
addressing mode is specified using first two bytes of an instruction.
• The opcode/addressing mode byte(s) may be followed by :
• No additional byte
• Two byte EA (For direct addressing only).
• One or two byte displacement
• One or two byte immediate operand
• One or two byte displacement followed by a one or two byte immediate operand
• Two byte displacement and a two byte segment address (for direct intersegment addressing
only).
Most of the opcodes in 8086 has a special 1-bit indicates. They are :
• W-bit : Some instructions of 8086 can operate on byte or a word. The W-bit in the opcode of such
instruction specify whether instruction is a byte instruction (W = 0) or a word instruction (W = 1).
• D-bit : The D-bit in the opcode of the instruction indicates that the register specified within the
instruction is a source register (D = 0) or destination register (D =1).
• S-bit : An 8-bit 2’s complement number can be extended to a 16-bit 2’s complement number by
making all of the bits in the higher-order byte equal the most significant bit in the low order byte.
This is known as sign extension.
The S-bit along with the W-bit indicate :

V-bit : V-bit decides the number of shifts for rotate and shift instructions. If V = 0, then
count = 1; if V = 1, the count is in CL register. For example, if V = 1 and CL = 2 then shift
 or rotate instruction shifts or rotates 2-bits.

Z-bit : It is used for string primitives such as REP for comparison with ZF Flag.

If an instruction has two opcode /addressing mode bytes, then the second byte is of one
of the following two forms .
where Mod, Reg and R/M fields specify operand as described in the following tables:
Addressing Modes Of 8086:
• Addressing mode indicates a way of locating data or operands. Depending up on the data type used in the
instruction and the memory addressing modes, any instruction may belong to one or more addressing modes or
same instruction may not belong to any of the addressing modes.

• The addressing mode describes the types of operands and the way they are accessed for executing an
instruction. According to the flow of instruction execution, the instructions may be categorized as

1. Sequential control flow instructions and


2. Control transfer instructions.

• Sequential control flow instructions are the instructions which after execution, transfer control to the next
instruction appearing immediately after it (in the sequence) in the program. For example the arithmetic, logic,
data transfer and processor control instructions are Sequential control flow instructions.

• The control transfer instructions on the other hand transfer control to some predefined address or the address
somehow specified in the instruction, after their execution. For example INT, CALL, RET & JUMP instructions
fall under this category.
The addressing modes for Sequential and control flow instructions are
explained as follows:

1.Immediate addressing mode:

In this type of addressing, immediate data is a part of instruction, and appears in the form of
successive byte or bytes.
Example: MOV AX, 0005H.
In the above example, 0005H is the immediate data. The immediate data may be 8- bit or 16-bit in size.

2.Direct addressing mode:


In the direct addressing mode, a 16-bit memory address (offset) directly specified in the instruction as a
part of it.
Example: MOV AX, [5000H].
3.Register addressing mode:

In the register addressing mode, the data is stored in a register and it is referred using the particular
register. All the registers, except IP, may be used in this mode.
Example: MOV BX, AX
4.Register indirect addressing mode:

Sometimes, the address of the memory location which contains data or operands is determined in an
indirect way, using the offset registers. The mode of addressing is known as register indirect mode.
In this addressing mode, the offset address of data is in either BX or SI or DI Register. The default segment
is either DS or ES.

Example: MOV AX, [BX].

5.Indexed addressing mode:


In this addressing mode, offset of the operand is stored one of the index registers. DS & ES are the default
segments for index registers SI & DI respectively.
Example: MOV AX, [SI]
Here, data is available at an offset address stored in SI in DS.

6.Register relative addressing mode:


In this addressing mode, the data is available at an effective address formed by adding an 8-bit or 16-bit displacement with the
content of any one of the register BX, BP, SI & DI in the default (either in DS & ES) segment.
Example: MOV AX, 50H [BX]
7.Based indexed addressing mode:

The effective address of data is formed in this addressing mode, by adding content of a base register
(any one of BX or BP) to the content of an index register (any one of SI or DI). The default segment
register may be ES or DS.

Example: MOV AX, [BX][SI]

8.Relative based indexed:

The effective address is formed by adding an 8 or 16-bit displacement with the sum of contents of
any
of the base registers (BX or BP) and any one of the index registers, in a default segment.
Example: MOV AX, 50H [BX] [SI]
Addressing Modes for control transfer instructions:
1.Intersegment direct:

In this mode, the address to which the control is to be transferred is in a different segment. This addressing
mode provides a means of branching from one code segment to another code segment. Here, the CS and
IP of the destination address are specified directly in the instruction.
Example: JMP 5000H, 2000H; jump to effective address 2000H in segment 5000H.

2.Intersegment indirect:

In this mode, the address to which the control is to be transferred lies in a different segment and it is passed
to the instruction indirectly, i.e. contents of a memory block containing four bytes, i.e. IP(LSB),
IP(MSB), CS(LSB) and CS(MSB) sequentially. The starting address of the memory block may be referred
using any of the addressing modes,except immediate mode.
Example: JMP [2000H].
Jump to an address in the other segment specified at effective address 2000H in DS.
3.Intrasegment direct mode:

In this mode, the address to which the control is to be transferred lies in the same segment in which the control
transfers instruction lies and appears directly in the instruction as an immediate displacement value. In this
addressing mode, the displacement is computed relative to the content of the instruction pointer.
The effective address to which the control will be transferred is given by the sum of 8 or 16 bit displacement and
current content of IP. In case of jump instruction, if the signed displacement (d) is of
8-bits (i.e. -128<d<+127), it as short jump and if it is of 16 bits (i.e. -32768<d<+32767), it is termed as long jump.
Example: JMP SHORT LABEL.

• Intrasegment indirect mode:

In this mode, the displacement to which the control is to be transferred is in the same segment in which the
control transfer instruction lies, but it is passed to the instruction directly. Here, the branch address is found as
the content of a register or a memory location.
This addressing mode may be used in unconditional branch instructions.
Example: JMP [BX]; Jump to effective address stored in BX.
Instruction set of 8086:
The 8086 microprocessor supports 8 types of instructions −
•Data Transfer Instructions
•Arithmetic Instructions
•Bit Manipulation Instructions
•String Instructions
•Program Execution Transfer Instructions (Branch & Loop Instructions)
•Processor Control Instructions
•Iteration Control Instructions
•Interrupt Instructions
Data Transfer Instructions:

These instructions are used to transfer the data from the source operand to the destination operand.
Following are the list of instructions under this group −

Instruction to transfer a word-


•MOV − Used to copy the byte or word from the provided source to the provided destination.
•PPUSH − Used to put a word at the top of the stack.
•POP − Used to get a word from the top of the stack to the provided location.
•PUSHA − Used to put all the registers into the stack.
•POPA − Used to get words from the stack to all registers.
•XCHG − Used to exchange the data from two locations.
•XLAT − Used to translate a byte in AL using a table in the memory.
Instructions for input and output port transfer-
• IN − Used to read a byte or word from the provided port to the accumulator.
• OUT − Used to send out a byte or word from the accumulator to the provided port.

Instructions to transfer the address-


• LEA − Used to load the address of operand into the provided register.
• LDS − Used to load DS register and other provided register from the memory
• LES − Used to load ES register and other provided register from the memory.

Instructions to transfer flag registers-


• LAHF − Used to load AH with the low byte of the flag register.
• SAHF − Used to store AH register to low byte of the flag register.
• PUSHF − Used to copy the flag register at the top of the stack.
• POPF − Used to copy a word at the top of the stack to the flag register.
Arithmetic Instructions:
These instructions are used to perform arithmetic operations like addition, subtraction, multiplication, division, etc.
Following is the list of instructions under this group −
Instructions to perform addition-
•ADD − Used to add the provided byte to byte/word to word.
•ADC − Used to add with carry.
•INC − Used to increment the provided byte/word by 1.
•AAA − Used to adjust ASCII after addition.
•DAA − Used to adjust the decimal after the addition/subtraction operation.

Instruction to perform multiplication -


•MUL − Used to multiply unsigned byte by byte/word by word.
•IMUL − Used to multiply signed byte by byte/word by word.
•AAM − Used to adjust ASCII codes after multiplication.
Instructions to perform subtraction-
•SUB − Used to subtract the byte from byte/word from word.
•SBB − Used to perform subtraction with borrow.
•DEC − Used to decrement the provided byte/word by 1.
•NPG − Used to negate each bit of the provided byte/word and add 1/2’s complement.
•CMP − Used to compare 2 provided byte/word.
•AAS − Used to adjust ASCII codes after subtraction.
•DAS − Used to adjust decimal after subtraction.

Instructions to perform division-


•DIV − Used to divide the unsigned word by byte or unsigned double word by word.
•IDIV − Used to divide the signed word by byte or signed double word by word.
•AAD − Used to adjust ASCII codes after division.
•CBW − Used to fill the upper byte of the word with the copies of sign bit of the lower byte.
•CWD − Used to fill the upper word of the double word with the sign bit of the lower word.
Bit Manipulation Instructions:

These instructions are used to perform operations where data bits are involved, i.e. operations like
logical, shift, etc.
Following is the list of instructions under this group −
Instructions to perform logical operation-
•NOT − Used to invert each bit of a byte or word.
•AND − Used for adding each bit in a byte/word with the corresponding bit in another byte/word.
•OR − Used to multiply each bit in a byte/word with the corresponding bit in another byte/word.
•XOR − Used to perform Exclusive-OR operation over each bit in a byte/word with the corresponding
bit in another byte/word.
•TEST − Used to add operands to update flags, without affecting operands.
Instructions to perform shift operations-
•SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in LSBs.
•SHR − Used to shift bits of a byte/word towards the right and put zero(S) in MSBs.
•SAR − Used to shift bits of a byte/word towards the right and copy the old MSB into the new MSB.

Instructions to perform rotate operations-


•ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to Carry Flag [CF].
•ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and to Carry Flag [CF].
•RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to MSB.
String Instructions:
String is a group of bytes/words and their memory is always allocated in a sequential order.
Following is the list of instructions under this group −
•REP − Used to repeat the given instruction till CX ≠ 0.
•REPE/REPZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
•REPNE/REPNZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
•MOVS/MOVSB/MOVSW − Used to move the byte/word from one string to another.
•COMS/COMPSB/COMPSW − Used to compare two string bytes/words.
•INS/INSB/INSW − Used as an input string/byte/word from the I/O port to the provided memory
•location.
•OUTS/OUTSB/OUTSW − Used as an output string/byte/word from the provided memory location to
•the I/O port.
•SCAS/SCASB/SCASW − Used to scan a string and compare its byte with a byte in AL or string word
with a word in AX.
•LODS/LODSB/LODSW − Used to store the string byte into AL or string word into AX.
Program Execution Transfer Instructions (Branch and Loop
Instructions):
These instructions are used to transfer/branch the instructions during an execution. It includes the
following instructions −
Instructions to transfer the instruction during an execution without any condition −
•CALL − Used to call a procedure and save their return address to the stack.
•RET − Used to return from the procedure to the main program.
•JMP − Used to jump to the provided address to proceed to the next instruction.
•Instructions to transfer the instruction during an execution with some conditions −
•JA/JNBE − Used to jump if above/not below/equal instruction satisfies.
•JAE/JNB − Used to jump if above/not below instruction satisfies.
•JBE/JNA − Used to jump if below/equal/ not above instruction satisfies.
•JC − Used to jump if carry flag CF = 1
• JE/JZ − Used to jump if equal/zero flag ZF = 1
• JG/JNLE − Used to jump if greater/not less than/equal instruction satisfies.
• JGE/JNL − Used to jump if greater than/equal/not less than instruction satisfies.
• JL/JNGE − Used to jump if less than/not greater than/equal instruction satisfies.
• JLE/JNG − Used to jump if less than/equal/if not greater than instruction satisfies.
• JNC − Used to jump if no carry flag (CF = 0)
• JNE/JNZ − Used to jump if not equal/zero flag ZF = 0
• JNO − Used to jump if no overflow flag OF = 0
• JNP/JPO − Used to jump if not parity/parity odd PF = 0
• JNS − Used to jump if not sign SF = 0
• JO − Used to jump if overflow flag OF = 1
• JP/JPE − Used to jump if parity/parity even PF = 1
• JS − Used to jump if sign flag SF = 1
Processor Control Instructions:

These instructions are used to control the processor action by setting/resetting the flag values.
Following are the instructions under this group −
•STC − Used to set carry flag CF to 1
•CLC − Used to clear/reset carry flag CF to 0
•CMC − Used to put complement at the state of carry flag CF.
•STD − Used to set the direction flag DF to 1
•CLD − Used to clear/reset the direction flag DF to 0
•STI − Used to set the interrupt enable flag to 1, i.e., enable INTR input.
•CLI − Used to clear the interrupt enable flag to 0, i.e., disable INTR input.
Iteration Control Instructions:

These instructions are used to execute the given instructions for number of times. Following is the list
of instructions under this group −
•LOOP − Used to loop a group of instructions until the condition satisfies, i.e., CX = 0
•LOOPE/LOOPZ − Used to loop a group of instructions till it satisfies ZF = 1 & CX = 0
•LOOPNE/LOOPNZ − Used to loop a group of instructions till it satisfies ZF = 0 & CX = 0
•JCXZ − Used to jump to the provided address if CX = 0
Interrupt Instructions:

These instructions are used to call the interrupt during program execution.
•INT − Used to interrupt the program during execution and calling service specified.
•INTO − Used to interrupt the program during execution if OF = 1
•IRET − Used to return from interrupt service to the main program
Assembler Directives:
• Assembly language: low-level languages forprogramming computers,microprocessors,
microcontrollers, and other IC.
• Assembler Directive: a statement to give direction to the assembler to perform task of the assembly
process.
control the organization of the program.
provide necessary information to the assembler to understand ALPs
and generate necessary machine codes.
Indicate how an operand or a section of the program is to be processed by the assembler
• Consists of two types of statements: instructions and directives
Instructions: translated to the machine code by the assembler
Directives are not translated to the machine codes
Important terms and rules:
• SYMBOLS: to signify different components of the ALP (assembly LanguageProgram)
Symbols consist of following characters:-
Upper case & lower case alphabets: A to Z; a to z
Digits: 0 to 9
Special characters: $, ?, @, _ (underscore)
No distinction between an uppercase and lowercase letter
A hexadecimal no. starting with A to F must begin with “0” (zero) ; otherwise will be taken as a symbol
• VARIABLE: these are symbols whose values can be varied while running a program
Names of variables: should be meaningful to make program maintenance easy
A variable can use: A to Z; a to z; 0 to 9; @; _ (underscore)
Digit can not be used as 1st character of an Assembler variable
• CONSTANT: these are symbols whose values can not be varies while running a program
A numeric constant may be a binary, decimal or hexadecimal number.
Symbols B, D & H must be used at the end of a binary, decimal and hexadecimal number,
respectively.
Important Assembler Directives of the 8086 Microprocessor:
• Data declaration directives: DB, DW, DD, DQ, DT
• ASSUME
• END directives
• EQU Directive
• PROC
• ORG
• SEGMENT
• GROUP, INCLUDE, EVEN, ALIGN
• EXTRN, PUBLIC,
• TYPE, PTR,
• LENGTH, OFFSET
• NAME, LABEL, SHORT, GLOBAL
Data declaration directives:
1. DB
The DB directive is used to declare a BYTE -2-BYTE variable - A BYTE is made up of 8 bits.
Examples:
• PRICES DB 49H, 98H, 29H; Declare array of 3 bytes named PRICES and initialize them with specified values.
2. DW
The DW directive is used to declare a WORD type variable - A WORD occupies 16 bits or (2 BYTE).
Examples:
• WORDS DW 1234H, 3456H; Declares an array of 2 words and initialize them with the specified values
3. DD
The DD directive is used to declare a DWORD - A DWORD double word is made up of
32 bits =2 Word's or 4 BYTE.
Examples:
• ARRAY DD 25629261H; This will define a double word named ARRAY and initialize the double word with the
specified value when the program is loaded into memory to be run. The low word, 9261H, will be put in memory
at a lower address than the high word.
4.DQ (DEFINE QUADWORD)
The DQ directive is used to tell the assembler to declare a variable 4 words in length or to reserve 4
words of storage in memory.
Example:
•BIG_NUMBER DQ 243598740192A92BH; This will declare a variable named BIG_NUMBER and
initialize the 4 words set aside with the specified number when the program is loaded into memory
to be run.

5.DT (DEFINE TEN BYTES)


The DT directive is used to tell the assembler to declare a variable, which is 10 bytes in length or to
reserve 10 bytes of storage in memory.
Example:
•PACKED_BCD DT 11223344556677889900
This will declare an array named PACKED_BCD, which is 10 bytes in length. It will initialize
the 10 bytes with the values 11, 22, 33, 44, 55, 66, 77, 88, 99, and 00 when the program is
loaded into memory to be run. The statement RESULT DT 20H DUP (0) will declare an
array of 20H blocks of 10 bytes each and initialize all 320 bytes to 00 when the program is
loaded into memory to be run.
Assume Directive:

ASSUME Directive
The ASSUME directive is used to tell the assembler that the name of the logical segment should be
used for a specified segment. The 8086 works directly with only 4 physical segments: a Code
segment, a data segment, a stack segment, and an extra segment.
Example:
• ASSUME CS:CODE ;This tells the assembler that the logical segment named CODE contains the
instruction statements forthe program and should be treated as a code segment.
• ASSUME DS:DATA ;This tells the assembler that for any instruction which refers to a data in the data
segment, data will found in the logical segment DATA.
End Directive:

• END - End Program


• ENDP - End Procedure
• ENDS - End Segment
• END – it signifies the end of the program module
The assembler will ignore any statement after an END directive
• ENDP - indicates the end of a procedure
Syntax: Procedure_name ENDP
• ENDS - indicates the end of a logical segment
Syntax: Segment_name ENDS
Equate (EQU) Directive:

This EQU directive is used to give a name to some value or to a symbol. Each time the assembler
finds the name in the program, it will replace the name with the value or symbol you given to that
name.
Example:
FACTOR EQU 03H ; you have to write this statement at the starting of your program
later in the program you can use this as follows :
ADD AL, FACTOR ; When it codes this instruction the assembler will code it as ADDAL, 03H ;
The advantage of using EQU in this manner is, if FACTOR is used many no of times in a program and
you want to change the value, all you had to do is change the EQU statement at beginning, it will
changes the rest of all.
PROC (Procedure) Directive:

PROC - The PROC directive is used to identify the start of a procedure. The term near or far is used
to specify the type of the procedure.
Example:
• SMART PROC FAR ; This identifies that the start of a procedure named as SMART and instructs the
assembler that procedure is far .
• SMART ENDP ; This PROC is used with ENDP to indicate the break of the procedure.
ORG (ORIGIN):

• ORG Changes the starting offset address of the data in the data segment. As an assembler
assembles a section of a data declarations 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 location counter is automatically set to 0000 when assembler starts reading a segment.
• The ORG directive allows you to set the location counter to a desired value at any point in the
program.
Example:
• The statement ORG 2000H tells the assembler to set the location counter to 2000H.
SEGMENT:

SEGMENT directive : to indicate the start of a logical segment.


• Syntax: Segment_name SEGMENT
• Additional terms are often added to a SEGMENT directive statement to indicate some special way in
which we want the assembler to treat the segment.
Example:
• CODE SEGMENT WORD ; tells the assembler that we want the content of this segment located on
the next available word (even address) when segments are combined and given absolute addresses.
• Without this WORD addition, the segment will be located on the next available paragraph (16-byte)
address, which might waste as much as 15 bytes of memory.
• The statement CODE SEGMENT PUBLIC tells the assembler that the segment may be put together
with other segments named CODE from other assembly modules when the modules are linked
together.
GROUP, INCLUDE, EVEN, ALIGN:

GROUP - used to group the logical segments named after the directive into one logical group
segment.
INCLUDE - used to insert a block of source code from the named file into the current source module.
EVEN - instructs the assembler to increment the location of the counter to the next even address if it is
not already in the even address.
If the word is at even address 8086 can read a memory in 1 bus cycle. If the word starts at an odd
address, the 8086 will take 2 bus cycles to get the data.
A series of words can be read much more quickly if they are at even address. When EVEN is used
the location counter will simply incremented to next address and NOP instruction is inserted in that
incremented location.
• ALIGN: Memory array is stored in word boundaries.
Example:
• ALIGN 2 means storing from an even address
EXTRN, PUBLIC:

EXTRN : 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. The statement EXTRN DIVIDE: FAR tells the assembler that
DIVIDE is a label of type FAR in another assembler module. Name or labels referred to as external in
one module must be declared public with the PUBLIC directive in the module in which they are
defined.
PUBLIC :The PUBLIC directive is used to instruct the assembler that a specified name or label will be
accessed from other modules.
Example:
• PUBLIC DIVISOR, DIVIDEND ;these two variables are public so these are available to all modules. If
an instruction in a module refers to a variable in another assembly module, we can access that
module by declaring as EXTRN directive.
TYPE, PTR(POINTER):

TYPE - instructs the assembler to determine the type of a variable and determines the number of bytes
specified to that variable.
Example:
• Byte type variable – assembler will give a value 1 Word type variable – assembler will give a value 2
Double word type variable – assembler will give a value 4 ADD BX, TYPE WORD_ ARRAY ; hear we want
to increment BX to point to next word in an array of words.

PTR (POINTER) : 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.
Example:
• INC [BX]; 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.
• INC BYTE PTR [BX] ; This statement tells the assembler that we want to increment the byte pointed to by
BX.
• INC WORD PTR [BX] ; This statement 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.
LENGTH, OFFSET:

LENGTH : tells the assembler to determine the number of elements in some named data item, such
as a string or an array.
Example:
• MOV CX, LENGTH STRING1; This will determine the number of elements in STRING1 and load it
into CX. If the string was declared as a string of bytes, LENGTH will produce the number of bytes in
the string. If the string was declared as a word string, LENGTH will produce the number of words in
the string.

OFFSET : 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.
Example:
• MOV BX, OFFSET PRICES; 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.
NAME, LABEL, SHORT, GLOBAL:
NAME : used to give a specific name to each assembly module when programs consisting of several modules are
written.
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.
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.
SHORT:The SHORT operator is used to tell the assembler that only a 1 byte displacement is needed to code a jump
instruction in the program. The destination must in the range of – 128 bytes to +127 bytes from the address of the
instruction after the jump.
Example: JMP SHORT NEARBY_LABEL
GLOBAL (DECLARE SYMBOLS AS PUBLIC OR EXTRN) : 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.
Example:
•GLOBAL DIVISOR
This statement makes the variable DIVISOR public so that it can be accessed from other assembly modules.
8086 Programming using Assembler Directives:
Basic structure of a program:
Name_data segment SEGMENT
Data declaration statement 1
:
:
Data declaration statement n
DATA ENDS
Name_codeseg SEGMENT
ASSUME CS:CODE, DS:DATA, ES:EXTRA, SS: STACK
START:
Program line 1
:
:
Program line n
Name_codeseg ENDS
END START
Example:
Program to multiply 2 16-bit words in memory locations called MULTIPLICAND and MULTIPLIER. Result is stored in memory location PRODUCT.
DATA SEGMENT
MULTIPLICAND DW 204A H; 1ST Word
MULTIPLIER DW 3B2A H; 2nd word
PRODUCT DW 2 DUP(0); sets aside storage for 2 words in memory and gives starting address of 1st word the name PRODUCT.
The DUP(0) part of the statement tells assembler to initialize 2 words to all zeros.
DATA ENDS
CODE SEGMENT
ASSUMER CS:CODE, DS:DATA;
START:
MOV AX, DATA
MOV DS, AX
MOV AX, MULTIPLICAND;
MUL MULTIPLIER;
MOV PRODUCT, AX;
MOV PRODUCT+2, DX;
INT3
CODE ENDS
END START

You might also like