System Programming with 8086

System Programming With 8086 Assembly Language Programs

ADDITION OF TWO 16 BIT NUMBERS

assume cs:code,ds:data
data segment
a db 0ah,0dh,"ENTER THE FIRST NUMBER:$"
b db 0ah,0dh,"ENTER THE SECOND NUMBER:$"
d db 0ah,0dh,"RESULT IS:$"
data ends

read macro
mov ah,01h
int 21h
sub al,30h
endm

display macro
add dl,30h
mov ah,02h
int 21h
endm

code segment
start: mov ax,data
mov ds,ax
lea dx,a
mov ah,09h
int 21h
read
mov dl,10h
mul dl
mov bh,al
read
add bh,al


read
mul dl
mov bl,al
read
add bl,al

lea dx,b
mov ah,09h
int 21h
read
mov dl,10h
mul dl
mov ch,al
read
add ch,al


read
mul dl
mov cl,al
read
add cl,al

lea dx,d
mov ah,09h
int 21h


add bl,cl
mov al,bl
daa
mov bl,al
jc l1
jnc l2
l1:inc bh
l2:add bh,ch
mov al,bh
daa
mov bh,al
jnc next
mov dl,01h
display
next:mov ah,00h
mov dh,10h
mov al,bh
div dh
mov cx,ax
mov dl,cl
display
mov dl,ch
display
   


mov ah,00h
mov dh,10h
mov al,bl
div dh
mov cx,ax
mov dl,cl
display
mov dl,ch
display

mov ah,4ch
int 21h
code ends
end start

 SUBTRACTION OF TWO 16 BIT NUMBERS

assume cs:code,ds:data
data segment
a db 0ah,0dh,"ENTER THE FIRST NUMBER:$"
b db 0ah,0dh,"ENTER THE SECOND NUMBER:$"
d db 0ah,0dh,"RESULT IS:$"
data ends

read macro
mov ah,01h
int 21h
sub al,30h
endm

display macro
add dl,30h
mov ah,02h
int 21h
endm

code segment
start: mov ax,data
mov ds,ax
lea dx,a
mov ah,09h
int 21h
read
mov dl,10h
mul dl
mov bh,al
read
add bh,al


read
mul dl
mov bl,al
read
add bl,al

lea dx,b
mov ah,09h
int 21h
read
mov dl,10h
mul dl
mov ch,al
read
add ch,al


read
mul dl
mov cl,al
read
add cl,al

lea dx,d
mov ah,09h
int 21h

cmp bx,cx
jnc l3
xchg bx,cx
mov dl,'-'
mov ah,02h
int 21h
l3:sub bl,cl
mov al,bl
das
mov bl,al
mov ah,00h
sbb bh,ch
mov al,bh
das
mov bh,al
mov ah,00h
mov dh,10h
mov ah,00h
mov al,bh
div dh
mov cx,ax
mov dl,cl
display
mov dl,ch
display
   
mov ah,00h
mov dh,10h
mov al,bl
div dh
mov cx,ax
mov dl,cl
display
mov dl,ch
display

mov ah,4ch
int 21h
code ends
end start

MULTIPLICATION OF TWO 8 BIT NUMBERS

assume cs:code,ds:data
data segment
m1 db 0ah,0dh,"Enter the first number: $"
m2 db 0ah,0dh,"Enter the second number: $"
m3 db 0ah,0dh,"Product:$"
data ends
code segment
 start:mov ax,data
