Sie sind auf Seite 1von 38

Unit -2 8086 family assembly language

programming.
Syllabus
 8086 family assembly language programming.
 Instruction templates.

 MOV instruction coding format.


 MOV instruction coding examples.

 Writing programs for use with an assembler.

 Assembly language program development tools.

Introduction

Each microprocessor is provided with instruction set (different type of instructions


available) instruction format, addressing mode, assembler directives and other
details.
 One has to learn this to write programs for the processor.
 Developing program however requires more than just writing instructions.
Steps for learning any programming language
 Learn few useful commands/ instructions and use them in writing programs.
 Learn how data can be read, written and displayed.
 Learn to move data from one place to another within computer.
 Perform arithmetic and logical operation.
 Learn control instructions (conditional operation)
 Learn iterative operation instruction (loops)

8086 family assembly language programming


 Defining problem or task is the first step of programming.
 One must think what the program is required to do.
 One must write in pseudo language what operation is required in the program

Example: program to find largest number.


 Read number ( It can be from mem/reg or input device)
 Compare each number stored in mem/reg.
 Store the max number (in mem/reg)

Instruction Template(format)

 A machine language instruction format has one or more fields associated with it.
 The first field is called as Operation code field or opcode field. Which indicate type of
operation to be performed.
 The other fields are called operand fields which contains data/information.and
instruction is executed using these fields.

Example: MOV reg/mem


(8 gpr + 24 add (oo,01,10) 32 ways+32 ways source/destination

They are two types of instruction:-


 Sequential control flow instructions are the instructions where control is
transferred to the next instruction after execution of the current instruction.
 Example, arithmetic, logical, data transfer and processor control
instructions are sequential control flow instructions.
 The control transfer instructions, on the other hand, transfer control to
some other predefined address and the address from where the execution
starts is given in the instruction or it is implicit.
 Example, INT, CALL, RET and JUMP instructions.

 The 8086 instructions are categorized into the following main types:-
 Data copy instructions
 Arithmetic and Logical Instructions
 Branch Instructions
 Loop instructions
 M/c control instructions
 Flag manipulation instructions
 Shift and rotate instructions
 String instructions.

Operand Types
 Three basic types of operands:
 Immediate – a constant integer (8, 16, or 32 bits)
value is encoded within the instruction

 Register – the name of a register


register name is converted to a number and encoded within the instruction

 Memory – reference to a location in memory (memory address is encoded


within the instruction, or a register holds the address of a memory
location)
DIRECT MEMORY OPERANDS
Ex- MOV ax,[1234h] or MOV ax,n1
 A direct memory operand is a named reference to storage in memory
 The named reference (label) is automatically dereferenced by the assembler

8086 Instruction Formats (nine)


1)One Byte Instruction
1. -all bits represent opcode(ex-CLD)

2. -only 5 bit represent opcode and 3bits represent register(ex-INC BX)

 This format is only one byte long.


 The least significant 3-bits of the opcode are used for specifying the register
operand, if any.
 Otherwise, all the 8-bits form an opcode and the operands are implied.

Example:
 CLD (Clear direction f lag)
-All 8bits represents opcode
opcode
8 bit
 INR ax, POP BX
-5 bit represent opcode and 3 least significant bit represents register

opcode register
5 bit

2)Two Byte instructions


1. Register to register- 2 byte
2. Register to memory with no displacement-2 byte

 1st byte-opcode with direction and word length

 2nd byte-whether operation is register to register/register to memory or memory to


register

 3rd byte and 4 th byte optional depends on addressing mode of memory


First byte indicate opcode.
 Bit D indicates source or destination register REG field of byte 2, 0 for source and
 1 for destination.
 Bit W indicates width of operand, byte or word operation, 0 for byte and 1 for
word operand.
 Remaining six bit D2 to D7 indicates opcode.
 Hence (26)64 different opcode can be generated.

Second Byte indicate whether the operation is

