Unit 3
Unit 3
KOTRESHI C K
SANPOLY
Advanced Microprocessor Dept of E&CE
Assembly language
program text written in
any text written in any text
editor.
linker
Other object code
modules from
Linked module
library
loader
testing
Above figure shows the steps involved in developing & executing ALP program.
linker
Loader
• Loader is a program that moves executable file to memory for execution.after loading program in
main memory the loader transfer the control the program for execution.
1
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
• Debugger is a program that allows the execution of program under the control of user.
• The process of locating & correcting an error using a debugger is known as debugging.
• To test the program debugger is used.
Development tools
Test editors
• An editor is a program which allows us to create a file containing the assembly language
program.
• Examples of some editors are pcwrite,worstar.
• The main function of the editor is to hep programmer to construct his alp program in right
format that the assembler accept.
• The user program is saved with .asm extension & also called as sorce file.
• If any typing mistakes is done editor will alert us to correct it.
Translator
• It is a program used to translate the user oriented language to machine oriented language.
• The translates are classified inti four types
1. Compiler
2. Interpreter
3. Assembler
4. Pre-processor
Assembler
• It is used to translate assembly language into machine language
• When assembler is running,it reads source file & generates two files .
• The first file is the object file .obj
• The object file consist of binary code for the instruction & information about address of
instruction
• The second file is list file with the extension .lst
Linker
• It is a program that joins together several object files & library functins intone large executable file.
• While writing large program it is a better to divide the large program into smaller modules,each
module is written,tested & debugged;these modules are kept in the library file & linked into other
program as required.
• It produces executable file with extension .exe
Locater
• It is program called EXE2BIN converts a .exe file to a .bin file which has physical addresses
Loader
• It is a progam that moves the executable file produced by linear from secondary storage to main
memory for execution.
2
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
Debugger
EMULATOR:
ASSEMBLE DIRECTIVES:
DB(define byte):
Examples:
SUM DB O
Reserve 1 byte of memory for a variable sum & initialized with a value 0.
DW(Define word):
Example:
MULTIPLER DW 437AH
Declares a variable multiplier of word type & initialized with the value 437AH.
Declares variable storage of type word & reserves 100 words (200 bytes) without initialization.
DQ (Define quadword)
It is used to tell assembler to declare a variable with a length of 4 word or to reserve 4 word
memory location.
EXAMPLES:
Number DQ 243598740192A92BH Declares a variable with a name number or type DQ & reserves 4
words in a M/L.
It is used to tell a assembler to declare a variable with a length of 2 words or to reserve 2 word of memory
location .
Declare variable with a name array & type of doble word or reserves 2 word M/L.
3
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
DT (define 10 bytes)
Examples
Declare a variable with a name result and type of DT and reserve 320 bytes of M/L(20h=32,32x10=320)&
initialized with a value zero.
1. TEMP ,DB 01001101B; define TEMP variable & binary number is used
2. TEMP DB 72519;odd number is used , after number Q is used
3. TEMP DB ‘M’;ASCII character enclosed with in a single or double quotes.
Assume
This directive is used to tell an assembler, the name of the logical segments used in programs
End directive is placed after the last statement of a last program to tell the assembles that is the end of the
module.
ENDS:
SEGMENT:
Group:
Group directive is used to group the logical segments into a one logical segment.
EVEN:
Even directive tells assembler to increment location counter to the next even address.
ORG(origin):
The ORG directive allows you to set location counter to desired value at any point in the program .
Ex: ORG 2000h tells the assembler to set the location counter to 2000h .
4
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
LENGTH:
If string is declared AS String of bytes then the length will produces the no.of bytes string if its declared as
word the length produces the no of words .
SIZE:
OFFSET:
Which tells the assembles to determine the offset or displacement address of variable.
TYPE:
TYPE directive determines the type of variable & also determines the number of bytes in the variable.if byte
type number of byte is 1,if word type the number of byte is 2.
PROC
EQU
Macro
ENDM
Include
Insert the content of the specified file at the position of Include in the program file.
5
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
NAME directive
Name directive is used to give a specific name to each assembly module when program consisting of
several modules are written.
Page
Page directive is used to indicate the number of lines on a page & max number of character on line.
Above instruction indicate 50 lines per page & 132 character per line.
TITLE
TITLE directive can be upto cocharacter printed on 2nd line of each page of source program.
PUBLIC
It indicate the assembler that the labels,variables,constantsor procedure declared PUBLIC may be accessed
by other assembly module.
The two variables basic &DA are available to other assembly module.
EXTRN
The EXTRN directive is used to tell the assembler that the name or labels are in some other assembly
module.
The external variable basic is some other module type of the variable is word.
PTR
This statement tells the assembler to increment the byte pointed to by Bx.
INC word[Bx]
This statement tells the assembler to increment the word pointed to by Bx.
Model
.Code
.Data
.Stack
Align
Align directive forces the assembler to align the next segment at an address that is divisible by 16.
STRUCT
It is used to declare the data type which is collection of primary data type(DB,DW&DD)& it allows the user
to define a variable which has more than one data type.
Ex: structure name STRUCT sequence of DB,DW,DD directive for declaring fields structure ends.
Record
Executable instructions: instructions or executable instruction tell the processor what to do each
instruction consist of opcode & these opcode generates machine code.
This directive tells the assembler to what to do & no machine code is generated.
NAMES representing the address are called label & label followed by[:] colon will be present .
Operand: operand may be a immediate data or register on which the operation is carried out.
Comment: comment start with semicolon(;)& its optional & is ignored by a assembler.
7
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
PROCEDURE MACRO
1. Procedure are used for large group of Macro are used for small group of
instruction to repeated. instruction to be repeated.
5. Directives PROC & ENDP are used for Directive macro & ENDM are used for
defining procedure. defining macro.
6. More time required for execution. Less time is required for execution.
7. Less memory is required due to only one More memory is required due to repeated
machine code is generated. generation of machine code.
Write a program to perform the addition of two 16-bit unpacked bcd number & store the result in Dx.
Mov SI,0300h
Mov DI,0310h
Mov AL,[SI+1]
Mov AL,[DI+1]
ADC AL,[DI+1]
AAA ;ASCII adjust
Mov DH,AL
INT 20h ;terminate the program
Write a program to subtract two 16-bit unpacked bcd number (ASCII srtring ) & store the result in Dx.
Mov SI,0300h
Mov DI,0320h
Mov AL,[DL]
AAS
Mov AL,[SI+1]
SBB AL,[DI+1]
AAS
8
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
Mov DH,AL
INT 20h
Write a program to find maximum number in a given string. the string is 32bytes ling & stored in an
address starting from 0300h.
Mov SI,0300h
Mov CL,20h ; 20h = 32 number
Mov AL,[SI]
INC SI
CMP AL,[SI]
JNB loop
Mov AL,[SI]
Loop: loop nz back
INT 20h
DAS
Mov result[Bx]Al ;Decimal adjust acc after addition
INC Bx
Loop again
JNC skip
Mov result[Bx],01h
Skip: INT 03h ;Use break point interrupt
End begin ;End of the program
10
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
11
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
Count equ 05h
Largest dw 00h
Code
Start: mov ax,@data
mov ds,ax
mov cx,count
mov SI,00h
mov ax,numlist[si]
down: add si,02h
cmp ax,numlist[si]
jae below
mov ax,numlist[si]
below: loop down
mov largest,ax
int 03h
end
5. Program to find smallest number in a given array
Model small
Stack 64h
Data
Numlist dw 20h,30h,10h,90h,60h
Count equ 05h
Smallest db 00h
Code
Start: Mov ax,@data
Mov ds,ax
Mov cx,count
Mov si,00h
Mov ax,numlist[si]
Down: Add si,02h
Cmp ax,numlist[si]
Jbe below
mov ax,numlist
below : loop down
mov smallest,ax
int 03h
end start
6. Program to arrange data in ascending order
Model small
Stack 64h
Data
Numlist db 55h,25h,45h,35h,15h
Len dw $-numlist
Code
Mov ax,@data
Mov ds,ax
Mov dx,0001h
Again: Cmp dx,0000h
Je exit
Mov dx,0000h
12
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
Mov si,offset numlist
Mov cx,len
Dec cx
Up: Mov al,[si]
Cmp al,[si+1]
Jbe down
Xchg al,[si+1]
Mov[si],al
Mov dx,0001h
Down: Inc si
Loop up
Again
Exit: Int 03h
End
7. Program to arrange in decending order
Model small
Stack 64h
Data
Numlist db 15h,35h,45h,25h,55h
Len dw$-numlist
Code
Mov ax,@data
Mov ds,ax
Mov dx,0001h
Again: Cmp dx,0000h
Je exit
Mov dx,0000h
Mov si,offset numlist
Mov cx,len
Dec cx
Up: Mov al,[si]
Cmp al,[si+1]
Jae down
Xchg al,[si+1]
Mov[si],al
Mov dx,0001h
Down: Inc si
Loop up
Jmp again
Exit: Int 03h
Align 16
End
8. Program to convert packed to unpacked BCD
MODLE SMALL
STACK
DATA
OrG 0100H
PBCD DB H5H
13
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
UPBCD DB 3 DUP(0)
CODE
START: MOV AX ,@ DATA
MOV DS , AX
MOV AL , PBCD
AND AL, OPH
MOV CL, OHH
MOV UPBCD, AL
MOV CL, OHH
MOV AL, PBCD
SHR AL, CL
MOV UPBCD A1, AL
INT3
END START.
9. Program to convert unpacked to packed bcd
Model small
Stack 64h
Data
Org 0100h
Upbcd db 04h,05h
Org 0110h
Pbcd db(0)
Code
Start: mov ax,@data
Mov ds,ax
Mov al,upbcd
Mov cl,04h
Shl al,cl
Mov bl,upbcd+1
Or al,bl
Mov pbcd,al
Int3
End start
10. Program to convert ascii to packed bcd
Model small
Stack
Data
Org 0100h
Ascii db 37h,33h
org 0110h
pbcd db(?)
Code
Start mov ax,@data
Mov ds,ax
Mov al,ascii
Sub al,30h
Mov bl,ascii+1
Sub bl,30h
Mov cl,04h
Shl al,cl
Or al,bl
Mov pbcd,al
Int 3
End start
14
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
15
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
Code
Begin: mov ax, data
Mov ds, ax
Mov ah,00h
Mov cl,04h
Mov al, hex
Mov bl,0ah
Div bl
Ror al,cl
Add al, ah
Mov decimal,al
Int 03h
End begin
16
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
Mov cx,05h
Mov bx,cx
Dec bx
Repeat : Mov al,[si]
Cmp al,string[bx]
Inc notpal
Dec bx
Inc si
Cmp si,bx
Je finish
Dec bx
Loop repeat
Finish : Mov dl,’y’
Mov ah,02h
Int 21h
Jmp last
Notpal: Mov al,’n’
Mov ah,02h
Int 21h
Last : Mov ah,4ch
Int 21h
End start
17
Kotreshi C K 15EC63B