P. 1
Microprocessor(8086) Lab

Microprocessor(8086) Lab

|Views: 241|Likes:
Published by Manjunatha Siddappa

More info:

Published by: Manjunatha Siddappa on Mar 03, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

09/16/2014

pdf

text

original

Microprocessor(8086) Lab

http://cnx.org/content/m32857/latest/

Connexions
You are here: Home » Content » Microprocessor(8086) Lab

Microprocessor(8086) Lab
Module by: Rajeshwari Hegde. User rating (?): (1 rating)

Summary: This module contains the programs involving Data transfer instructions, Arithmetic and logical instructions, string manipulation instructions etc Q1. Byte and word move using different addressing modes Program: .model small .data Num dw 4321h .code Mov ax,@data Mov ds,ax Mov ax,1234h ;immediate addressing Mov bx,ax ;register addressing Mov ax,num ;direct addressing Mov si,1000h Mov al,[si] ;indirect addressing Mov bl,[si+100h] ;relative addressing Mov bx,1000h Mov ax,[si+bx] ;base index addressing Mov cx,[si+bx+100h] ;relative base index addressing Mov ah,4ch Int 21h

1 of 41

2/19/2011 2:32 PM

Microprocessor(8086) Lab

http://cnx.org/content/m32857/latest/

End Output: Ax=1234h Bx=1234h Ax=4321h….. 2. Program to transfer a block of data without overlap .model small .data d1 db 1,2,3,4,5 d2 db 10 dup(0) .code mov ax,@data ;Initialize the data segment mov ds,ax lea si,d1 ;Load offset address of d1 in si lea di,d2 ;Load offset address of d2 in di mov cx,05 ;load cx with count up:mov al,[si] ;Move the 1st element of d1 to al mov [di],al ;Move to d2 inc si ;Increment si inc di ;Increment di dec cx ;decrement the counter jnz up ;Repeat till cx becomes zero mov ah,4ch ;Terminate the program int 21h end d1 d2

2 of 41

2/19/2011 2:32 PM

Microprocessor(8086) Lab

http://cnx.org/content/m32857/latest/

01 02 03 04 05
TABLE 1

3 of 41

2/19/2011 2:32 PM

Microprocessor(8086) Lab

http://cnx.org/content/m32857/latest/

01 02 03 04 05
TABLE 2

3. Program to transfer a block of data with overlap .model small .data d1 db 1,2,3,4,5 d2 db 10 dup(0) .code mov ax,@data ;Initilize the data segment mov ds,ax lea si,d1 ;Load the offset address of d1 in si lea di,d2 ;Load the offset address of d2 in di mov cx,05h ;load cx with count up:mov al,[si] ;Move the first element of d1 to al mov [di],al ;Move to d2 inc si ;Increment si inc di ;Increment di dec cx ;decrement the counter jnz up ;Repeat till cx becomes zero mov cx,05h ;Load cx with count lea si,d1+2 ;Load si with offset address of d1+2 lea di,d2 ;Load the offset address of d2 in di up1:mov al,[di] ;Move the first element of d2 to al mov [si],al ;Move al to d1

4 of 41

2/19/2011 2:32 PM

4ch .org/content/m32857/latest/ INC di .Repeat the loop mov ah.Increment di inc si .Terminate the program int 21h end d1 d2(temp location) (after block transfer) (with overlap) 01 02 03 04 05 TABLE 3 01 02 03 04 05 TABLE 4 01 02 01 02 03 04 05 TABLE 5 5 of 41 2/19/2011 2:32 PM .Microprocessor(8086) Lab http://cnx.Increment si loop up1 .

d1 .Move the first element of d2 to bl mov [di].5 d2 db 22h.model small .3.d2 .05h .Move bl to d1 inc si .4ch .Load offset address of d2 in di mov cx.@data .al .code mov ax.If not=0.load cx with count up:mov al.bl .Increment si inc di .2.Terminate the program int 21h end 01 02 03 04 05 TABLE 6 6 of 41 2/19/2011 2:32 PM .org/content/m32857/latest/ 4.33h.ax lea si.44h.Load offset address of d1 in si lea di.Microprocessor(8086) Lab http://cnx.[di] .[si] .data d1 db 1.66h . Jump to label up mov ah.Initilize the data segment mov ds.4. write an ALP to interchange 2 blocks of data .Move the first element of d1 to al mov bl.Increment di dec cx .decrement the count jnz up .55h.Move al to d2 mov[si].