o Reg to Reg
o Memory to Register
o Register to Memory.

Note:-Memory to Memory operation are not provided.


Opcode D W MOD REG R/M

Ex- MOV CX,AX

Opcode D W MOD REG R/M


100010 1 1 11 001 000
=8BC8H

EX-MOV [SI],AX

Opcode D W MOD REG R/M


100010 0 1 00 000 100
=8904H
3)Three Byte Instructions (register to memory/memory to register)with 8 bit
displacement
1. Register to memory with 8 bit displacement-3 byte

2. 1st byte-opcode with direction and word length

3. 2nd byte-whether operation is register to register/register to memory or memory to


register

4. 3rd byte represent the 8 bit displacement

8 bit Displacement

7 0

EX-MOV AX,34H[SI]

Opcode D W MOD REG R/M 8 BIT


DISPLACEMENT
100010 1 1 01 000 100 00110100
=8B4434H
First byte indicate opcode.
 Bit D indicates source or destination register REG field of byte 2, 0 for source and
1 for destination.
 Bit W indicates width of operand, byte or word operation, 0 for byte and 1 for
word operand.
 Remaining six bit D2 to D7 indicates opcode.
 Hence (26)64 different opcode can be generated.
Second Byte indicate whether the operation is

o Reg to Reg
o Memory to Register
o Register to Memory.

Third Byte indicate 8 bit displacement

4)Fourth Byte Instructions (register to memory/memory to register)with 16


bit displacement
1. Register to memory with 16 bit displacement-4 byte

2. 1st byte-opcode with direction and word length

3. 2nd byte-whether operation is register to register/register to memory or memory to


register

4. 3rd byte and 4 th byte represent the 16 bit displacement

16 Bit Disp

F2 46H

7 0

EX-MOV AX,2334H[SI]

Opcod D W MO RE R/ 8 BIT 8 BIT


e D G M DISPLACEMENT(L DISPLACEMENT(H
) )
100010 1 1 01 000 100 00110100 00100011
=8B443423H

First byte indicate opcode.


 Bit D indicates source or destination register REG field of byte 2, 0 for source and
1 for destination.
 Bit W indicates width of operand, byte or word operation, 0 for byte and 1 for
word operand.
 Remaining six bit D2 to D7 indicates opcode.
 Hence (26)64 different opcode can be generated.

Second Byte indicate whether the operation is

o Reg to Reg
o Memory to Register
o Register to Memory.

Third Byte indicate 8 bit displacement lower byte and

Fourth Byte indicate 8 bit displacement higher byte

4)immediate data to register or memory Instructions (register to


memory/memory to register)with 16 bit displacement

a)8 bit immediate data

 Immediate data to register -2 byte

opcode w reg 8 bit operand


4 bit

Ex:- mov bl,23h

1011 0 011 00100011


=B323H
 Immediate data to memory-3 byte ( no displacement)

opcode w mod 000 r/m 8 bit operand


7 bit

Ex:- Mov [si],23h

opcode w mod 000 r/m 8 bit operand


1100011 0 00 000 100 00100011
=E604H

 Immediate data to memory-4 byte ( 8 bit displacement)

opcode w mod 000 r/m 8 bit displacement 8 bit operand


7 bit

Ex:- Mov 23h[di],43h

opcode w mod 000 r/m 8 bit displacement 8 bit operand


1100011 0 00 000 100 00100011 01000011
=E6042343H

 Immediate data to memory-5 byte ( 16 bit displacement)

opcode W mod 000 r/m 16 bit 16 bit 8 bit


displacement(L) displacement(H) operand
7 bit

Ex:- Mov 2323h[bx],54h

opcode W mod 000 r/m 16 bit 16 bit 8 bit


displacement(L) Displacement(H) operand
1100011 0 00 000 111 00100011 00100011 01010100
=E607232354H

b)16 bit immediate data

 Immediate data to register – 3 byte

opcode w reg 16 bit operand 16 bit operand(H)