mov ds,ax
lea dx,m1
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bh,al
mov ah,01h
int 21h
mov bl,al
sub bx,3030h
mov ax,bx
aad
mov bl,al
lea dx,m2
mov ah,09h
int 21h
mov ah,01h
int 21h
mov ch,al
mov ah,01h
int 21h
mov cl,al
sub cx,3030h
mov ax,cx
aad
mul bl
mov bx,ax
lea dx,m3
mov ah,09h
int 21h
mov ax,bx
mov cx,03e8h
mov dx,0000h
div cx
mov bx,dx
add al,30h
mov dl,al
mov ah,02h
int 21h
mov ax,bx
mov dx,0000h
mov cx,0064h
div cx
mov bx,dx
add al,30h
mov dl,al
mov ah,02h
int 21h
mov ax,bx
mov dx,0000h
mov ch,0ah
div ch
mov bh,ah
add al,30h
mov dl,al
mov ah,02h
int 21h
add bh,30h
mov dl,bh
mov ah,02h
int 21h
mov ah,4ch
int 21h
code ends
end start

DIVISION OF 16 BIT NUMBER BY 8 BIT NUMBER

assume cs:code,ds:data
data segment
m1 db 0ah,0dh,"enter the first no: $"
m2 db 0ah,0dh,"enter the second no: $"
m3 db 0ah,0dh,"the quotient is:$"
m4 db 0ah,0dh,"the remainder is:$ "
data ends
code segment

read macro
mov ah,01h
int 21h
sub al,30h
mov ah,00h
endm

display1 macro
mov ah,09h
int 21h
endm

display2 macro
mov ah,02h
int 21h
endm

        start: mov ax,data
mov ds,ax

lea dx,m1
display1

mov bx,0000h
mov ax,0000h
mov dx,03e8h
read
mul dx
mov bx,ax

mov ax,0000h
read
mov dx,0064h
mul dx
add bx,ax

mov ax,0000h
read
mov dx,0ah
mul dx
add bx,ax


read
add bx,ax

lea dx,m2
display1

mov ch,00h
mov dl,0ah
read
mul dl
mov cl,al
read
add cl,al

mov ax,bx
mov dx,0000h
div cx

mov bx,ax
mov [di],dx

lea dx,m3
display1

mov ax,bx
mov cx,03e8h
mov dx,0000h
div cx

mov bx,dx
add al,30h
mov dl,al
display2

mov ax,bx

mov dx,0000h
mov cx,0064h
div cx

mov bx,dx
add al,30h
mov dl,al
display2

mov ax,bx
mov dx,0000h
mov ch,0ah
div ch

mov bh,ah
add al,30h
mov dl,al
display2

add bh,30h
mov dl,bh
display2

lea dx,m4
display1

mov ax,[di]
mov cx,03e8h
mov dx,0000h
div cx

mov bx,dx
add al,30h
mov dl,al
display2

mov ax,bx

mov dx,0000h
mov cx,0064h
div cx

mov bx,dx
add al,30h
mov dl,al
display2

mov ax,bx
mov dx,0000h
mov ch,0ah
div ch

mov bh,ah
add al,30h
mov dl,al
display2

add bh,30h
mov dl,bh
display2

mov ah,4ch
int 21h
code ends
end start

SUB STRING DELETION

assume cs:code,ds:data
data segment
a db 0ah,0dh,"Enter main string : $"
b db 0ah,0dh,"Enter the substring to be deleted : $"
c1 db 0ah,0dh,"The result is : $"
arr1 db 30 dup(?)
arr2 db 30 dup(?)
data ends

read macro
mov ah,01h
int 21h
endm

disp macro
mov ah,09h
int 21h
endm

result macro
mov ah,02h
int 21h
endm

code segment
start:     mov ax,data
            mov ds,ax
          
            lea dx,a
            disp
          
            mov cl,00h
            lea si,arr1
          
loop1:     read
           cmp al,0dh
           jz loop12
           mov [si],al
           inc si
           inc cl
           jmp loop1
          
loop12:    lea dx,b
           disp
          
           mov ch,00h
           lea si,arr2
          
loop2:     read
           cmp al,0dh
           jz loop21
           mov [si],al
           inc si
           inc ch
           jmp loop2
          
loop21:    lea dx,c1
           disp
          
           lea si,arr1
           lea di,arr2
          
core: mov al,[si]
           dec cl
           cmp cl,00h
           jz next
           cmp al,[di]
           jz dele
          
