0% found this document useful (0 votes)
17 views18 pages

Unit 3

The document outlines the development cycle of assembly language programs (ALP) using the 8086 microprocessor, detailing the steps from program entry using a text editor to debugging and testing. It describes the roles of various tools such as assemblers, linkers, loaders, and debuggers, as well as assembly directives and their functions. Additionally, it includes example programs for arithmetic operations on BCD numbers and arrays, illustrating the application of the discussed concepts.

Uploaded by

kotreshi ck
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views18 pages

Unit 3

The document outlines the development cycle of assembly language programs (ALP) using the 8086 microprocessor, detailing the steps from program entry using a text editor to debugging and testing. It describes the roles of various tools such as assemblers, linkers, loaders, and debuggers, as well as assembly directives and their functions. Additionally, it includes example programs for arithmetic operations on BCD numbers and arrays, illustrating the application of the discussed concepts.

Uploaded by

kotreshi ck
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

ADVANCED MICROPROCESSOR

KOTRESHI C K
SANPOLY
Advanced Microprocessor Dept of E&CE

Unit-3 8086 programming


ALP program development cycle

Assembly language
program text written in
any text written in any text
editor.

assembler Program listing

Object code module binary


Error messages

linker
Other object code
modules from
Linked module
library

loader

testing

Above figure shows the steps involved in developing & executing ALP program.

Entering the program using a text editor

• The program is entered using any editor.


• Any ordinary editor can be used to enter the alp program such as word star edit & so on.
• Its saved with .asm extension.
• Output of the text editor is a i/p to the assembler.
• Assembler translates the assembly language to binary equivalent usually known as object code or
machine code with file name .obj
• Microsoft assembler (MASM) can be used.
• During assembling the program,the assembler checks for syntax errors & display Before generating
object file .
• The object code module contains information about where the program or module to be loaded in
memory.

linker

• Linking procets converts the object file to executable file(.obj to .exe).


• It also used for combining morethan one assembled module into one executable file.

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

Testing the program

• 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

• It is a program allows the execution of a program under user control.


• The process of locating & correcting an error using a debugger is known as debugging.

EMULATOR:

1. An emulator is a mixture of hardware & software.


2. it is usually used to test & debug the hardware & software of an external system such as the
prototype of a microprocess or based instrument.

ASSEMBLE DIRECTIVES:

1. Directives are also called as pseudo case/instruction.


2. No machine code is generated .
3. Directives gives the instruction to the assembler that , how operand as to be processed.

DB(define byte):

1. Reserve 1 byte of memory for a variable.

Examples:

SUM DB O

Reserve 1 byte of memory for a variable sum & initialized with a value 0.

DW(Define word):

It is used tell the assembler to define a variable of type word or 16 bit.

Example:

MULTIPLER DW 437AH

Declares a variable multiplier of word type & initialized with the value 437AH.

STORAGE DW100 DVP(?)

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.

DD (define double word)

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 .

Example: Array DD 25629214

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)

DT is used to tell a assembler to declare variable with length of 10 bytes .

Examples

Result DT 20HDUP (0)

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.

Few more examples

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

Example 1. Assume CS:code.

2.Assume DS: data

For DS m/l,the data logical segment is assume for DS(data segment).

END: End of the program

End directive is placed after the last statement of a last program to tell the assembles that is the end of the
module.

ENDP: end of the procedure.

Sub routines are called procedure to indicate end of procedure.

ENDS:

Ends directive to indicate end of the logical segment.

SEGMENT:

Segment directive indicates the beginning of logical 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:

Length is used to determine the number of elements in string or array.

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 .

Ex: mov cx,length string 1

The length of the string 1is loaded to cx register

SIZE:

To determine the number of bytes in the string or array.

Ex: mov cx,siz string1

The size of the string in bytes will be loaded to cx register.

OFFSET:

Which tells the assembles to determine the offset or displacement address of variable.

Ex: mov bx,OFFSET tax

In this instruction offset address of tax variable is loaded to bx register.

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.

Ex: ADD bx ,TYPE word_array

On executing this instruction,bx points to the next word in an array of words.

PROC

It is used to indicate start of procedure.

EQU

To assign names to constants.

Ex: pressure EQU 05h

Wherever pressure is used in the program is replaced with 05h.

Macro

It is used to indicate the beginning of a macro.

ENDM

It is used to indicate the end of macro.

Include

Insert the content of the specified file at the position of Include in the program file.

Ex: 1. Include matlab 2. Include c:test1.asm

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.

Ex: Page 50,132

Above instruction indicate 50 lines per page & 132 character per line.

TITLE

TITLE directive is used at the beginning of the source program.

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.

Ex: PUBLIC basic,DA

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.

Ex: EXTRN basic:word

The external variable basic is some other module type of the variable is word.

PTR

The PTR directive assign a specific type to a variable or a label.

Ex: INC Byte PTR[Bx]

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

This directive helps in providing shortcuts while defining any segment.

Ex: model memory-model;memory-model can be a small medium,compact or large.

.Code

This directive is used to define code segment.

Ex: Code name


6
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE

.Data

This directive is used to define data segment.

Ex: Data name

.Stack

This directive is used to define stack segment.

Ex: stack size & size is optional.

Align

Align directive forces the assembler to align the next segment at an address that is divisible by 16.

Ex: Align 16;align next address which 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

Record is used to define a bit pattern within a byte or word.

Structure of assembly language program

ALP progrsm consist of three types of statement

Executable instructions: instructions or executable instruction tell the processor what to do each
instruction consist of opcode & these opcode generates machine code.