0ffffh n2 dw 02 dup(0) .2222h.4444h.org/content/m32857/latest/ 11 22 33 44 55 TABLE 7 d1 d2 d1 d2 01 02 03 04 05 TABLE 8 11 22 33 44 55 TABLE 9 Before block exchange After block exchange 5 .model small .@data .3333h.Microprocessor(8086) Lab http://cnx.data n1 dw 1111h.Initialize Data segment 7 of 41 2/19/2011 2:32 PM . Addition and subtraction of N numbers Program to add N data words .code mov ax.

Write an ALP to add/subract 2 32 bit signed/unsigned numbers.Load cx with count mov dx.code mov ax.to point to the next data word dec cx . repeat the loop jnc down .dx .by si mov [si+2].ax .org/content/m32857/latest/ mov ds.Clear accumulator mov cx.Add the first element with accumulator inc si .model small .4444h.Terminate the program int 21h end I/p:1111h.Microprocessor(8086) Lab http://cnx.00h .2222h.[si] . .4ch .00 . increment dx down:mov [si].Clear dx clc .ax lea si.0ffffh o/p:1aaa9h 6 .Load si with the offset address of n1 mov ax.if carry=1. jump to label down inc dx .clear carry up:add ax.Increment si twice inc si .If cx≠0.Store carry in next memory location mov ah.Decrement the count jnz up .Store the result in memory pointed to .05h .data d1 dd 0f2222222h d2 dd 33333333h d3 dd 10 dup(0) .n1 .3333h.@data .else if carry =0.Initialize the data segment 8 of 41 2/19/2011 2:32 PM .

[di] .decrement bx dec cx .Load di with offset address of d2 lea bx.Clear ax lea si. mov [bx].Load si with offset address of d1 lea di.Move the lower byte of Ist number to al adc al.Increment si inc di .model small .org/content/m32857/latest/ mov ds.Increment di dec bx .al .00h .Decrement cx jnz up .by bx inc si .d2 .else increment carry counter down:mov [bx].terminate the program int 21h end Input: 0f2222222h and 33333333h( unsigned number addition) Output:125555555h 6.d3+5 .clear carry up:mov al.dl .Microprocessor(8086) Lab http://cnx.Move the carry to memory location mov ah.Store the result in memory pointed to .00h .Add with carry the second no.ax mov ax.Load cx with with the count mov dl.if cx is not equal to zero.Load bx with offset address of d3+5 mov cx.Program to add/subtract 2 64 unsigned/signed numbers . repeat .4ch .04h .If no carry.the loop jnc down .jmp to label down inc dl .data 9 of 41 2/19/2011 2:32 PM .clear dl clc .d1 .[si] .

second number mov [bx].[si] .[di] .al .Load di with offset of d2 lea bx.res+8 .Load si with offset of d1 lea di.4ch .Load cx with count lea si.08h .ax clc .org/content/m32857/latest/ d1 dq 1234567812345678h d2 dq 1234567812345678h res db 09 dup(0) .code mov ax.1234567812345678h Output:2468ACF02468ACF0H 7 Program to divide a 32 bit number by a 16 bit number .Decrement bx inc si .ah . repeat the loop jnc exit .@data .Move the result to memory pointed by bx dec bx .Load bx with offset of the result mov ah.Store carry in memory location mov ah.Terminate the program int 21h end Input: 1234567812345678h.If cx≠0.Mov the LS byte of first no.model small 10 of 41 2/19/2011 2:32 PM .00 .else if carry=0.Decrement count jnz up .Initialize data segment mov ds.Increment di dec cx .Mov 00 to ah up:mov al.Add with carry to the LS byte of the .Increment si inc di . to al adc al.Clear carry mov cx.store 00 in memory inc ah .d2 .else increment carry exit:mov [bx].Microprocessor(8086) Lab http://cnx.d1 .