return:    inc si
           mov dl,al
           result
           jmp core
          
dele: mov ah,ch
     mov bx,si

dele1:     mov al,[si]
     cmp al,[di]
     jnz return1
     inc si
     inc di
     dec ch
     jz check
     jmp dele1

                    
return1:   lea di,arr2
     mov ch,ah
     mov si,bx
     mov al,[si]
     jmp return

                                    
check:     lea di,arr2
           sub cl,ch
           sub cl,01h
           cmp cl,00h
           jz next
           jmp core
                    
          
next:       mov ah,4ch
           int 21h
           code ends      
           end start 
     
DRAW A LINE

assume cs:code,ds:data

data segment
data ends
code segment
start: mov ah,00h
mov al,12h
int 10h
mov ah,0ch
mov al,04h
mov cx,100h
mov dx,150h

loop1: int 10h

inc cx
cmp cx,150h
jz  stop
jmp loop1

stop: mov ah,00h
int 16h
mov ax,03h
int 10h

mov ah,4ch
int 21h
code ends
end start


DRAW HOUSE

assume cs:code,ds:data data segment data ends code segment start: mov ah,00h mov al,12h int 10h mov ah,0ch mov al,04h mov cx,100h mov dx,250h mov bx,cx loop1: int 10h inc cx cmp cx,150h jz loop12 jmp loop1 loop12: mov cx,bx loop2: int 10h dec dx cmp dx,200h jz loop3 jmp loop2 loop3: int 10h inc cx cmp cx,150h jz loop4 jmp loop3 loop4: int 10h inc dx cmp dx,250h jz loop5 jmp loop4 loop5: mov cx,100h mov dx,200h loop6: int 10h inc cx dec dx cmp cx,129h jz loop7 jmp loop6 loop7: mov cx,150h mov dx,200h loop8: int 10h dec cx dec dx cmp cx,127h jz stop jmp loop8 stop: mov ah,00h int 16h mov ax,03h int 10h mov ah,4ch int 21h code ends end start

CREATE A FILE

assume cs: code,ds: data
data segment
fc db 0ah, 0dh,"File created$"
fnc db 0ah, 0dh,"File not created$"
filename db "hello.txt"
data ends

print macro
mov ah,09h
int 21h
endm

code segment
start:
mov cx,0001h
mov ax,data
mov ds,ax

lea dx,filename
mov ah,3ch
int 21h

jc notdone
lea dx,fc
mov ah,09h
int 21h
jmp stop

notdone:
lea dx,fnc
mov ah,09h
int 21h

stop:mov ah,4ch
int 21h
code ends

end start

OPEN AND WRITE INTO A FILE

assume cs:code, ds:data
data segment 
a db 0ah,0dh,"The file is created.$"
b db 0ah,0dh,"The file is not created$"
d db 0ah,0dh,"Error$"
e db 0ah,0dh,"Written$"
fname db "myfile1.txt"
fhandle dw 10 dup(?)
fdata db 100 dup('hello')
data ends
print macro
mov ah,09h
int 21h
endm
code segment
start:  mov ax,data
mov ds,ax
mov cl,00h
lea dx,fname
mov ah,3ch
int 21h
mov fhandle,ax
jnc l2
l1: lea dx,b
print
jmp l3
l2: lea dx,a
print
l3: mov ah,3dh
mov al,00h
mov dx,fhandle
int 21h
mov ah,40h
mov bx,fhandle
mov cx,5
lea dx,fdata
int 21h
jnc l5
l4: lea dx,d
print
jmp exit
l5: cmp ax,5
jne l6
jmp exit
l6: lea dx,d
print

exit: mov ah,4ch
int 21h
code ends
end start

FILE DELETION