4 bit

Ex:- mov bx,1223h

1011 0 011 00100011 00010010


=B32312H

 Immediate data to memory- 4 byte( no displacement)

opcode w mod 000 r/m 8 bit 8 bit


operand(L) operand(H)
7 bit

Ex:- Mov [si],2423h

opcode w mod 000 r/m 8 bit operand(L) 8 bit operand(H)


1100011 0 00 000 100 00100011 00100100
=E6042324H

 Immediate data to memory- 5 byte( 8 bit displacement)

opcode w mod 000 r/m 8 bit 8 bit 8 bit


displacement operand(L) operand(H)
7 bit

Mov 23h[di],3443h

opcode w mod 000 r/m 8 bit 8 bit 8 bit


displacement operand(L) operand(H)
1100011 0 00 000 100 00100011 01000011 00110100
=E604234334H

 Immediate data to memory- 6 byte( 16 bit displacement)

opcode W mod 000 r/m 16 bit 16 bit 16 bit 16 bit


displacem displacement( operand(L) operand(
ent(L) H) H)

Mov 2323h[bx],1654h
opcode W mod 000 r/m 16 bit 16 bit 8 bit 8 bit
displacem Displacemen operand( operand(H)
ent(L) t(H) L)
1100011 0 00 000 111 00100011 00100011 0101010 00010110
0
=E60723235416H

Ex-MOV 0F246H[BP], 1234H

First byte indicate opcode.


 Bit D indicates source or destination register REG field of byte 2, 0 for source and
1 for destination.
 Bit W indicates width of operand, byte or word operation, 0 for byte and 1 for
word operand.
 Remaining six bit D2 to D7 indicates opcode.
 Hence (26)64 different opcode can be generated.

Second Byte indicate whether the operation is

o Reg to Reg
o Memory to Register
o Register to Memory.

Third Byte indicate 8 bit displacement lower byte and Fourth Byte indicate 8 bit
displacement higher byte

16 Bit Disp
Fifth Byte indicate 8 bit operand lower byte and Six Byte indicate 8 bit operand
higher byte

Summary of Memory Accessing modes

Memory Operands

Operands No Displacement Displacement Displacement Register Operands

8 – bit 16 – bit

MOD 00 01 10 11

R/M W=O W=l

000 (BX) + (SI) (BX) + (SI) + DB (BX) +(SI) + D16 AL AX

001 (BX) + (DI) (BX) + (DI) + DB (BX) + (DI) + D16 CL CX

010 (BP) + (SI) (BP) + (SI) + DB (BP) + (SI) + D16 DL DX

011 (BP) + (DI) (BP) + (DI) + DB (BP)+(DI)+D16 BL BX

100 (SI) (SI) + DB (SI) + D16 AH SP


101 (DI) (DI) + DB (DI) + D16 CH BP

110 D16 (BP) + DB (BP) + D16 DH SI

111 (BX) (BX) + DB (BX) + D16 BH DI

MOD and R/M bit pattern of 8086


1. Effective address EA produced by these addressing modes will be added to data
segment base to form the physical address except for those cases where BP is used
as part of EA.
Example: DS:[BX] DS=2000H BX=1234H THEN PHYSICAL ADDRESS IS 21234H

2. In that case EA will be added to stack segment base to form physical addresses.
3. We can use segment override prefix to indicate that EA to be added to some
other segment base.

INSTRUCTION SET OF 8086


 The 8086 instructions are categorized into the
following main types:-
 Data copy instructions
 Arithmetic and Logical Instructions
 Branch Instructions
 Loop instructions
 M/c control instructions
 Flag manipulation instructions
 Shift and rotate instructions
 String instructions.
Data Copy / Transfer Instruction

MOV
 It transfers data from one register/memory location to
another register/memory location.
 The source may be anyone of the segment registers or
other general or special purpose registers or a
memory location.
 The destination may be another register or memory
location