code mov ax.cx=number of elements in the array 11 of 41 2/19/2011 2:32 PM .ax .@data .Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/ .@data mov ds.data array dw 1111h.terminate the program int 21h end Input: dividend-12345678h .load ax with lower word mov bx.code mov ax. To find the Largest/smallest number in an array of 16 bit numbers .Load si with EA of num mov dx.ax lea si.move remainder to memory mov [di+2].res .4ch .5555h res dw 02 dup(0) .Initialize Data segment lea bx.num1 .2222h.data num dd 12345678h num1 dw 2345h res dw 02 dup(0) . divisor-2345h Output:Quotient:8422h.8567h.[si+2] . array .dx . Remainder:134Eh 8 .move quotient to memory mov ah.[si] .Initialize data segment mov ds.model small .num .dx:ax/bx lea di.ax .load dx with higher word of dividend mov ax.Load BX with EA of array mov cx.move the divisor into bx div bx .05h .4589h.load di with EA of res mov [di].

move the 1st number of n1 to ax inc si inc si 12 of 41 2/19/2011 2:32 PM .bx=number of elements to be sorted dec bx l2: mov cx.ax . Program to sort a given set of 16 bit unsigned integers in ascending/descending order .4ch .data n1 dw 0ffffh.compare the 1st and 2nd element jnc below .4589h.bx .@data .n1[si] .[bx+2] .count .[bx] .00h .code mov ax.2222h.org/content/m32857/latest/ mov ax.store the largest number in location res mov ah.if cx≠0.8567h.[bx+2] below:inc bx inc bx dec cx jnz up .terminate the program int 21h end Input: 1111h.Jc below . repeat mov res.3rd number and so on.Initialize Data segment mov ds.model small . .for smallest number mov ax.5555h.si=0 l1: mov ax.7777h count dw 04h .move the 1st word of the array to ax up:cmp ax.if 1st number>2nd number compare 1st with .ax mov bx.Microprocessor(8086) Lab http://cnx.3333h.5555h Output:8567h stored in location res 9 .number of iterations mov si.

@data .code mov ax.model small .compare with the character to be . 0ffffh.initialize DS and ES mov ds."character found$" msg1 db 0ah.ax mov cl.repeat till cx=0 dec bx jnz l2 .searched jz found .jnc rep1 .else exchange 1st and 2nd no mov n1[si-2]. 5555h.4ch int 21h end Input: 0ffffh.compare with the next number jc rep1 . no exchange .n1[si] .Load the EA of string into si up:mov al. xchg ax.Microprocessor(8086) Lab http://cnx.[si] .org/content/m32857/latest/ cmp ax.n1[si] . Program to search a character in a given string .all the iterations over? mov ah.0dh.ax mov es.string . 3333h.ax rep1:loop l1 .>2nd no.if 1st no. 7777h. 5555h.data string db "bmscollege$" enter db "j" msg db 0ah. 10 ."charcter not found$" char db 02 dup(0) .jnc for descending order.enter .CL=count lea si.0ah .0dh.mov the first character to al cmp al.jump to found 13 of 41 2/19/2011 2:32 PM . 7777h Output: 3333h.

initialize DS mov ds.no cmp ax.@data .display.msg .org/content/m32857/latest/ inc si .compare bx with 01 jz down .jump to down up:dec bx .4ch .compare with 02h jz down .code mov ax.msg1 .Microprocessor(8086) Lab http://cnx. char found mov ah.09h int 21h end1:mov ah.else repeat the loop dec cl jnz up nfound:lea dx.display.no .ax mov ax.terminate int 21h end Output: character not found 11 Program to find the factorial of a given number(no<=8) .factorial=2.move the number to ax and bx mov bx.if 0.data no dw 08h res dw 02 dup(0) .else decrement bx mul bx .01h .if no=2.multiply ax and bx cmp bx. char not found mov ah. store the result 14 of 41 2/19/2011 2:32 PM .model small .09h int 21h jmp end1 found:lea dx.02h .