assume cs:code, ds:data
data segment 
a db 0ah,0dh,"The file is created.$"
b db 0ah,0dh,"The file is not created$"
d db 0ah,0dh,"The file is deleted$"
fname db "MYFILE1.TXT"
fhandle dw 10 dup(?)
fdata db 100 dup('hello')
data ends
print macro
mov ah,09h
int 21h
endm
code segment
start:  mov ax,data
mov ds,ax
l6: mov ax,0000h
mov ah,41h
lea dx,fname
mov bx,fhandle
int 21h
lea dx,d
mov ah,09h
int 21h
exit: mov ah,4ch
int 21h
code ends
end start

FILE RENAME

assume cs:code,ds:data

data segment
fname db 'newfile2.txt',0
newfname db 20 dup(?)
fhandle1 dw 10 dup(?)
fhandle2 dw 10 dup(?)
msg1 db 0ah, 0dh, "File created$"
msg2 db 0ah, 0dh, "File not created$"
msg3 db 0ah,0dh,"File renamed$"
msg4 db 0ah, 0dh, "Unable to rename file$"
msg5 db 0ah,0dh,"Rename? (Y/N)$"
msg6 db 0ah,0dh,"Enter new file name: $"
data ends

print macro msg
mov ah, 09h
mov dx, offset msg
int 21h
endm

read macro
mov ah,01h
int 21h
endm

code segment
start: mov ax, data
mov ds, ax
mov es,ax
mov cx,0000h
lea dx,fname
;mov cx,20h
mov ah, 3ch
int 21h
mov fhandle1,ax
jnc l1
print msg2
jmp exit
l1: print msg1

here: print msg5
read
cmp al,'Y'
jne exit
print msg6
;mov ax,data
;mov es,ax
lea di,newfname
newname: read
cmp al,0dh
jz next
mov [di],al
inc di
jmp newname
next: mov ah,56h
lea dx,fname
lea di,newfname
int 21h
mov fhandle2,ax
jc error
print msg3
jmp exit
error: print msg4

exit: mov ah,4ch
int 21h

code ends
end start
DIRECTORY CREATION

assume cs:code,ds:data data segment f db 0ah,0dh,"directory created$" g db 0ah,0dh,"do you want to create directory if yes press 1 else press 2:$" h db 0ah,0dh,"$" path db'd:\siby\dir',00h fh dw 10 dup(?) data ends display macro mov ah,09h int 21h endm code segment start: mov ax,data mov ds,ax mov es,ax lea dx,g display lea dx,h display mov ah,01h int 21h sub al,30h cmp al,01h jnz stop mov ah,39h lea dx,path int 21h jc stop lea dx,f display stop: mov ah,4ch int 21h code ends end start

SET SYSTEM TIME

assume cs:code, ds:data data segment h db 0ah,0dh, "Enter hourr:$" m db 0ah,0dh, "Enter minute :$" s db 0ah,0dh, "Enter second :$" a db 0ah,0dh, "Time set:$" e db 0ah,0dh, "Time cannot be set :$" data ends read macro mov ah ,01h int 21h sub al,30h endm print macro p lea dx,p mov ah,09h int 21h endm code segment start: mov ax,data mov ds,ax print h read mov dh,0ah mov ah,00h mul dh mov ch,al read add ch,al print m read mov dh,0ah mov ah,00h mul dh mov cl,al read add cl,al print s read mov dh,0ah mov ah,00h mul dh mov dh,al read add dh,al int 21h jc l1 print a jmp l3 l1:print e l3:mov ah,4ch int 21h code ends end start

GET SYSTEM TIME


assume cs:code, ds:data
data segment
a db 0ah,0dh, "Time is:$"
b db ":$"
p db "am$"
q db "pm$"
data ends


print macro p
push dx
lea dx,p
mov ah,09h
int 21h
pop dx
endm

show macro x
push cx
push dx
mov ah,00h
mov al,x
mov cl,0ah
div cl
mov bx,ax
add bx,3030h
mov dl,bl
mov ah,02h
int 21h
mov dl,bh
mov ah,02h
int 21h
pop dx
pop cx
endm