MOV Instruction
• Move from source to destination. Syntax:
MOV destination, source
• No more than one memory operand permitted
• CS, IP cannot be the destination
• No immediate to segment moves

.data
count DB 100
wVal DW 2
.code
mov bl,count
mov ax,wVal
mov count,al

mov al,wVal ; error


mov ax,count ; error

18

Instruction Templates
Direct-Offset Operands
A constant offset is added to a data label to produce an effective address
(EA). The address is dereferenced to get the value inside its memory
location.

.data
arrayB DB 10h,20h,30h,40h
.code
mov al,arrayB+1 ; AL = 20h
mov al,[arrayB+1] ; alternative notation

arrayB+1 doesn't produce 11h!

19

Instruction Templates Example: MOV AX,BX


Opcode D W Mod Reg R/M

We can specify either of AX or BX using the REG field.


If we specify AX using REG field, then the D bit must
be 1, indicating that AX is the destination register.
In this case MOD value is 11 indicates register to
register operation, and REG is 011 indicates BX register,
which is source register, therefore D bit should be
0. W bit should be one as it is word operation. R/M
value is 000 specifies register AX. Thus the 2 byte
code for this instruction would be

Opcode D W Mod Reg R/M


100010 0 1 11 011 000 =89 D8H
 If we specify AX using REG field, then the D bit must be
1, indicating that AX is the destination register. The
REG field must be 000 to indicate AX register.
 The W bit must be 1 to indicate it is a word operation.
 MOD value is 11, and R/M value of 011. Thus the 2 byte
code for this instruction would be

Opcode D W Mod Reg R/M


100010 1 1 11 000 011 =8BC3H

 Thus MOV AX,BX has two equally valid opcodes.


 89 D8H and 8B C3H
 An assembler generates one of these as the opcode.

Example: MOV CL, [SI]


 Here we have to specify CL using REG field.
 The D bit must be 1, indicating that CL is the
destination register.
 The REG field must be 001 to indicate CL register.
 The W bit must be 0 to indicate it is byte operation.
 MOD value of 00, indicates a memory operation
without any displacement.
 [SI] is specified using R/M value of 100.
 Thus the 2 byte code for this instruction would be
Opcode D W Mod Reg R/M
100010 1 0 00 001 100 =8A 0CH
Example: MOV 46H[BP], DX
 Here we have to specify DX using REG field.
 The D bit must be 0, indicating that DX is the source
register.
 The REG field must be 010 to indicate DX register.
 The W bit must be 1 to indicate it is a word operation
 MOD value is 01, indicates memory operation with 8 bit
displacement.
 46H[BP] is specified using R/M value of 110, and a
displacement of 46H. Thus the 3 byte code for this
instruction
Opcode D Wwould
Modbe Reg R/M 8 Bit Disp
100010 0 1 01 010 110 46H =89 56 46H

Example: MOV F246H[BP],DX


 Here we have to specify DX using REG field.
 The D bit must be 0, indicating that DX is the source
register.
 The REG field must be 010 to indicate DX register.
 The W bit must be 1 to indicate it is word operation.
 F246H[BP] is specified using MOD value of 10, and
R/M value of 110, and a displacement of F246H.
 Thus the four byte code for this instruction would be

Opcode D W Mod Reg R/M 16 Bit Disp


100010 0 1 10 010 110 F2 46H =89 96 F246H
Example: MOV AX,25H
(Move immediate data to register)

Template: 1 0 1 1 W REG

 This instruction moves the value 25H i.e 0025H to AX


register.
 It is a 3 byte instruction.
 In this example, we specify AX using the REG field.
 The REG field must be 000 to indicate AX register,
 W=1 to indicate it is a word operation.
 Thus the 3 byte code for this instruction would be

Opcode W REG 16 Bit Data


1011 1 000 00 25H =B8 00 25H

But in memory it will be stored as B8 25 00H

