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

Increment di inc si .Increment si loop up1 .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 .Repeat the loop mov ah.Microprocessor(8086) Lab http://cnx.org/content/m32857/latest/ INC di .4ch .

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

code mov ax.3333h.Initialize Data segment 7 of 41 2/19/2011 2:32 PM .model small .Microprocessor(8086) Lab http://cnx.data n1 dw 1111h.@data . Addition and subtraction of N numbers Program to add N data words .0ffffh n2 dw 02 dup(0) .4444h.2222h.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 .

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

07h down1:add dl.num dw 0ffh cube dw 02 dup(0) .@data Mov ds.model small .data num dw 05h .Microprocessor(8086) Lab http://cnx.num Mul num Mov cx.dx Mul num Add ax.0h Mov ax.30h mov ah.org/content/m32857/latest/ jc down1 add dl.cx 31 of 41 2/19/2011 2:32 PM . Program to find the Cube of a given number .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.code Mov ax.02h int 21h inc si dec ch jnz up mov ah.

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

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

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

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

0dh.ax lea si."$" sfound db "string found$" nfound db "string not found$" null equ 0dh cr db 0ah.0ah."$" data ends code segment assume cs:code.dst cld mov cx.4ch int 21h end 31.ax mov es.09h lea dx.src lea di.ds:data start:mov ax.0dh."$" mes2 db "enter the string to be searched".org/content/m32857/latest/ mov ax.0fh rep movsb mov ah.mes1 int 21h 36 of 41 2/19/2011 2:32 PM .@data mov ds.ax mov es.data mov ds.0dh. 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".0ah.ax mov ah.Microprocessor(8086) Lab http://cnx.

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

sfound int 21h jmp quit t2:mov ah.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.Microprocessor(8086) Lab http://cnx.09h lea dx.subst[di] cmp al. Program to multiply two data words and display the answer by calling a far procedure data segment .mul1 db 12h 38 of 41 2/19/2011 2:32 PM .09h lea dx.subst[di] jz down mov di.00 inc si jmp again down:inc si inc di mov al.nfound int 21h quit:mov ah.null jz found jmp again found:mov ah.org/content/m32857/latest/ jz t2 cmp 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.data mov ds.cl call disp mov ah.ds:data start:mov ax.offset tps mov al.mul1 mul mul2 mov cx.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 .Microprocessor(8086) Lab http://cnx.ax mov al.ah call disp mov al.ax mov sp.org/content/m32857/latest/ .

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

org/content/m32857/latest/ ret disp endp sbrt ends end Input:12h 24h Output:0288h. 41 of 41 2/19/2011 2:32 PM . Last edited by Rajeshwari Hegde on Nov 16. 2009 11:22 pm US/Central.Microprocessor(8086) Lab http://cnx.0). 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. and is an Open Educational Resource.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.