code segment
start: 
mov di,0000h
mov cx,data
mov ds,cx
mov ah,2ch
int 21h
print a
cmp ch,0ch
jl loc1
mov di,0001h
sub ch,0ch
loc1:show ch
print b
show cl
print b
show dh
print b
show dl
cmp di,0001h
je loc2
print p
jmp last
loc2:print q
last:mov ah,4ch
int 21h
code ends
end start

SET SYSTEM DATE

assume cs:code, ds:data
data segment
a db 0ah,0dh, "Enter day:$"
b db 0ah,0dh, "Enter month :$"
p db 0ah,0dh, "Enter year :$"
q db 0ah,0dh, "Date set:$"
r db 0ah,0dh, "Cannot be set :$"
data ends

read macro
mov ah ,01h
int 21h
sub al,30h
endm



print macro p
lea dx,p
mov ah,09h
int 21h
endm

code segment
start: mov ax,data
mov ds,ax
mov ah,2bh
print a
read
mov dh,0ah
mov ah,00h
mul dh
mov ch,al
read
add ch,al

print b
read
mov dh,0ah
mov ah,00h
mul dh
mov cl,al
read
add cl,al

print p
read
sub al,30h
mov cx,03e8h
mov ah,00h
mul cx
mov bx,ax
read
sub al,30h
mov ch,064h
mul ch
add bx,ax
read
sub al,30h
mov ch,0ah
mul ch
add bx,ax
read
sub al,30h
mov ah,00h
add bx,ax


jc l1
print q
jmp l3
l1:print r
l3:mov ah,2bh
int 21h
mov ah,4ch
int 21h
code ends
end start

GET SYSTEM DATE

assume cs:code, ds:data
data segment
a db 0ah,0dh, "Date is:$"
b db "/$"
data ends


print macro p
push dx
lea dx,p
mov ah,09h
int 21h
pop dx
endm

show macro s
push dx
mov dl,s
add dl,30h
mov ah,02h
int 21h
pop dx
endm

code segment
start: 
mov cx,data
mov ds,cx
mov ah,2ah
int 21h
push cx
print a
mov al,dl
mov ah,00h
mov cl,0ah
div cl
mov cx,ax
show cl
show ch
print b
mov al,dh
mov ah,00h
mov cl,0ah
div cl
mov cx,ax
show cl
show ch
print b
pop cx
mov ax,cx
mov dx,0000h
mov di,03e8h
div di
mov cx,dx
show al
mov ax,cx
mov dx,0000h
mov di,064h
div di
mov cx,dx
show al
mov ax,cx
mov dx,0000h
mov di,0ah
div di
mov cx,dx
show al
mov ax,cx
show al

mov ah,4ch
int 21h
code ends
end start

KEYBOARD INTERFACE

assume cs:code, ds:data
data segment
a db 0ah,0dh, "Enter character:$"
p db 0ah,0dh, "Sucessfull:$"
q db 0ah,0dh, "Error:$"
data ends


print macro p
lea dx,p
mov ah,09h
int 21h
endm


code segment
start: 
mov cx,data
mov ds,cx

print a
loc:
mov ah,00h
int 16h
mov dl,al
mov ah,02h
int 21h
jc err
cmp dl,0dh
jne loc
print p
jmp last
err:
print q
last:
mov ah,4ch
int 21h
code ends
end start

PRINTER

assume cs:code, ds:data
data segment
a db 0ah,0dh, "Enter character:$"
p db 0ah,0dh, "Sucessfull:$"
q db 0ah,0dh, "Error:$"
data ends


print macro p
lea dx,p
mov ah,09h
int 21h
endm


code segment
start: 
mov cx,data
mov ds,cx

print a
mov ah,02h
int 0000h
int 17h
jz err
loc:mov ah,00h
int 16h
mov ch,al
mov dl,ch
mov ah,02h
int 21h
mov ah,00h
mov dx,0000h
int 17h
cmp al,0dh
jne loc
print p
jmp last
err:print q
last:mov ah,4ch
int 21h
code ends
end start