Example: MOV DS:F246H[BP], DX


 Here we have to specify DX using REG field.
 The D bit must be 0, indicating that DX is the source
register.
 The REG field must be 010 to indicate DX register.
 The W bit must be 1 to indicate it is a word operation.
 F246H[BP} is specified with MOD=10 and R/M=110 and
displacement=F246H.
 Whenever Bp is used to generate the EA, the default
segment would be SS.
 In this example, as we want the segment register to be DS,
we have to provide the segment override prefix (SOP) byte
to start with.
 The SOP byte is 001SR110, where SR value is provided as
follows. SR Segment register
00 ES
01 CS
10 SS
11 DS

 So, the SOP byte is 00111110=3EH


 Thus the 5 byte code for this instruction is

SOP Opcode D W Mod Reg R/M 16 Bit Disp


3E 100010 0 1 10 010 110 F2 46H
=3E 89 96 F2 46H

 The instruction MOV SS:0F246H[BP],DX.


 This generates a 4 byte code, without the SOP byte, as SS is
already the default segment register in this case.

(move immediate data to memory location)


Example: MOV DS: 0F246H[BP], 1234H
Template: 1 1 0 0 0 1 1 W MOD 0 0 0 R/M
 This instruction moves the value 1234H to a memory
location whose EA is given as the sum of the 16 bit offset
value F246H and the contents of BP register.
 The PA is generated using DS as the segment register.
 The W=1 as it is word operation.
 MOD = 10 as it is 16 bit displacement.
 R/M =110 as it 16bit displacement is with BP register.
 When BP is used the default segment is SS, but this
instruction uses DS, therefore SOP is required. i.e 3E for
DS.
 Thus the 7 byte code is
SOP Opcode W Mod Opcode R/M 16 Bit Disp 16 Bit Data
3E 1100011 1 10 000 110 F2 46 1234H
=3E C7 86 F2 46 12 34H
 The physical address for the above instruction is 3E C7
86 F2 46 12 34H.
 It stores in memory as
 3E
 C7
 86
 46
 F2
 34
 12

example
 Mov cx ,dx
 Mov bl,[si]
 Mov oF246H[bp],dx
 Mov ds:0b234H[bp],dx :default ss
 Mov cl,[di]
 Mov dl,[bx]+[si]+04: mod 01 000
 Mov [bx+si],ax
 Mov 2345h[bx+di],bx
 Mov bx,cs:3456h[bp]
Standard format for writing the
program
Address Code /data Label Mnemonic Operand comment
/Opcode

 Address-it is used to represent offset of a code byte or


data byte Code/data-actual code bytes or data bytes are
put in this column
 Label- label is a name which represents an address
referred to a jump or call instruction. Label fallowed by
colon(:) if it is used in same code segment.(31 character)
 Mnemonics-contains opcode mnemonics for the
instructions.
 Operand-column contains the registers, memory
locations or data acted upon by instructions
 Comments-gives you space for to describe the function
of the instruction for future reference.

Assembler directives:-
1. Segment and ends
2. DB,DW,DD,DQ,DT
3. EQU
4. .model small
5. .code
6. .data
7. Proc endp
8. End
9. Org
10. Assume
SEGMENT & ENDS directives
 Segment & Ends directives are used to
identify a group of data items or group of
instructions that you want to put together
in a particular segment this is called logical
segment

SEGMENT & ENDS directives example


 Data1 segment
 Loc db 10h
 I db 5h
 Data1 ends
 Code1 segment
 Assume cs:Code1,ds:Data1
 Start: ------------
 --------------
 ----------
 Code1 ends
 End start
Writing programs for use with an
assembler
.model small
.data
n1 db 20
n2 db 30
a db ? Execute
.code
mov ax,@data
mov ds,ax
mov al,n1
add al,n2
shr al,01
mov a,al
int 3
end
.model small
 This is an assembler directive.
 It is direction to the assembler, not instruction to