data n1 db 09H n2 db 0ah.code mov ax.0dh.Initialize data segment mov ds.4ch . Program to check whether the given data byte is positive or negative .org/content/m32857/latest/ jmp up down:mov res.Clear carry mov al.0dh.model small .Microprocessor(8086) Lab http://cnx.4ch int 21h 15 of 41 2/19/2011 2:32 PM . display the no is positive mov dx.offset n3 mov ah.ax mov ah.10h .ax clc .end of the program int 21h end I/P=08h O/P=9D80h 12.offset n2 .dx mov res+2.09h int 21h jmp end1 d1:mov dx."the data is negative $" .Check the MSB jz d1 ."the data is positive $" n3 db 0ah.If 0.Else display the no is negative mov ah.09h int 21h end1:mov ah.n1 and al.@data .

compare the remainder with 0.jump to end1 down:lea dx.4ch .data n1 db 0feH n2 db 0ah.Initialize data segment mov ds. Program to check whether data byte is odd or even .divide by 2 cmp ah.move the number to al div bl .ax mov ah.Display “the given …odd” int 21h jmp end1 .02h mov al.end of the program int 21h 16 of 41 2/19/2011 2:32 PM .code mov ax.@data .org/content/m32857/latest/ end Input:09h Output:the data is positive Input:0ffh Output:the data is negative 13. the number is positive lea dx.n1 .00h mov bl.if 0.model small .0dh.09h int 21h end1:mov ah."the given data is odd $" n3 db 0ah.00h .n2 mov ah.n3 . jz down .09h .0dh.Microprocessor(8086) Lab http://cnx."the given data is even$" n4 db 04 dup(0) .display” the given …even” mov ah.

Initialize data segment mov ds.Clear carry back:rol ax.If ax=bx.ax mov ax.'it is a palindrome$' msg2 db 0ah.@data .Display “it is not a palindrome” int 21h jmp last pali:mov ah.00 .Load cx with the count mov bx.Rotate bx once without carry dec cl .code mov ax. compare ax and bx jz pali .msg2 .Rotate left ax once.'it is not a palindrome$' num dw 4421h .Move 00 to bx clc .num .09h lea dx.If cl≠0.01 .Program to check whether the given word is a bitwise palindrome .data msg1 db 0ah.org/content/m32857/latest/ end Input:0feh Output displayed on the screen:“the given data is even” Input:09h Output displayed on the screen:”the given data is odd” 14.Decrement the count jnz back .10h . through carry rcr bx.msg1 .09h lea dx.01 .0dh.bx . repeat the loop cmp ax. jump to label pali mov ah.Microprocessor(8086) Lab http://cnx.Display ”it is a palindrome” 17 of 41 2/19/2011 2:32 PM .Move number to ax mov cl.model small .if cl=0.0dh.

cmp bh.data num dw 8448h msg1 db 0ah. Program to check whether the given data word is a nibble wise palindrome .Terminate the program int 21h end 15.09h lea dx. jump to label pali mov ah.bl .if cl=0.num .org/content/m32857/latest/ int 21h last:mov ah.Clear carry up:ror bl.4ch ."it is a palindrome$" msg2 db 0ah.4ch . compare bh with bl jz pali . Rotate right bl once.msg1 int 21h end1:mov ah.Microprocessor(8086) Lab http://cnx.01 .0dh.09h .ax .@data .ax mov ax.Jump to label end1 pali:mov ah.0dh.Terminate the program 18 of 41 2/19/2011 2:32 PM .Display “it is a palindrome” lea dx.If bh=bl.Move 04 to cl mov bx.model small .04 .Move ax to bx clc ."it is not a palindrome$" .Repeat the loop if cl≠0.msg2 int 21h jmp end1 . Initialize data segment mov ds.Move number to ax mov cl. through carry dec cl .Decrement cl jnz up .code mov ax.

code Mov ax.clear ah Add al. Program to add 2 ASCII numbers .@data .02h Int 21h Pop ax Mov dl.move the first no to al Mov bl.3030h .ah .al .org/content/m32857/latest/ int 21h end 16.Or ax with 3030h for display Push ax Mov dl. add al and bl Aaa .bl .Microprocessor(8086) Lab http://cnx.02h Int 21h Mov ah.Initialize data segment Mov ds.n1 .display the content of al Mov ah.ax Mov al.00h .end of the program Int 21h End 19 of 41 2/19/2011 2:32 PM .data .4ch .N2 db ‘9’ N1 db ‘5’ N2 db ‘8’ N3 db 02 dup(0) .second number to bl Mov ah.n2 .ASCII adjust after addition Or ax.display the content of ah Mov ah.N1 db ‘9’ .model small .

30h Lea si.bring the digit to LSB position Cmp al.res .cl .code Mov ax. Initialize data segment Mov al.model small .0f0h .org/content/m32857/latest/ Input : N1=’9’ N2=’9’ Output: 18 Input: N1 = ‘5’ N2 = ‘8’ Output: 13 17.data num db 35h . Program to convert a hex number to ascii number .al Mov al.num db 0AAh res db 2 dup(0) .num .compare with 0ah Jc d2 .04h Rol al.if the number is >0ah.0ah .store the result in memory Mov [si].ax .if the number is < 0ah.num And al.07h .07h . jump to D2 Add al. add 37h 20 of 41 2/19/2011 2:32 PM .@data Mov ds.0fh .mask the upper nibble Cmp al.jump to D1 Jc d1 Add al.if the number is<0ah.Microprocessor(8086) Lab http://cnx.if the number is>0ah.0ah . add 37h D1:add al.mask the lower nibble of the digit Mov cl.move the number to al And al.

Program to convert an 8 bit BCD number to binary number . Initialize data segment Mov al.mask the upper nibble 21 of 41 2/19/2011 2:32 PM .4ch .org/content/m32857/latest/ D2:add al. stored in memory locations [si] & [si+1] Input:0AAh Output: 41h and 41h stored in memory locations [si] & [si+1] 18.get the BCD number to al And al.al Mov al.store the result in memory Mov ah.move the BCD number to al And al.mask the lower nibble Mov cl.0f0h .multiply with 0ah Mov bl.D1 db 85h D2 db 02 dup(0) .@data Mov ds.30h Mov [si+1].0fh .code Mov ax.end of the program Int 21h End Input:35h Output:33h and 35h.model small . bring the upper nibble to LS position Mov bl.D1 .al .04h Rol al.store the result in bl Mov al.data D1 db 99h .ax .D1 .0ah Mul bl .al .Microprocessor(8086) Lab http://cnx.cl .

divide ax by bl mov [si+1].ax .ah .org/content/m32857/latest/ Add al.0h . Initialize data segment Mov al.code Mov ax.model small .num db 63h res db 03 dup(0) .add al and bl Mov D2.64h div bl .divide ax by 64h Lea si.end of the program Int 21h End Input : 99 Output: 63h Input : 85 Output: 55h 19.move the quotient to [si] Mov al.bl .00h .@data Mov ds.num .data num db 0ffh .al .move the binary number to al Mov ah.clear ah mov bl.move the remainder to [si+2] 22 of 41 2/19/2011 2:32 PM .al .move the quotient to [si+1] mov [si+2].ah .4ch .al .clear ah Mov bl.move the remainder to al mov ah.Microprocessor(8086) Lab http://cnx.res Mov [si].store the binary no in D2 Mov ah.0ah div bl .Program to convert an 8 bit binary number to BCD number .

"the code is 2 out of 5 code$" n2 db 0ah.02h .si+2] Input :063h Output:09 09 stored in locations [si+1.if 1st three MSBs are not zero jump to .if 1st three MSBs are non-zero.display ”the code is 2 out of 5 code” 23 of 41 2/19/2011 2:32 PM .bits jnc d1 .0e0h .ax . si+2] 20. Program to check whether the code belongs to 2/5 code .0dh."the code is not a 2 out of 5 code$" n3 db 0fh .code mov ax. jnz invalid . move the .invalid mov bl.00h and al.0dh.@data mov ds.si+1. jump to invalid lea dx.if dl≠0.check for number of ones in remaining 5 .initialize the data segment mov al.05h mov al.increment dl if carry=1 d1:dec bl .org/content/m32857/latest/ mov ah.decrement the count jnz up .check for carry inc dl .number to al up:ror al.end of the program int 21h end Input :0ffh Output:02 05 05 stored in locations [si. repeat cmp dl.if bl≠0.Microprocessor(8086) Lab http://cnx.compare dl with 02.n1 .4ch .model small .01h .move the number to al mov dl.data n1 db 0ah.and it with 0eh jnz invalid . n3 .n3 .

@data mov ds.Microprocessor(8086) Lab http://cnx. display “the code is not a mov ah.Initiliaze data segment mov ax.and 2nd number to bx mov dx.4ch . Program to find the LCM of two data bytes .ax .09h .bx 24 of 41 2/19/2011 2:32 PM .num+2 . 2 out of 5 code int 21h end1:mov ah.2dh lcm dw 2 dup(0) .if ax>bx.org/content/m32857/latest/ mov ah.bx .ax mov num+2.code mov ax.09h int 21h jmp end1 .02h num dw 09h.num dw 05h.stack 64 . jump to again xchg ax.num .n2.end of the program int 21h end Input:0fh Output: the code is not a 2 out of 5 code Input:09h Output: the code is a 2 out of 5 code 21.compare ax and bx jnc again .bx .jump to end1 invalid:lea dx.clear dx cmp ax.otherwise exchange ax and bx mov num.move the 1st number to ax mov bx.0 .data .

bx .data num dw 1bh.@data Mov ds.code Mov ax.Initiliaze data segment Mov ax. 25 of 41 2/19/2011 2:32 PM .Microprocessor(8086) Lab http://cnx.model small . Program to find the GCD of two numbers .num+2 .org/content/m32857/latest/ again: push ax .num jnc no_increment inc dx no_increment: jmp again store: pop lcm+2 pop lcm mov ah.push ax and dx onto the stack push dx div bx .ax .compare the remainder with 0 je store pop dx pop ax add ax.4ch int 21h end Input:05h.00h .09h Gcd dw ? .num .move the 1st number to ax Mov bx. 02h Output:0ah Input: 22.divide ax by bx cmp dx.and 2nd number to bx Again:cmp ax.

0 Div bx Cmp dx.data N1 db 6 N2 db 7 N3 db 02 dup(0) .4ch Int 21h End 23.bx Jmp divaxbx Exit:mov gcd.ax Mov ah.ax Mov ah.n2 mov ch.bx Mov gcd+2.Microprocessor(8086) Lab http://cnx.@data Mov ds.dx Jmp again Down:xchg ax.09h Aad div ch 26 of 41 2/19/2011 2:32 PM .n1 Mov al. Program to divide a packed bcd number by an unpacked bcd number and display the quotient and remainder on the screen .code Mov ax.0 Je exit Mov ax.model small .org/content/m32857/latest/ Je exit Jb down Divaxbx:mov dx.

@data Mov ds. Remainder 4 displayed on the screen 24.02h Int 21h mov dl.Program to multiply two unpacked BCD numbers and display the result .data N1 db 9 N2 db 5 N3 db 02 dup(0) .ax Mov al.02h int 21h pop ax Mov dl.n1 Mov bl.ah Mov ah.Microprocessor(8086) Lab http://cnx.model small .3030h Push ax Mov dl.code Mov ax.02h Int 21h Mov ah.4ch Int 21h End Input:6 and 7 Output: Quotient 7. " " mov ah.n2 mul bl Aam 27 of 41 2/19/2011 2:32 PM .org/content/m32857/latest/ Or ax.al Mov ah.

4ch Int 21h End Input: N1=9.program to multiply two 32 bit unsigned numbers .3030h Push ax Mov dl.org/content/m32857/latest/ Or ax.num2 Lea bx.ax Lea si.res clc mov ax.@data Mov ds.ah Mov ah.num1 Lea di. N2=5 Output:45 displayed on the screen 2 5.02h Int 21h pop ax Mov dl.al Mov ah.Microprocessor(8086) Lab http://cnx.code Mov ax.data num1 dd 0ff0aff0h num2 dd 03304002h res dq 00h .stack 100h .model small .02h Int 21h Mov ah.[si] mul word ptr[di] 28 of 41 2/19/2011 2:32 PM .

ax mov cx.dx mov ax.cx adc dx.00h pop cx add ax.dx mov ax[si+2] mul word ptr[di] add ax.cx adc dx.00h mov[bx+2].org/content/m32857/latest/ mov[bx].4ch int 21h end Input: Num1:0ff0aff0h Num2:03304002h 29 of 41 2/19/2011 2:32 PM .Microprocessor(8086) Lab http://cnx.00h mov[bx+4].ax mov[bx+6].00h push dx push ax mov ax.cx adc dx.[si+2] mul word ptr[di+2] add ax.[si] mul word ptr[di+2] pop cx add ax.ax mov cx.dx mov ah.cx adc dx.

al mov ch.ah mov[si+1].02 up:mov dl.cl cmp dl.ax mov ah.00h mov al.@data mov ds.model small .res mov[si].0ah 30 of 41 2/19/2011 2:32 PM .0fh cmp dl.org/content/m32857/latest/ Output:32d32d18dd5fe0h 26.code mov ax.02h int 21h mov dl.0f0h mov cl.al mul bl lea si.0ah jb down add dl.Microprocessor(8086) Lab http://cnx.Program to find the square of a given data byte .04h ror dl.07h down:add dl.[si] and dl.num mov bl.30h mov ah.data num db 0ffh res db 04 dup(0) .[si] and dl.

org/content/m32857/latest/ jc down1 add dl.data num dw 05h .code Mov ax.num dw 0ffh cube dw 02 dup(0) .@data Mov ds.07h down1:add dl.num Mul num Mov cx.dx Mul num Add ax.02h int 21h inc si dec ch jnz up mov ah.cx 31 of 41 2/19/2011 2:32 PM .model small .Microprocessor(8086) Lab http://cnx.4ch int 21h end Input:04h Output:10h is displayed on the screen Input:0ffh Output:FE01h is displayed on the screen 27 .ax Mov dx.30h mov ah. Program to find the Cube of a given number .0h Mov ax.

4ch Int 21h End Input:0ffh Output:fd02ffh in locations cube and cube+2 Input:05h Output:7d in locations cube and cube+2 28.data n1 dw 0fff0h n3 db 04 dup(0) mes1 db 0ah.10h mov ax.@data mov ds.bl dec cx 32 of 41 2/19/2011 2:32 PM .model small .n3 clc mov cl.dx Mov ah. Program to find number of ones in a given data word and display the count on the screen .01 jnc d1 inc bl d1:mov [si].Microprocessor(8086) Lab http://cnx.code mov ax.n1 up:rcl ax.org/content/m32857/latest/ Mov cube.00h lea si.0dh."no of 1's$" .ax mov bx.ax Jnc skip Inc dx Skip:mov cube+2.

model small .04h ror dl.0ah jc d12 add dl.[si] and dl.30h mov ah.07h d12:add dl.Microprocessor(8086) Lab http://cnx.07h d11:add dl.ascii multiplication .0f0h mov cl.0ah jc d11 add dl.[si] and dl.02h int 21h mov ah.org/content/m32857/latest/ jnz up mov dl.30h mov ah.4ch int 21h end Input:0fff0h Output:0c displayed on the screen 29.02h int 21h mov dl.cl cmp dl.data N1 db 6 N2 db 7 N3 db 02 dup(0) 33 of 41 2/19/2011 2:32 PM .0fh cmp dl.

@data mov ds.org/content/m32857/latest/ . 0ah.0dh.0ah.00h Aad div ch Or ax."$" string db 18 dup(0) .ah Mov ah."$" blank db " ". Program to reverse the string .n2 mov ch.4ch Int 21h End 2 9 .@data Mov ds.n1 Mov al.02h Int 21h pop ax Mov dl.Mov ah.data mes1 db 0ah.09h .ax 34 of 41 2/19/2011 2:32 PM .model small .0dh.Microprocessor(8086) Lab http://cnx.al Mov ah."enter the string".ax Mov ah.0dh.code mov ax.code Mov ax.02h Int 21h Mov ah.3030h Push ax Mov dl.

data src db 'string transfer$' dst db 25 dup(0) .Program to transfer the string .al jmp cops rev:mov dx.offset blank mov ah.org/content/m32857/latest/ mov es.01h int 21h cmp al.dl cops:mov ah.offset string add si.0dh jz rev dec si mov [si].si int 21h mov ah.4ch int 21h end 30.model small .09h mov dx.14h mov dl.code 35 of 41 2/19/2011 2:32 PM .09h int 21h mov ah.24h mov [si].09h int 21h mov si.offset mes1 mov ah.Microprocessor(8086) Lab http://cnx.ax mov dx.

"$" data ends code segment assume cs:code.ds:data start:mov ax.@data mov ds.0dh.0ah.mes1 int 21h 36 of 41 2/19/2011 2:32 PM ."$" mes2 db "enter the string to be searched".ax lea si. program to search a sub string in a main string data segment mainstr db 80 dup(0) subst db 80 dup(0) mes1 db "enter the string".src lea di.dst cld mov cx.Microprocessor(8086) Lab http://cnx.ax mov ah.0dh.org/content/m32857/latest/ mov ax.ax mov es.ax mov es.0fh rep movsb mov ah."$" sfound db "string found$" nfound db "string not found$" null equ 0dh cr db 0ah.data mov ds.0ah.4ch int 21h end 31.0dh.09h lea dx.

al lea dx.00 t3:mov ah.al inc di jmp t3 out:mov subst[di].00 up:mov ah.00 again:mov al.null 37 of 41 2/19/2011 2:32 PM .cr mov ah.cr mov ah.0dh jz out mov subst[di].mainstr[si] cmp al.mes2 int 21h mov di.al lea dx.0dh jz acc mov mainstr[si].Microprocessor(8086) Lab http://cnx.01h int 21h cmp al.al inc si jmp up acc:mov mainstr[si].org/content/m32857/latest/ mov si.00 mov di.01h int 21h cmp al.09h int 21h mov si.09h int 21h lea dx.

09h lea dx.00 inc si jmp again down:inc si inc di mov al.Microprocessor(8086) Lab http://cnx.sfound int 21h jmp quit t2:mov ah.09h lea dx.4ch int 21h code ends end start Output on the screen Enter the string: bmscollege Enter the string to be searched: college Output: string found 3 2.subst[di] jz down mov di.org/content/m32857/latest/ jz t2 cmp al.nfound int 21h quit:mov ah.mul1 db 12h 38 of 41 2/19/2011 2:32 PM . Program to multiply two data words and display the answer by calling a far procedure data segment .subst[di] cmp al.null jz found jmp again found:mov ah.

org/content/m32857/latest/ .4ch int 21h code ends end start Far procedure to display the number on the screen public disp sbrt segment public 39 of 41 2/19/2011 2:32 PM .ds:data start:mov ax.offset tps mov al.cl call disp mov ah.Microprocessor(8086) Lab http://cnx.data mov ds.ax mov sp.ah call disp mov al.mul1 mul mul2 mov cx.ax mov al.mul2 db 24h mul1 db 0ffh mul2 db 0ffh data ends stack_seg segment dw 40 dup(0) tps label word stack_seg ends sbrt segment public extrn disp:far sbrt ends code segment assume cs:code.

07h down:add dl.07h down1:add dl.02h int 21h pop ax mov dl.Microprocessor(8086) Lab http://cnx.02h int 21h pop ax pop cx pop dx pop ax 40 of 41 2/19/2011 2:32 PM .org/content/m32857/latest/ disp proc far assume cs:sbrt push ax push dx push cx mov dl.0ah jb down add dl.cl cmp dl.0f0h mov cl.30h push ax mov ah.30h push ax mov ah.al and dl.0ah jc down1 add dl.0fh cmp dl.al and dl.04h ror dl.

org/content/m32857/latest/ ret disp endp sbrt ends end Input:12h 24h Output:0288h.Microprocessor(8086) Lab http://cnx. Last edited by Rajeshwari Hegde on Nov 16.0). and is an Open Educational Resource. 41 of 41 2/19/2011 2:32 PM . 2009 11:22 pm US/Central. displayed on the screen More about this module: Metadata | Downloads | Version History How to reuse and attribute this content How to cite and attribute this content This work is licensed by Rajeshwari Hegde under a Creative Commons Attribution License (CC-BY 3.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->