PALLINDROME

assume cs:code,ds:data
data segment
a db 0ah,0dh,"enter the string to be checked:$"
b db 0ah,0dh,"it is pallindrome!$"
d db 0ah,0dh,"sorry it is not pallindrome:$"
array1 db 30 dup(?)
data ends

read macro
mov ah,01h
int 21h
endm

msg macro
mov ah,09h
int 21h
endm

code segment
start: mov ax,data
mov ds,ax

lea dx,a
msg

mov ch,00h
lea si,array1
lea di,array1

loop1: read
cmp al,0dh
jz check1
inc ch
mov [si],al
inc si
jmp loop1

check1: dec si

check: mov bx,si
clc
cmp bx,di
jz printpal
jc printpal
mov bx,0000h
mov al,[di]
cmp al,[si]
jnz printnopal
dec ch
dec ch
dec si
inc di
jmp check

printpal: lea dx,b
msg
jmp stop

printnopal: lea dx,d
   msg

stop: mov ah,4ch
int 21h
code ends
end start

SEPARATE  EVEN NUMBERS

assume cs:code,ds:data
data segment
a db 0ah,0dh,"enter the limit:$"
b db 0ah,0dh,"enter the number:$"
d db 0ah,0dh,"the even numbers are:$"
e db 0ah,0dh,"$"
f db 0ah,0dh,"sorry no even numbers found!$"
arr1 db 30 dup(?)
data ends

read macro
mov ah,01h
int 21h
sub al,30h
endm

print macro
add al,30h
mov ah,02h
int 21h
endm

display macro
mov ah,09h
int 21h
endm

code segment
start: mov ax,data
mov ds,ax
lea dx,a
display
read
mov ch,al
mov bh,ch
lea dx,b
display
mov bl,00h
lea si,arr1
loop1: lea dx,e
display


read
mov [si],al
dec ch
jz loop2
inc si
jmp loop1
loop2:  lea si,arr1
mov cl,02h
loop3: mov ah,00h
mov al,[si]
div cl
cmp ah,00h
jz output
return: dec bh
jz stop
inc si
jmp loop3
output: cmp bl,00h
jnz out1
lea dx,d
display


out1: lea dx,e
display

mov dl,[si]
print
inc bl
jmp return
stop: cmp bl,00h

jz msg
jmp stop1
msg: lea dx,f
display


stop1:  lea dx,e
display

mov ah,4ch
int 21h
code ends
end start
SORTING

assume cs:code,ds:data

data segment
a db 0ah,0dh,"enter the size of the array:$"
b db 0ah,0dh,"enter the elements:$"
d db 0ah,0dh,"the sorted array is:$"
e db 0ah,0dh,"$"
array1 db 30 dup(?)
data ends

read macro
mov ah,01h
int 21h
sub al,30h
mov ah,00h
endm

print macro
add dl,30h
mov ah,02h
int 21h
endm

msg macro
mov ah,09h
int 21h
endm

code segment

start: mov ax,data
mov ds,ax
lea dx,a
msg
lea dx,e
msg

mov cl,00h

read

mov cl,al
mov bl,cl
lea dx,b
msg
lea si,array1

loop1: lea dx,e
msg
read
mov [si],al
inc si
dec cl
jz sort
jmp loop1

sort: lea dx,d
msg
mov cl,bl

sort1:dec cl

loop3:       lea si,array1
         mov ch,bl
        dec ch

loop4: mov al,[si]
inc si
cmp al,[si]
jc loop5
xchg al,[si]
xchg [si-1],al

loop5: dec ch
jz loop6
jmp loop4

loop6: dec cl
jz print1
jmp loop3

print1: lea si,array1

loop7: lea dx,e
        msg
        mov dl,[si]
        print
        inc si
        dec bl
        jz stop
        jmp loop7

stop: mov ah,4ch
int 21h
code ends
end start