the 8086
 It tells the size of the code and data segment.
 It requires one 64KB segment for data
 And one 64KB segment for code.

Naming data and addresses-


EQU,DB,DW,DD directives
 Programs works with 3 general categories of data
 Constants-values does not change during execution
 Variables-values does change during execution
 Addresses-are referred to in many instruction
 Example jump above
 Constants ,Variables & Addresses used in our
program can be given names(which allow you
remember the name instead of calculate address)
 Special directives are used to give names
EQU directive
 Used to assign names to constant in our program
 PI equ 3.14 ;it tells assembler each time it find
PI name replace by 3.14
 Example
 Mul ax,PI
 Replace by mul ax,3.14 by the assembler
 Useful if you call PI “n” number of times
 Change the value is easy only one time ,instead of
change n times

DB, DW DD( Assembler Directives)


directions to the assembler, not instructions for the 8086
 DB,DW DD are used to assign names to variables in the program.
 DB specifies data of type byte
Example: num DB 04H
 DW specifies data of type word
Example: num DW 042AH
Example: num DW 2 DUP(0).
It tells the assembler to initialize the two words to all zeros.
 DD specifies data of type Double word
Example: num DD 2 DUP(0).
It tells the assembler to initialize the two double words to all zeros.
 .Data
 This is a directive to define a data segment.
 .Code
 This is directive to define a code segment.
DB, DW DD( Assembler Directives)
directions to the assembler, not instructions for the 8086
 DB,DW DD are used to assign names to variables in the program.
 DB specifies data of type byte
Example: num DB 04H
 DW specifies data of type word
Example: num DW 042AH
Example: num DW 2 DUP(0).
It tells the assembler to initialize the two words to all zeros.
 DD specifies data of type Double word
Example: num DD 2 DUP(0).
It tells the assembler to initialize the two double words to all zeros.
 .Data
 This is a directive to define a data segment.
 .Code
 This is directive to define a code segment.

DB, DW DD( Assembler Directives)


directions to the assembler, not instructions for the 8086
 DB,DW DD are used to assign names to variables in the program.
 DB specifies data of type byte
Example: num DB 04H
 DW specifies data of type word
Example: num DW 042AH
Example: num DW 2 DUP(0).
It tells the assembler to initialize the two words to all zeros.
 DD specifies data of type Double word
Example: num DD 2 DUP(0).
It tells the assembler to initialize the two double words to all zeros.
 .Data
 This is a directive to define a data segment.
 .Code
 This is directive to define a code segment.
 The DB directive is used to declare a byte-
type variable, or to set aside one or more
storage locations of type byte in memory.
example
 TEMP DB 42H, for, tells the assembler to
reserve I byte of memory for a variable
named TEMP to put the value 42H in that
memory location when the program is
loaded into RAM to be run.

 PRICES DB 49H,98H,29H
; Declare array of 3 bytes named PRICES and
initialize 3 bytes as shown.

 NAME DB 'TINA'
; Declare array of 4 bytes and initialize with
ASCII codes for letters in TINA.
 TEMPERATURE DB 100 DUP(?)
; Set aside 100 bytes of storage in memory
and give it the name , but leave the 100
bytes uninitialized. Program instructions
will load values into these locations.

 PRESSURE_STORAGE DB 20H DUP(O)


; Set aside 20H bytes of storage in memory,
give it the name PRES-SURE_STORAGE, and
put 0 in all 20H locations.

 THREEW DW 1234H,3456H,5678H
;Declare array of 3 words and initialize with
specified values.
 STORAGE DW 100 DUP(O)
; Reserve an array of 100 words of memory and
initialize alII 00 words with 0000. Array is
named STORAGE.
 STORAGE DW 100 DUP(?)
; Reserve 100 words of storage in memory and
give it the name STORAGE, but leave the
words uninitialized.
 The DD directive is used to declare a variable of type