Assembler directives or pseudo code

This directive tells the assembler to what to do & no machine code is generated.

Macros: Macros are basically a text substitution mechanism.

General format of assembly language instruction

Label: mnemonic operand,operand;comment

Each part of the instruction is separated by space.

NAMES representing the address are called label & label followed by[:] colon will be present .

The label name can be used in the branch instruction.

Mnemonics : it indicates operations to be performed on the operand .

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.

It is useful for other user to understand the instruction.

7
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE

Comparison b/w macro & procedure

PROCEDURE MACRO
1. Procedure are used for large group of Macro are used for small group of
instruction to repeated. instruction to be repeated.

2. Machine code is generated only once in Machine code is generated everything


memory. the macro is called.

3. Call & RET are used to call procedure &


Macro can be called just by writing its name
return from procedure.

4. Length of the object file is less. Object file is lengthy

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.

8. Procedure can be defined as Macro can be defined as


Procedure name PROC ……….. Macro name MACRO
……………………………………………. ……………………………….
……………………………………………. ……………………………….
Procedure name ENDP ENDM

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

Program to add two 4-digit packed BCD numbers.


• Model
• Stack
• Data
Num1 db 23h,55h
Num2 db 10h,33h
Result db 3 dup(0)
• Code
Begin: mov Ax,@data;
Mov DS,Ax
CLC
Mov Bx,00h
Mov Cx,02h
Again: mov Al,Num1[Bx]
ADC Al,Num2[Bx]
DAA
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

Program to subtract two 4-digit packed BCD number


• Model
• Stack
• Data
Num1 db 23h,55h
Num2 db 10h,33h
Result db 3 dup(0)
• Code
Begin: mov Ax,@data;
Mov DS,Ax
9
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE
CLC
Mov Bx,00h
Mov Cx,02h
Again: mov Al,Num1[Bx]
SBB Al,Num2[Bx]

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

Program to add an array of five 16-bit numbers


• Model small
• Data
Numlist DW 02h,04h,06h,08h,0Ah
Count equ 05h
Result DW(0)
• Code
Mov Ax,@data
Mov DS,Ax
Mov Cx,count
Mov Ax,count
Mov Si,Ax
up: Add Ax,numlist[SI]
Add SI,02
Loop up
Mov result,Ax
Int 03h
End
1. Program to find the GCD of a number
Model small
Stack 64h
Data
Num db 90.36
Gcd db(i)
Code
Mov ax,@data
Mov ds,ax
Mov al,num
Mov bl,num+1
Up: Div bl
Cmp ah,00h
Je exit
Mov al,bl
Mov bl,ah
Mov ah,00h
Jmp up
Exit Mov gcd,bl
Int 03h

10
Kotreshi C K 15EC63B
Advanced Microprocessor Dept of E&CE

2. Program to find the lcm of two numbers


Model small
Stack 64h
Data
Num dw 35,14
Lcm dw 2dup(0)
Code
Mov ax,@data
Mov ds,ax
Mov cx,01
Mov dx,00
Mov ax,num
Mov bx,num+2
Up: Mov lcm,dx
Mov lcm+2,ax
Div bx
Cmp dx,00h
Je exit
Mov dx,00
Mov ax,num
Inc cx
Mul cx
Jmp up
Exit: Int 03h
End
3. Program to find square of given number
Model small
Stack 64h
Data
Num dw 02
Square dw 2dup(0)
Code
Start: mov ax,@data
Mov ds,ax
Mov dx,00
Mov ax,num
Mul num
Mov square,ax
Mov square+2,dx
Int 03h
end
4. Program to find the largest number in given array
Model small
Stack 64h
Data
Numlist dw 20h,30h,90h,60h

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

Program to convert packed BCD to ascii


Model small
Stack bhh
Data
Org 0100h
Pbcd db 73h
Org 0110h
Ascii db 2 dup(?)
Code
Start: mov ax,@data
Mov ds,ax
Mov al,pbcd
And al,0fh
Add al,30h
Mov ascii,al
Mov al,pbcd
Mov cl;044
Shr al,cl
Add al,30h
Mov ascii+1,al
Int3
End start

Program to convert decimal to hex-decimal


Model small
Start 64h
Data
Decimal db 25h
Hex db?
Code
Begin:
Mov ax,@data
Mov ds,ax
Mov bx,00h
Mov cl,04h
Mov al,decimal
Mov dl,al
And dl,0fh
And al,0f0h
Ror al,cl
Mov dh,0ah
Mul dh
Add al,dl
Mov hex,al
Int 03h
End begin

Program to convert hexadecimal to decimal


Model small
Stack 64h
Data
Hex dB 19h
Decimal dB?

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

Program to count vowels in given string.


Small
Stack 644
Data
String dB ‘Bengaluru’
Total db00
Code
Begin: mov ax, @data
Mov ds, ax
Lea dx, string
Mov ah,09h
Int 21h
Mov cx,09h
Mov bx,00h
Count: mov al, [bx]
Cmp al,’a’
Ie vowel
Cmp al,’e’
Je vowel
Cmp al,’I’
Je vowel
Cmp al,’0’
Je vowel
Cmp al, ’u’
Je vowel
Jmp last
Vowel: inc total
Last: inc bx
Loop count
Int 08h
End begin
Program to find that the given string is a palindrome OR NOT.
Model small
Stack 64h
Data
String db ‘radar’
Code
Start: mov ax,@data
Mov ds,ax
Lea si,string

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy