Beruflich Dokumente
Kultur Dokumente
programming.
Syllabus
8086 family assembly language programming.
Instruction templates.
Introduction
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.
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
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
o Reg to Reg
o Memory to Register
o Register to Memory.
EX-MOV [SI],AX
8 bit Displacement
7 0
EX-MOV AX,34H[SI]
o Reg to Reg
o Memory to Register
o Register to Memory.
16 Bit Disp
F2 46H
7 0
EX-MOV AX,2334H[SI]
o Reg to Reg
o Memory to Register
o Register to Memory.
Mov 23h[di],3443h
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
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
Memory Operands
8 – bit 16 – bit
MOD 00 01 10 11
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.
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
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
19
Template: 1 0 1 1 W REG
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
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
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.
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.
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.
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
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.
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]