double word or to reserve memory locations which can be
accessed as type double word.
ARRAY_POINTER DD 25629261H,
for example, will define a double word named
ARRAY_POINTER 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. A declaration of this type is
often used with the LES or LDS instruction.
 The instruction LES DI,ARRAY_POINTER.
Example:-, will copy the low word of this double word, 9261
H, into the DI register and the high word of the double
word, 2562H, into the extra segment register.

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.
BIG_NUMBER DQ 24359874092A92BH,
will declare a vari-able named BIG_NUMBER and
initialize the 4 words set aside with the specified
number when the program is loaded into memory
to be run.
STORAGE DQ 100 DUP(O)
reserves 100 quad words of storage and initializes them
all to 0 when the program is loaded into memory to
be run.
 DT is used to tell the assembler to define a variable
which is 10 bytes in length or to reserve 10 bytes of
storage in memory.
PACKED_BCD DT 11223344556677889900
will declare an array named PACKED_BCD which is
10 bytes in length.
It will also initialize the 10 bytes with the values
11223344556677889900 .
 This directive is often used when declaring data
arrays for the 8087 math coprocessor.
RESULTS DT 20H DUP(O)
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.

 As the assembler assembles a section of 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 the 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.
ORG 2000H tells the assembler to set the location
counter to 2000H
 A "$" is often used to symbolically represent the
current value of the location counter.
 The $ actually represents the next available byte
location where the assembler can put a data or
code byte. The $ is often used in ORG statements
to tell the assembler to make some change in the
location counter relative to its current value.
ORG $ + 100
tells the assembler to increment the value of the location
counter by 100 from its current value. A
statement such as this might be used in a data
segment to leave 100 bytes of space for future
use.

 The END directive is put after the last


statement of a program to tell the
assembler that this is the end of the
program module.
 The assembler will ignore any statements
after an END directive, so you should make
sure to use only one END directive at the
very end of your program module.
 A carriage return is required after the END
directive.
 This directive is used along with the name of the
procedure to indicate the end of a procedure to the
assembler.
 This directive, together with the procedure directive,
PROC, is used to "bracket" a procedure. Here's an
example.
 SQUARE_ROOT PROC ; Start of procedure
; Procedure instruction
; Statements
 SQUARE_ROOT ENDP ; End of procedure

 This directive is used with the name of a segment to


indicate the end of that logical segment. ENDS is
used with the SEGMENT directive to "bracket" a
logical segment containing instructions or data.
Here's an example.

CODE SEGMENT ;Start of logical segment


containing code
Instruction statements
CODE ENDS ;End of segment named
CODE
 EQU is used to give a name to some value or
symbol.
 Each time the assembler finds the given name in
the program, it will replace the name with the value
or symbol you equated with that name.
Example:-
C_FACT EQU 03H
later in the program you write the instruction statement
ADD AL,C_FACT. When it codes this instruction
statement, the assembler will code it as if you had
written the instruction ADD AL,03H.

 The advantage of using EQU in this manner is


that
 if C_FACT is used 27 times in a program, and
you want to change the value, all you have to do
is change the EQU statement and reassemble the
program.
 The assembler will automatically put in the new
value each time it finds the name C_FACT.
 If you had used 03H instead of the EQU
approach, then you would have had to try to find
all 27 instructions and change them yourself.
C_WORD EQU 11001001 ; Replacement
MOV AL, C_WORD ; assignment
D-ADJ EQU DAA ; Create clearer
; mnemonic for DAA
ADD AL, BL ; Add BCD numbers
D-ADJ ; Keep result in BCD
format
STRING-START EQU [BX]; Give name to [BX]

 The ASSUME directive is used to tell the assembler the


name of the logical segment it should use for a specified
segment.
ASSUME CS:CODE,
tells the assembler that the instructions for a program are in a
logical segment named CODE.
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.
the assembler reads the statement MOV AX,[BX] after it reads
this ASSUME, it will know that the memory location
referred to by [BX] is in the logical segment DATA.

 You must tell the assembler what to assume for any


segment you use in a program.
 If you use a stack in your program, you must tell the
assembler the name of the logical segment you have
set up as a stack with a statement such as

ASSUME SS:STACK_HERE.
 The assembler must be told what to assume for the
extra segment with a statement such as

ASSUME ES:STRING_DESTINATION.

Type of numbers used in data statements


 Binary

 Decimal
 Hexadecimal

 Bcd
 ASCII
 Example:
 Temp db 01110101B
 Temp db -20[D](assember insert 2s comp value) temp db 20[D]
 Temp dw 3B2AH
 Temp db 59H
 Temp db ‘RAMA’-assembler allocate 4 mem loc for each character
 Temp db ‘1234’ –assembler allocate 4 mem loc for each ascii no

Assembly language program development tools.


 Editor-allow to create a file containing the assembly language statements .it stores
ASCII code for letters and numbers in successive RAM location .ASM
 Assembler-convert mnemonics into binary code
 Create Object file (binary code & offset address)and list file only find syntax
error .OBJ & .LST(MASM)
An assembler is a program which converts an assembly language program into equivalent
machine code and it is further converted into executable code for execution of program by the
micro process/system.
The assembler decide the address of each label and substitute value of each constant and
variable .
It then forms machine code for each mnemonics and data in assembly language program .
To do this assembler need some information from programmer like the storage required for
a constant or variable, logical name of segments, type of routines and module start and end of
segment etc.
The Assembler Directives are directions to the assembler, these are not instructions for
the 8086.

 Linker-join several object programs into one obj program(Ex:library file ,other
modules).EXE &.MAP
 Produces MAP file:-contains address info about the linked files
o When writing a large program, it is convenient and efficient to divide large program into smaller
module.
o Each module can be individually written tested and debugged.
o When all module work as desired, these object module can be linked together to form a large
function program.
o Linker is a program used to join several object file into one large object file.
o The linker produce a link file which contains the library code for all the combined modules.
o The linker also produce a link map file which contains address information about the link files.
o The linker which comes with TASM assembler produce link file with .exe extension.
o The linker does not assign absolute addresses to the program. It assigns only relative addresses
starting from zero. Thus makes program relocatable.
 Locator-used to assign the physical addresses for segments .BIN(in IBM-PC DOS
(EXE2BIN (Locator) convert .exe to .bin(which contain Physical Address) in case
microprocessor kit
o A locator is a program used to assign the specific address of where the segment of the object
code are to be loaded into memory.
o A locator program called exe to bin comes with IBM PC DOS.
o Exe to bin converts a .exe file into a .bin file which has physical addresses.

 Debugger-load program into system mem and execute(Reg/MEM contents and


allow to change content and rerun,break point)
o A debugger is a program which allow you to load your object code program into system
memory, execute the program and trouble shoot or debug it.
o Through debugger we can look the content of register and memory location after each
instruction.
o A debugger also allow you to set a break point at any point in your program.
If you insert a break point, the debugger will run a program up to the instruction where break point is
inserted and stop execution, to examine the register and memory contents
 Emulator- it is mixer of HW & SW used to test and debug the HW & SW of external
system such as prototype of the microprocessor based instrument

Questions
1. State and explain the instruction formats of 8086.
2. Explain the fields used in the template for the instruction 'Move data between a
register and register/memory. Derive the code for the instruction MOV DH, [Sl]+
85H
3. Brief about assembly development tools
4. Describe about directives in 8086 assembler
5. Construct the binary code for each of the fallowing 8086 instruction
1. Mov cx ,dx
2. Mov bl,[si]
3. Mov oF246H[bp],dx
4. Mov ds:0b234H[bp],dx
5. Mov cl,[di]
6. Mov dl,[bx]+[si]+04
7. Mov [bx+si],ax
8. Mov 2345h[bx+di],bx
9. Mov bx,cs:3456h[bp]

Das könnte Ihnen auch gefallen