Sie sind auf Seite 1von 90

;buble sort

maxi equ 10d

read macro ; macro to read a character in bl


push ax
mov ah, 01h
int 21h
mov bl, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

make_entry macro x ; x cannot be any of ah or al


push ax
push dx
read
mov dh, bl
read
mov dl, bl
and dx, 0f0fh
mov ax, dx
aad
pop dx
mov x, al
pop ax
endm

show macro x
push ax
push bx
mov al, x
aam
mov bx, ax
or bx, 3030h
write bh
write bl
pop bx
pop ax
endm

; ------------- data segment ------------------------

_data segment
msg1 db ' enter the no. of terms present (max 10) : $'
msg2 db ' make your entry : $'
msg3 db ' the sorted array is (in ascending order) : $'
msg4 db ' no. of items exceeds the limit$'
vars db maxi dup (0)
var1 db ?
var2 db ?
_data ends

; --------- stack segment ------------------------

_stack segment stack


dw 80 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
lea sp, stack_top ; initialise stack pointer

print msg1 ; display msg1

xor cx, cx
make_entry cl ; cl contains the no. of terms

mov ch, 00h


lea si, vars
loop1: write 0ah
write 0dh
print msg2
make_entry bh ; entries been made
mov byte ptr [si], bh
inc ch
inc si
cmp ch, cl
jne loop1
cmp cl, maxi
jg errormsg

lea si, vars


mov var1, cl
xor dl, dl
jmp loop2
errormsg: print msg4
jmp last

loop2: mov bh, var1


mov var2, bh
xor bx, bx
dec var2
loop3: mov ah, byte ptr [si+bx]
mov al, byte ptr [si+bx+0001h]
cmp ah, al
jl loop4
mov byte ptr [si+bx], al
mov byte ptr [si+bx+0001h], ah
loop4: inc bl
cmp bl, var2
jne loop3
inc dl
cmp dl, var1
jne loop2

write 0ah
write 0dh
print msg3

lea si , vars
xor ch, ch
loop5: mov bl, byte ptr [si]
show bl
write 20h
inc si
inc ch
cmp ch, cl
jne loop5

last: mov ax, 4c00h


int 21h

_code ends
end start

; program to design a two digit calculator(+,-,*,/)for single digit number.

print macro msg


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

data segment
msg1 db "enter the expression = $"
msg2 db "the result = $"
ends data

code segment
assume cs:code,ds:data

start : mov ax,data


mov ds,ax
print msg1

mov ah,01h
int 21h
mov bh,al
sub bh,30h
int 21h
mov bl,al
cmp bl,197d
je plus
cmp bl,196d
je minus

plus : mov ah,01h


int 21h
sub al,30h
add bh,al
or bh,30h

mov ah, 02h


mov dl, 0ah
int 21h
mov dl, 0dh
int 21h
print msg2

mov ah,02h
mov dl,bh
int 21h
jmp last

minus: mov ah,01h


int 21h
sub al,30h
sub bh,al
or bh,30h

mov ah, 02h


mov dl, 0ah
int 21h
mov dl, 0dh
int 21h
print msg2

mov ah,02h
mov dl,bh
int 21h
jmp last
last : mov ax,4c00h
int 21h

code ends
end start

data segment
msge1 db 'dir-name changed$'
msge2 db 'error$'
dir db 'raj',0
data ends

code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov ah,38h
mov dx,offset dir
int 21h
jc loop1
mov dx,offset msge1
mov ah,09h
int 21h
mov ax,4c00h
int 21h
loop1: mov dx,offset msge2
code ends
end

;----------------------------------------------------------------------
; program to clear screen (scroll up) and place cursor at bottom left
;----------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; c:\tasm\bin\indranil\cls_bl.asm ( 8086 program)
; dated : 30-11-2000.
;----------------------------------------------------------------------
attri equ 02h ; attribute to be used in specified area

code segment
assume cs : code
start: mov ah, 0fh
int 10h ; get current video mode
mov bl, bh ; active display page

mov dl, ah ; no. of character cols. on screen


mov ah, 06h ; interrupt function no.
mov al, 00h ; zero as whole screen is to be blanked
mov bh, attri ; attribute in the specified region
mov ch, 00h ; top left y co-ordinate
mov cl, 00h ; top left x co-ordinate
mov dh, 19h ; bottom right y co-ordinate
int 10h ; interrupt to scroll window up
; ( using int 10h ( function 06h) )
mov ah, 02h ; function no. to set cursor
mov bh, bl ; active display page
mov dh, 18h ; top left y co-ordinate
mov dl, 00h ; top left x co-ordinate
int 10h ; interrupt to set cursor ( int 10h(02h) )

mov ah, 01h


int 21h ; to prompt the user to press any key

mov ax, 4c00h


int 21h ; terminate process
code ends
end start

;----------------------------------------------------------------------
; end of program
;----------------------------------------------------------------------

;----------------------------------------------------------------------
; program to clear screen (scroll up) and place cursor at bottom left
;----------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; c:\tasm\bin\indranil\cls_bl.asm ( 8086 program)
; dated : 30-11-2000.
;----------------------------------------------------------------------
attri equ 02h ; attribute to be used in specified area

code segment
assume cs : code
start: mov ah, 0fh
int 10h ; get current video mode
mov bl, bh ; active display page

mov dl, ah ; no. of character cols. on screen


mov ah, 06h ; interrupt function no.
mov al, 00h ; zero as whole screen is to be blanked
mov bh, attri ; attribute in the specified region
mov ch, 00h ; top left y co-ordinate
mov cl, 00h ; top left x co-ordinate
mov dh, 19h ; bottom right y co-ordinate
int 10h ; interrupt to scroll window up
; ( using int 10h ( function 06h) )

mov ah, 02h ; function no. to set cursor


mov bh, bl ; active display page
mov dh, 18h ; top left y co-ordinate
mov dl, 00h ; top left x co-ordinate
int 10h ; interrupt to set cursor ( int 10h(02h) )

mov ah, 01h


int 21h ; to prompt the user to press any key

mov ax, 4c00h


int 21h ; terminate process
code ends
end start
;----------------------------------------------------------------------
; end of program
;----------------------------------------------------------------------

;------------------------------------------------------------------------
; program to clear a specified portion of the screen
;------------------------------------------------------------------------

attri equ 02h ; attribute of specified portion

print macro x ; macro to display a string


mov ah, 09h
mov dx, offset x
int 21h
endm

read macro ; macro to read a character


mov ah, 01h
int 21h
endm

write macro x ; macro to write a character


mov ah, 02h
mov dl, x
int 21h
endm

take_val macro ; macro to input a two digit no. and place


its binary in al
read
mov dh, al
read
mov dl, al
mov ax, dx
and ax, 0f0fh
aad
endm

data segment
msg1 db ' enter the top left x co-ordinate ( 2 digits) :
$'
msg2 db ' enter the top left y co-ordinate ( 2 digits) :
$'
msg3 db ' enter the bottom right x co-ordinate ( 2
digits) : $'
msg4 db ' enter the bottom right y co-ordinate ( 2
digits) : $'
msg5 db ' invalid entry made$'
data ends

code segment
assume cs : code , ds : data
start: mov ax, data
mov ds, ax ; initialise ds register
print msg1 ; display msg1
take_val ; input the top left x co-ordinate
cmp al, 50h ; al should be less than 80d (i.e. 50h)
jg errormsg
mov cl, al ; top left x co-ordinate

write 0ah
write 0dh ; move cursor to next line
print msg2 ; display msg2
take_val ; input the top left y co-ordinate
cmp al, 19h ; al should be less than 25d (i.e. 19h)
jg errormsg
mov ch, al ; top left y co-ordinate
jmp loop0

errormsg: print msg5


jmp last

loop0: write 0ah


write 0dh ; move cursor to next line
print msg3 ; display msg3
take_val ; input the bottom right x co-ordinate
cmp al, 50h ; al should be less than 80d (i.e. 50h)
jg errormsg
mov bh, al
write 0ah
write 0dh ; move cursor to next line
print msg4 ; display msg4
take_val ; input the bottom right y co-ordinate
cmp al, 19h ; al should be less than 25d (i.e. 19h)
jg errormsg
mov dh, al ; bottom right y co-ordinate
mov dl, bh ; bottom right x co-ordinate

mov ah, 06h ; interrupt function no.


mov al, dh
sub al, ch ; no. of lines to scroll ( al = dh-ch )
mov bh, attri ; attribute used in specified area
int 10h ; interrupt call

last: mov ax, 4c00h


int 21h ; terminate with return code
code ends
end start

;-----------------------------------------------------------------------------

; program to delete file (using 21h, function 41h)


;-----------------------------------------------------------------------------
; programmed by indranil gupta (regn. no. 98011015)
; j;\tasm12\del_file.asm
;-----------------------------------------------------------------------------

_data segment ; data segment begins here


file_name db 'new.txt',0 ; name of file to be deleted
msg1 db 'successful$' ; messages
msg2 db 'not successful$'
_data ends ; end of data segment

_code segment ; code segment begins here


assume cs:_code, ds:_data
start: mov ax,_data
mov ds, ax
mov dx, offset file_name
mov ah, 41h ; call of interrupt to delete file
int 21h ; int 21h, function 41h
jc errmsg
mov dx, offset msg1
jmp last
errmsg: mov dx, offset msg2
last: mov ah, 09h ; call of interrupt to display
message
int 21h ; int 21h, function 09h

mov ax,4c00h ; call of interrupt to terminate


program
int 21h

_code ends ; code segment ends here


end start

;-----------------------------------------------------------------------------
; end of program
;-----------------------------------------------------------------------------

data segment
msge1 db 'file-deleted$'
msge2 db 'error$'
file db 'raj.txt',0
data ends

code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov ah,41h
mov dx,offset file
int 21h
jc loop1
mov dx,offset msge1
mov ah,09h
int 21h
mov ax,4c00h
int 21h
loop1: mov dx,offset msge2
code ends
end

;-------------------------------------------------------------------------
; program to display the ascii code of a character pressed
;-------------------------------------------------------------------------

; programmed by indranil gupta (regn no. 98011015)


; j:\tasm12\bin\dis_asc.asm ( 8086 program)
; dated : 23-10-2000.
;-------------------------------------------------------------------------

data segment
msg1 db 'enter any character : $'
msg2 db 'the equivalent ascii code in hex is $'
data ends

code segment
assume cs:code, ds:data
start: mov ax, data
mov ds, ax ; initialise ds register

mov ah, 09h


mov dx, offset msg1
int 21h ; display message to enter character

mov ah, 01h


int 21h ; read character from console
mov bl, al

mov ah, 02h


mov dl, 0ah
int 21h ; to insert a new line character
mov dl, 0dh
int 21h

mov ah, 09h


mov dx, offset msg2
int 21h ; to display message 2

mov al, bl
and bl, 0fh ; masking lower nibble of bl

cmp bl, 0ah


jge pos1
or bl, 30h
jmp pos2

pos1: sub bl, 09h


or bl, 40h
pos2: and al, 0f0h ; masking higher nibble of al
ror al, 04h
or al, 30h

mov ah, 02h


mov dl,al
int 21h ; displaying first hex character of hex
code
mov dl,bl
int 21h ; displaying next hex character of hex
code

mov ax, 4c00h ; terminate program


int 21h

code ends
end start

;-------------------------------------------------------------------------

; end of program
;-------------------------------------------------------------------------

;---------------------------------------------------------------------------

; program to display the ascii graphic character of hex no.


;---------------------------------------------------------------------------

; programmed by indranil gupta


;---------------------------------------------------------------------------

data segment
msg1 db 0ah,0dh,' enter the two digit hex code (0-9,a-f)
: $'
msg2 db 0ah,0dh,' the equivalent character is : $'
msg3 db 0ah,0dh,' error in input$'
data ends

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

mov ah, 09h


mov dx, offset msg1
int 21h

mov ah, 01h


int 21h
mov bh, al
int 21h
mov bl, al

cmp bh, 30h


jl err1
cmp bh, 39h
jg l1
and bh, 0fh
jmp l2
l1: cmp bh, 61h
jl err1
cmp bh, 66h
jg err1
sub bh, 57h

l2: cmp bl, 30h


jl err1
cmp bl, 39h
jg l3
and bl, 0fh
jmp l4
l3: cmp bl, 61h
jl err1
cmp bl, 66h
jg err1
sub bl, 57h

l4: shl bh, 04h


or bh, bl

mov ah, 09h


mov dx, offset msg2
int 21h
mov ah, 02h
mov dl, bh
int 21h
jmp last

err1: mov ah, 09h


mov dx, offset msg3
int 21h

last: mov ax, 4c00h


int 21h

code ends
end start

;---------------------------------------------------------------------------

; end of program
;---------------------------------------------------------------------------

;---------------------------------------------------------------------
; program to find wheather a no. is even or odd.
;---------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015)
; j:\tasm12\bin\indranil\even_odd.asm (8086 program)
; dated : 30-11-2000.
;---------------------------------------------------------------------

print macro x ; macro to display a string


mov ah, 09h
mov dx, offset x
int 21h
endm
read macro ; macro to read a character
mov ah, 01h
int 21h
endm

write macro x ; macro to write a character


mov ah, 02h
mov dl, x
int 21h
endm

data segment
msg1 db ' enter any two digit decimal no. : $'
msg2 db ' the no. is even.$'
msg3 db ' the no. is odd.$'
msg4 db ' invalid input$'
data ends

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

print msg1

read
cmp al, 30h
jl errormsg
cmp al, 39h
jg errormsg
mov bh, al
read
cmp al, 30h
jl errormsg
cmp al, 39h
jg errormsg
mov bl, al

write 0ah
write 0dh

and bx, 0f0fh


mov ax, bx
aad
mov bl, 02h
div bl
cmp ah, 00h
je loop1
print msg3
jmp loop2
loop1: print msg2
jmp loop2
errormsg: print msg4
loop2: mov ax, 4c00h
int 21h
code ends
end start
;---------------------------------------------------------------------

; end of program
;---------------------------------------------------------------------

; name : dipendra shrestha


; roll : 10
; program to check whether an input no is even or odd

print macro msg ;macro for displaying message


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

better_display macro ;code for better display


mov ah,02h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
endm

data segment
msg1 db "enter a 2-digit no = $"
msg2 db "the no is even$"
msg3 db "the no is odd$"
data ends

code segment
assume cs:code,ds:data

start : mov ax,data


mov ds,ax

print msg1

mov ah,01h
int 21h
mov bh,al
int 21h
mov bl,al

and bx,0f0fh
better_display
mov ax,bx
mov bl,02h
div bl
cmp ah,0h
je iseven
print msg3
jmp last

iseven : print msg2


jmp last
last : mov ax,4c00h
int 21h

code ends
end start

;--------------------------------------------------------------------
; program to find the factorial of a no. by iterative methord
;--------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015)
; c:\tasm\bin\fact_hex.asm ( 8086 program)
; dated : 30-11-2000.
;--------------------------------------------------------------------

print macro x ; macro to print a message x


mov ah, 09h
mov dx, offset x
int 21h
endm

read macro ; macro to read a character


mov ah, 01h
int 21h
endm

write macro x ; macro to write a character


mov ah, 02h
mov dl, x
int 21h
endm

data segment
msg1 db ' enter any single digit decimal no. < 9 : $'
msg2 db ' the factorial in hex is $'
msg3 db ' invalid input or out of range$'
var1 db ?
data ends

code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialise ds

print msg1

read ; read a character


cmp al, 30h
jl errormsg
cmp al, 38h
jg errormsg
mov var1, al
and var1, 0fh

write 0ah
write 0dh ; move cursor to new line

print msg2

xor ax, ax
mov al, var1
mov cx, ax ; cx <- ax
dec cx

cmp var1, 01h


jg loop1 ; if entered value is 0 or 1 display 1
write 31h
jmp loop6

loop1: mul cx ; ax <- ax * cx


dec cx
cmp cx, 0000h
jne loop1

xor cx, cx
mov bx, ax ; bx contains the factorial
loop2: xor cl, cl
xor dh, dh
loop3: shl bx, 01h ; shift msb of bx to carry bit
rcl dh, 01h ; rotate dh left through carry bit
inc cl
cmp cl, 04h
jne loop3

cmp dh, 0ah


jg loop4
add dh, 30h ; displayed value lies between 0 to 9
jmp loop5
loop4: add dh, 37h ; displayed value lies between a to f
loop5: write dh
inc ch
cmp ch, 04h
jne loop2
write 68h ; append the result with character h
jmp loop6

errormsg: print msg3


loop6: mov ax, 4c00h ; terminate process
int 21h
code ends
end start

;--------------------------------------------------------------------
; end of program
;--------------------------------------------------------------------
;-------------------------------------------------------------------------
; program to find the factorial of a number using recursion
;-------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015)
; c:\tasm\bin\indranil\fact_rec.asm ( 8086 program )
; dated : 30-11-2000.
;-------------------------------------------------------------------------

read macro
push ax
mov ah, 01h
int 21h
mov bl, al
pop ax
endm

write macro x
push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x
push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

_data segment
msg1 db ' enter the number ( < 9 ) : $'
msg2 db ' the factorial in hex is : $'
msg3 db ' invalid input or out of range$'
_data ends

_stack segment stack


dw 30 dup (0)
stack_top label word
_stack ends

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax
mov ax, _stack
mov ss, ax
lea sp, stack_top

print msg1

read
cmp bl, 30h
jl errormsg
cmp bl, 38h
jg errormsg
and bl, 0fh
xor cx, cx
mov cl, bl
jmp l0

errormsg : print msg3


jmp last

l0: write 0ah


write 0dh

print msg2

xor ax, ax
mov ax, 0001h

call fact

mov bl, ah
call show
mov bl, al
call show
write 'h'

jmp last

fact proc near


cmp cx, 0000h
je l1
mul cx
dec cx
call fact
l1: ret
endp

show proc near


mov bh, bl
and bh, 0f0h
shr bh, 04h
cmp bh, 0ah
jl l2
add bh, 37h
jmp l3
l2: add bh, 30h
l3: write bh
mov bh, bl
and bh, 0fh
cmp bh, 0ah
jl l4
add bh, 37h
jmp l5
l4: add bh, 30h
l5: write bh
ret
endp

last: mov ax, 4c00h


int 21h

_code ends
end start

;-------------------------------------------------------------------------
; end of program
;-------------------------------------------------------------------------

; name : dipendra shrestha


; roll : 10
; program to generate the fibonacci series

print macro msg ;macro definition for diaplaying message


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

data segment
msg1 db "enter the no of terms(max 5) = $"
msg2 db "the fibonacci series = $"
n db ?
var db ?
data ends

code segment
assume cs:code,ds:data

start : mov ax,data


mov ds,ax
print msg1

mov ah,01h
int 21h
and al,0fh
mov n,al

mov ah,02h ;code for better display


mov dl,0ah
int 21h
mov dl,0dh
int 21h
print msg2

mov cl,00h
mov bl,00h
mov bh,01h
mov ch,01h
mov ah,02h
mov dl,30h
int 21h
mov dl,31h
int 21h

loop1: mov ah,02h


or ch,30h
mov dl,ch
int 21h
mov var,ch
mov ch,00h
mov bl,bh
mov bh,var
mov ch,bh
and bl,0fh
add ch,bl
inc cl
cmp cl,n
jne loop1

last : mov ax,4c00h ;terminating the program


int 21h

code ends
end start

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

read macro
mov ah, 01h
int 21h
endm

write macro x
mov ah, 02h
mov dl, x
int 21h
endm

data segment
msg1 db ' enter the two digit no. of terms (max 11) : $'
msg2 db ' the fibonacii terms are :-$'
msg3 db ' invalid entry or out or range$'
var1 db ?
var2 db ?
data ends

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

print msg1

read
cmp al, 30h
jl errormsg
cmp al, 31h
jg errormsg
mov bh, al
read
cmp al, 30h
jl errormsg
cmp al, 39h
jg errormsg
mov bl, al

and bx, 0f0fh


mov ax, bx
aad
cmp al, 01h
jl loop2
cmp al, 0bh
jg errormsg
mov bl, al
jmp loop0

errormsg: print msg3


jmp loop2

loop0: write 0ah


write 0dh
print msg2
xor cl, cl
mov bh, 00h
mov dh, 01h
write 30h
write 31h
write 20h
dec bl
cmp bl, 01h
jl loop2
loop1: mov ch, bh
add ch, dh
mov al, ch
aam
or ax, 3030h
mov var1, ah
mov var2, al
write var1
write var2
write 20h
mov bh, dh
mov dh, ch
inc cl
cmp cl, bl
jne loop1

loop2: mov ax, 4c00h


int 21h

code ends
end start

;----------------------------------------------------------------------
; program to copy contents of source file to destination file
;----------------------------------------------------------------------
; programmed by indranil gupta (regn. no. 98011015)
; j:\tasm12\bin\fil_copy.asm (8086 program)
; dated : 23-10-2000.
;----------------------------------------------------------------------

data segment
srcfile db 'abc.txt',0 ; source file
dstfile db 'xyz.txt',0 ; destination file
fhan1 dw ? ; file handlers
fhan2 dw ?
buffer db 100 dup (0)
msg1 db 'successful$'
msg2 db 'not successful$'
data ends

code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialize ds register

mov ah, 3dh


mov al, 80h
mov dx, offset srcfile
int 21h ; open srcfile in reading mode
jc errormsg
mov fhan1, ax

mov ah, 3dh


mov al, 81h
mov dx, offset dstfile
int 21h ; open dstfile in writing mode
jc errormsg
mov fhan2, ax

mov ah, 3fh


mov bx, fhan1
mov cx, 100
mov dx, offset buffer
int 21h ; read the contents of first file
jc errormsg

mov cx, ax
mov ah, 40h
mov bx, fhan2
mov dx, offset buffer
int 21h ; write the contents of second file
jc errormsg

mov ah, 3eh


mov bx, fhan1
int 21h ; close srcfile
jc errormsg

mov ah, 3eh


mov bx, fhan2
int 21h ; close dstfile
jc errormsg

mov dx, offset msg1


jmp last
errormsg: mov dx, offset msg2
last: mov ah, 09h
int 21h ; display message

mov ax, 4c00h


int 21h ; terminate process
code ends
end start

;----------------------------------------------------------------------
; end of program
;----------------------------------------------------------------------

;---------------------------------------------------------------------------
; program to set or get file attributes
;---------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; c:\tasm\bin\file_att.asm ( 8086 program )
;---------------------------------------------------------------------------

read macro ; macro to read a character in al


mov ah, 01h
int 21h
endm
write macro x ; macro to write a chararacter x
mov dl, x
mov ah, 02h
int 21h
endm

print macro x ; macro to display a string


mov dx, offset x
mov ah, 09h
int 21h
endm

data segment
filename db 15 dup (0)
msg1 db 0ah,0dh,' enter 1 to set file attributes $'
msg2 db 0ah,0dh,' or any other key to set file attributes
: $'
msg3 db 0ah,0dh,' enter the file name : $'
msg4 db 0ah,0dh,' enter the no. of attributes you want to
have : $'
msg5 db 0ah,0dh,' the file attributes are : $'
msg6 db 0ah,0dh,' enter $'
msg7 db 0ah,0dh,' enter the attribute to be set : $'

msgr db ' read only $'


msgh db ' hidden $'
msgs db ' system $'
msgv db ' volume label $'
msga db ' normal ( archive ) $'
err1 db 0ah,0dh,' invalid file name$'
data ends

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

print msg1
print msg2
read
mov cl, al

print msg3
lea si, filename
l1: read
cmp al, 0dh
je l2
mov byte ptr [si], al
inc si
jmp l1

l2: mov byte ptr [si], 00h


cmp cl, 31h
je l7

mov ah, 43h


mov al, 00h
mov dx, offset filename
int 21h
jc errmsg
mov bl, cl
print msg5
and cl, 01h
cmp cl, 00h
je l3
print msgr
l3: mov cl, bl
and cl, 02h
cmp cl, 00h
je l4
print msgh
l4: mov cl, bl
and cl, 04h
cmp cl, 00h
je l5
print msgs
l5: mov cl, bl
and cl, 08h
cmp cl, 00h
je l6
print msgv
l6: mov cl, bl
and cl, 20h
cmp cl, 00h
je last
print msga
jmp last
errmsg: print err1
last: mov ax, 4c00h
int 21h

l7: print msg5


print msg6
write 'r'
print msgr
print msg6
write 'h'
print msgh
print msg6
write 's'
print msgs
print msg6
write 'v'
print msgv
print msg6
write 'n'
print msga

print msg4
read
mov cl, al
and cl, 0fh
print msg7

xor ch, ch
xor bl, bl
l8: read
cmp al, 'r'
jne l9
or bl, 01h
jmp ld
l9: cmp al, 'h'
jne la
or bl, 02h
jmp ld
la: cmp al, 's'
jne lb
or bl, 04h
jmp ld
lb: cmp al, 'v'
jne lc
or bl, 08h
jmp ld
lc: or bl, 20h
ld: inc ch
cmp ch, cl
jne l8

mov ah, 43h


mov al, 01h
xor cx, cx
mov cl, bl
mov dx, offset filename
int 21h
jnc lf
print err1
lf: mov ax, 4c00h
int 21h

code ends
end start

;---------------------------------------------------------------------------
; end of program
;---------------------------------------------------------------------------

;name : dipendra shrestha


;roll no : 10
;program to transfer the contents of the source file to destination file

print macro message ;macro for displaying message


mov ah,09h
mov dx,offset message
int 21h
endm

data segment
source db 80 dup(0)
dest db 80 dup(0)
recsize equ 512
rdcount dw ?
buff db recsize dup(0)
handle1 dw ?
handle2 dw ?
msg1 db "enter source filename$"
msg2 db 0ah,0dh,"enter destination filename$"
error_msg db "error$"
success_msg db "1 file copied$"
data ends

text segment
assume cs:text,ds:data

main : mov ax,data


mov ds,ax
print msg1; accept source file name
mov si,offset source
loop1 : mov ah,01h
int 21h
cmp al,0dh
je done1
mov [si],al
inc si
jmp loop1

done1 :print msg2 ;accept dest file name


mov si,offset dest
loop2 : mov ah,01h
int 21h
cmp al,0dh
je done2
mov [si],al
inc si
jmp loop2
done2 : ;open source in read mode
mov ah,3dh
mov al,00
mov dx,offset source
int 21h
jc file_error
mov handle1,ax ;further used to access file
;create dest file
mov ah,3ch
mov cx,00 ;normal
mov dx,offset dest
int 21h
jc file_error
mov handle2,ax

read_file: ;read source file


mov ah,3fh
mov bx,handle1
mov cx,recsize ;(whole sector) n. of byte to be read
mov dx,offset buff
int 21h
jc file_error
mov rdcount,ax ;no of character read ax=0 eof
mov ah,40h
mov bx,handle2
mov cx,rdcount
mov dx,offset buff
int 21h
jc file_error
mov ah,09h
mov dx,offset success_msg
int 21h
cmp cx,recsize
je read_file

file_end :
mov ah,3eh
mov bx,handle1
int 21h
mov ah,3eh
mov dx,handle2
int 21h
jmp quit

file_error: ;display error message


mov dx,offset error_msg
mov ah,09h
int 21h
quit :
mov ax,4c00h
int 21h
text ends
end main

; name : dipendra shrestha


; roll : 10
; program to convert a hexadecimal no. into a decimal no.

print macro msg ; macro for displaying message


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

data segment
msg1 db "enter the hexadecimal no = $"
msg2 db "its decimal equivalent = $"
data ends

code segment
assume cs:code,ds:data

start : mov ax,data


mov ds,ax
print msg1

mov ah,01h ;inputting the headecimal no.


int 21h
mov bh,al
int 21h
mov bl,al
mov ah,02h ;code for better display
mov dl,0ah
int 21h
mov dl,0dh
int 21h

print msg2

cmp bh,3ah
jg l1
sub bh,30h
jmp l2

l1 : sub bh,37h

l2 : cmp bl,3ah
jg l3
sub bl,30h
jmp l4

l3 : sub bl,37h

l4 : shl bh,04h
or bh,bl
xor ax,ax
mov al,bh
aam
mov bx,ax
or bx,3030h

mov ah,02h
mov dl,bh
int 21h
mov dl,bl
int 21h

mov ax,4c00h
int 21h

code ends
end start

data segment
msg1 db ' enter any two digit hexadecimal no. (<64h) : $'
msg2 db ' the equivalent bcd no. is : $'
msg3 db ' invalid entry or out of range$'
data ends

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

mov ah, 09h


mov dx, offset msg1
int 21h
mov ah, 01h
int 21h
mov bh, al
int 21h
mov bl, al

mov ah, 02h


mov dl, 0ah
int 21h
mov dl, 0dh
int 21h

cmp bh, 36h


jg errormsg

loop1: and bh, 0fh


cmp bl, 3ah
jl loop2
sub bl, 37h
loop2: and bl, 0fh
shl bh, 04h
or bh, bl
mov al, bh
cmp al, 63h
jg errormsg
aam
mov bx, ax

cmp bh, 00h


jl errormsg
cmp bh, 09h
jg errormsg
cmp bl, 00h
jl errormsg
cmp bl, 09h
jg errormsg

shl bh, 04h


or bh, bl

mov ah, 09h


mov dx, offset msg2
int 21h

xor bl, bl
loop3: shl bh, 01h
jc loop4
mov dl, 30h
jmp loop5
loop4: mov dl, 31h
loop5: mov ah, 02h
int 21h
inc bl
cmp bl, 08h
je loop6
cmp bl, 04h
jne loop3
mov dl, 20h
int 21h
jmp loop3

errormsg: mov ah, 09h


mov dx, offset msg3
int 21h

loop6: mov ax, 4c00h


int 21h

code ends
end start

;--------------------------------------------------------------------------
; program to convert hexadecimal no. to binary no.
;--------------------------------------------------------------------------
; programmed by indranil gupta (regn. no. 98011015)
; j:\tasm12\bin\hex_bin.asm (8086 program)
; dated : 30-10-2000.
;--------------------------------------------------------------------------

dis_char macro x ; macro to display character x


mov dl, 30h
add dl, x
mov ah, 02h
int 21h
endm

data segment
msg1 db ' enter any hexadecimal no. : $'
msg2 db ' the equivalent binary is : $'
msg3 db 'invalid entry made$'
hex_val db 5 dup (0)
data ends

code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialize ds register

mov ah, 09h


mov dx, offset msg1
int 21h ; display initial message

xor cx, cx ; clear cx

lea bx, hex_val ; initialise bx with offset of an array


loop1: mov ah, 01h
int 21h ; reading the hexadecimal input
mov byte ptr [bx], al
inc bx
inc cx
cmp al, 0dh ; terminate input of pressing enter key
je loop2

cmp al, 2fh ; to check that input character lies beyond 2fh
jl errormsg

cmp al, 66h ; to chech that input character lies before 66h
jg errormsg

cmp al, 3ah


jl loop1 ; character lies between 0 to 9

cmp al, 40h ; to chech that input character lies after 3ah &
before 40h
jl errormsg

cmp al, 47h


jl loop1 ; character lies between a to f

cmp al, 60h


jl errormsg ; to chech that input character lies after 47h &
before 60h

jmp loop1 ; character lies between a to f

loop2: sub bx, cx

mov ah, 02h


mov dl, 0ah
int 21h
mov dl, 0dh
int 21h ; move cursor to next line

mov ah, 09h


mov dx, offset msg2
int 21h ; display message

loop3: cmp byte ptr [bx], 3ah ;


jg loop4
and byte ptr [bx], 0fh
jmp loop5

loop4: and byte ptr [bx], 0fh


add byte ptr [bx], 09h

loop5: rol byte ptr [bx], 04h


xor cx, cx

loop6: shl byte ptr [bx], 01h


jc loop7
dis_char 00h
jmp loop8
loop7: dis_char 01h
loop8: inc cx
cmp cx, 04h
jne loop6
mov ah, 02h
mov dl, 20h
int 21h

inc bx
cmp byte ptr [bx], 0dh ; continue until enter key is obtained
jne loop3

jmp loop9

errormsg: mov ah, 09h


mov dx, offset msg3
int 21h

loop9: mov ax, 4c00h


int 21h
code ends
end start

;--------------------------------------------------------------------------
; end of program
;--------------------------------------------------------------------------

;-----------------------------------------------------------------------
; program to convert hexadecimal no. to binary no.
;-----------------------------------------------------------------------
; programmed by indranil gupta (regn. no. 98011015)
; j:\tasm12\bin\hex_dec.asm (8086 program)
; dated: 30-10-2000.
;-----------------------------------------------------------------------

data segment
msg1 db ' enter a two digit hexadecimal no. ( < 63h ) : $'
msg2 db ' the decimal equivalent is $'
data ends

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

mov ah, 09h


mov dx, offset msg1
int 21h

mov ah, 01h


int 21h
mov bh, al

mov ah, 01h


int 21h
mov bl, al

cmp bl, 3ah


jl lab1
add bl, 09h
lab1: and bl, 0fh

cmp bh, 3ah


jl lab2
add bh, 09h
lab2: and bh, 0fh

rol bh, 04h


or bh, bl

xor ax, ax
mov al, bh

aam

mov bx, ax

mov ah, 02h


mov dl, 0ah
int 21h
mov dl, 0dh
int 21h

mov ah, 09h


mov dx, offset msg2
int 21h

mov ah, 02h


mov dl, bh
or dl, 30h
int 21h

mov ah, 02h


mov dl, bl
or dl, 30h
int 21h

mov ax, 4c00h


int 21h
code ends
end start

;-----------------------------------------------------------------------
; end of program
;-----------------------------------------------------------------------
val equ 0abh

read macro ; macro to read a character in bl


push ax
mov ah, 01h
int 21h
mov bl, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

take_in macro x ; macro to input a two digit no in x


push ax
push dx
read
mov dh, bl
read
mov dl, bl
mov ah, dh
mov al, dl
and ax, 0f0fh
aad
pop dx
mov x, al
pop ax
endm

con macro x ; macro to convert binary x to decimal


and display
push ax
xor ax, ax
mov al, x
aam
or ax, 3030h
write ah
write al
pop ax
endm
; ------------- data segment ------------------------

_data segment
msg1 db ' the equivalent decimal is : $'

_data ends

; --------- stack segment ------------------------

_stack segment stack


dw 80 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
lea sp, stack_top ; initialise stack pointer

write 0ah
write 0dh
print msg1

mov bx, 000ah


xor ax, ax
mov al, val
l1: div bx
or dl, 30h
write dl
cmp ax, 0000h
jg l1

_code ends
end start

;---------------------------------------------------------------------------
; program to convert a hexadecimal no to decimal upto ( 65535d )
;---------------------------------------------------------------------------
; programmed by indranil gupta ( regn no 98011015 )
; c:\tasm\bin\indranil\hx_dc_l.asm ( 8086 program )
;---------------------------------------------------------------------------

val equ 0078h ; input hexadecimal no. ( <= 0ffffh)


read macro ; macro to read a character in bl
push ax
mov ah, 01h
int 21h
mov bl, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

; ------------- data segment ------------------------

_data segment
msg1 db ' the equivalent decimal no. is : $'
array db 5 dup (0)

_data ends

; --------- stack segment ------------------------

_stack segment stack


dw 80 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
lea sp, stack_top ; initialise stack pointer

mov ax, val


mov bx, 000ah
lea si, array
xor cl, cl
l1: xor dx, dx
div bx
mov byte ptr [si], dl
inc si
inc cl
cmp ax, 0000h
jne l1

l2: dec si
mov ch, byte ptr [si]
or ch, 30h
write ch
dec cl
cmp cl, 00h
jne l2

mov ax, 4c00h


int 21h

_code ends
end start

;---------------------------------------------------------------------------
; end of program
;---------------------------------------------------------------------------

;-----------------------------------------------------------------------------
; program for insertion sorting of numbers
;-----------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; j:\tasm12\bin\indranil\inst_st.asm ( 8086 program )
;-----------------------------------------------------------------------------

maxi equ 10d ; maximum defined array

read macro x ; macro to read a character in x


push ax ; x cann`t be either of ah or al
mov ah, 01h
int 21h
mov x, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

take_in macro x ; macro to input a two digit no in x


push ax ; x cann`t be either of ah or al
push dx
push cx
read cl
mov dh, cl
read cl
mov dl, cl
mov ah, dh
mov al, dl
and ax, 0f0fh
aad
pop cx
pop dx
mov x, al
pop ax
endm

con macro x ; macro to convert binary x to decimal


and display
push ax
xor ax, ax
mov al, x
aam
or ax, 3030h
write ah
write al
pop ax
endm

; ------------- data segment ------------------------

_data segment
arry db maxi dup (0)
msg1 db 0ah,0dh,' enter the 2 digit no. of terms (max
10d) : $'
msg2 db 0ah,0dh,' make your entry (2 digits) : $'
msg3 db 0ah,0dh,' the sorted list in ascending order is :
$'
msg4 db 0ah,0dh,' overflow error$'
_data ends

; --------- stack segment ------------------------

_stack segment stack


dw 80 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
lea sp, stack_top ; initialise stack pointer

print msg1
take_in cl ; cl contains the no. of terms
cmp cl, maxi
jle l0
print msg4
jmp last

l0: xor ch, ch


lea si, arry
l1: print msg2
take_in dl
mov byte ptr [si], dl ; make entries in the array
inc ch
inc si
cmp ch, cl
jne l1

lea si, arry ; perform the sorting


mov ah, cl
dec ah
xor bh, bh
l2: mov bl, bh
inc bl
mov di, si
inc di
mov dl, byte ptr [si]
l3: cmp dl, byte ptr [di]
jl l4
mov dh, byte ptr [di]
mov byte ptr [di], dl
mov byte ptr [si], dh
mov dl, dh
l4: inc di
inc bl
cmp bl, cl
jl l3
inc bh
inc si
cmp bh, ah
jl l2

lea si, arry


xor ch, ch
print msg3
l5: mov bh, byte ptr [si] ; display the sorted array
con bh
write 20h
inc ch
inc si
cmp ch, cl
jl l5

last: mov ax, 4c00h


int 21h ; terminate process

_code ends
end start

;-----------------------------------------------------------------------------
; end of program
;-----------------------------------------------------------------------------

;-----------------------------------------------------------------------
; program to find the largest of n-2-digit nmbers

print macro x ; macro to print a string


mov ah, 09h
mov dx, offset x
int 21h
endm

read macro ; macro to read a character


mov ah, 01h
int 21h
endm

write macro x ; macro to write the character x


mov ah, 02h
mov dl, x
int 21h
endm

data segment
msg1 db ' enter any two digit no. of terms (in decimal): $'
msg2 db ' make a two digit unsigned entry : $'
msg3 db ' the largest is $'
msg4 db ' invalid input$'
terms db ?
i db ?
data ends

code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialise ds register
print msg1 ; display msg1
read ; make entry of the no. of terms
cmp al, 30h
jl errormsg
cmp al, 39h
jg errormsg
mov bh, al
read
cmp al, 30h
jl errormsg
cmp al, 39h
jg errormsg
mov bl, al
and bx, 0f0fh ; masking higher nibble
mov ax, bx
aad ; convert unpacked bcd to binary in al
mov terms, al ; 'terms' contains the no. of terms
jmp loop0

errormsg: print msg4 ; display error msg


jmp last

loop0: write 0ah


write 0dh ; move cursor to next line
print msg2 ; display msg2

read ; make the first entry


cmp al, 30h
jl errormsg
cmp al, 39h
jg errormsg
mov bh, al
read
cmp al, 30h
jl errormsg
cmp al, 39h
jg errormsg
mov bl, al ; first entry is in bx

dec terms ; decrement the no. of terms


mov i, 00h ; initialise counter i to zero
loop1: write 0ah
write 0dh ; move cursor to next line
print msg2 ; display msg2

read ; make subsequent entry in cx


cmp al, 30h
jl errormsg
cmp al, 39h
jg errormsg
mov ch, al
read
cmp al, 30h
jl errormsg
cmp al, 39h
jg errormsg
mov cl, al ; cx contains the next entry
cmp bx, cx ; compare cx with bx
jg loop2
mov bx, cx ; if cx > bx then bx <- cx
loop2: inc i ; inc counter i
mov dl, terms
cmp i, dl
jne loop1

write 0ah
write 0dh ; move cursor to next line
print msg3 ; display msg3
write bh ; display bx, the largest no.
write bl

last: mov ax, 4c00h


int 21h ; terminate program
code ends
end start

;-----------------------------------------------------------------------
; end of program
;-----------------------------------------------------------------------

read macro ; macro to read a character in bl


push ax
mov ah, 01h
int 21h
mov bl, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

make_entry macro x ; x cannot be any of ah or al


push ax
push dx
read
mov dh, bl
read
mov dl, bl
and dx, 0f0fh
mov ax, dx
aad
pop dx
mov x, al
pop ax
endm

show macro x
push ax
push bx
mov al, x
aam
mov bx, ax
or bx, 3030h
write bh
write bl
pop bx
pop ax
endm

; ------------- data segment ------------------------

_data segment
msg1 db ' enter the first two digit no. : $'
msg2 db ' enter the second two digit no. : $'
msg3 db ' the hcf is : $'
msg4 db ' the lcm is : $'
; var1 db ?
; var2 db ?
_data ends

; --------- stack segment ------------------------

_stack segment stack


dw 80 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
lea sp, stack_top ; initialise stack pointer

print msg1 ; display msg1


make_entry bh
; mov var1, bh

write 0ah
write 0dh
print msg2
make_entry bl

; mov var2 , bl

mov dx, bx

cmp bh, bl
jg loop1
mov cl, bl
mov bl, bh
mov bh, cl
; bh > bl
loop1: xor ax, ax
mov al, bh
div bl
mov bh, bl
mov bl, ah
cmp bl, 00h
jne loop1

write 0ah
write 0dh

print msg3

show bh

write 0ah
write 0dh

print msg4

xor ax, ax
mov al, dh
mul dl
div bh

show al

mov ax, 4c00h


int 21h

_code ends
end start

maxi equ 10d

read macro ; macro to read a character in bl


push ax
mov ah, 01h
int 21h
mov bl, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

make_entry macro x ; x cannot be any of ah or al


push ax
push dx
read
mov dh, bl
read
mov dl, bl
and dx, 0f0fh
mov ax, dx
aad
pop dx
mov x, al
pop ax
endm

; ------------- data segment ------------------------

_data segment
msg1 db ' enter the no. of terms present (max 10) : $'
msg2 db ' make your entry : $'
msg3 db ' match found.$'
msg4 db ' match not found.$'
msg5 db ' enter the item to be searched : $'
msg6 db ' no. of items exceeds the limit$'
vars db maxi dup (0)
_data ends
; --------- stack segment ------------------------

_stack segment stack


dw 80 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
lea sp, stack_top ; initialise stack pointer

print msg1 ; display msg1

xor cx, cx
make_entry cl ; cl contains the no. of terms
cmp cl, maxi
jg errormsg

mov ch, 00h


lea si, vars
loop1: write 0ah
write 0dh
print msg2
make_entry bh
mov byte ptr [si], bh
inc ch
inc si
cmp ch, cl
jne loop1

write 0ah
write 0dh
write 0ah
jmp l1

errormsg: print msg6


jmp last

l1: print msg5

make_entry bh

lea si, vars


xor ch, ch
loop2: cmp bh, byte ptr [si]
je fnd
inc si
inc ch
cmp ch, cl
jne loop2
write 0ah
write 0dh
print msg4
jmp last

fnd: write 0dh


write 0ah
print msg3

last: mov ax, 4c00h


int 21h

_code ends
end start

;---------------------------------------------------------------------------

; program to implement linked list operations


;---------------------------------------------------------------------------

; programmed by indranil gupta


;---------------------------------------------------------------------------

;==========================
; program is not complete
;===========================

read macro x ; macro to read a character in bl


push ax
mov ah, 01h
int 21h
mov x, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm
; ------------- data segment ------------------------

_data segment
msg1 db 0ah,0dh,' program to demonstrate linked list
operations :-$'
msg2 db 0ah,0dh,' the options are as :-$'
msg3 db 0ah,0dh,' enter 1 to create$'
msg4 db 0ah,0dh,' enter 2 to insert$'
msg5 db 0ah,0dh,' enter 3 to delete$'
msg6 db 0ah,0dh,' enter 4 to display$'
msg7 db 0ah,0dh,' enter 5 to exit$'
msg10 db 0ah,0dh,' enter 6 to search$'
msg8 db 0ah,0dh,' enter your option : $'
msg9 db 0ah,0dh,0ah,' enter the element to be inserted :
$'
msga db 0ah,0dh,' memory allocation error.(exit from
program)$'
msgb db 0ah,0dh,0ah,' do you wish to continue ( press 1 if
yes ) : $'
msgc db 0ah,0dh,' do you wish to insert another ( press 1
if yes ) : $'
msgd db 0ah,0dh,0ah,' the list is as :-$'
msge db 0ah,0dh,' search is successful$'
msgf db 0ah,0dh,' search is not successful$'
msgg db 0ah,0dh,' enter the item to be searched : $'
srh_el db 16 dup ('$')
lin db
0ah,0dh,0ah,'--------------------------------------------------------------$'
begin dw ?
_data ends

; --------- stack segment ------------------------

_stack segment stack


dw 180 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
lea sp, stack_top ; initialise stack pointer

print msg1
l0: print lin
print msg2
print msg3
print msg4
print msg5
print msg6
print msg7
print msg10
print msg8
read cl
write 0ah
write 0dh
jmp ll1
ll0: jmp l0
ll1: cmp cl, 31h
jne l1
call cre
jmp l2
l1: cmp cl, 34h
jne l2
call disp
l2: cmp cl, 36h
jne l3
call srch
l3: write 0ah
print msgb
read cl
cmp cl, 31h
je ll0
last: mov ax, 4c00h
int 21h

;---------- procedure to create a list ---------------------------

cre proc near


push ax
push bx
push cx
push dx
push si

mov ah, 48h


mov bx, 0001h
int 21h
jc perr2
mov begin, ax
p0: mov si, ax
mov dx, ax

print msg9
xor bx, bx
p1: read cl
cmp cl, 0dh
je p2
mov byte ptr [si+bx], cl
inc bl
jmp p1
perr2: jmp perr1
p2: mov byte ptr [si+bx], 24h
write 0ah
print msgc
read cl
cmp cl, 31h
jne p3
mov ah, 48h
mov bx, 0001h
int 21h
jc perr1
mov si, dx
add si, 000eh
mov byte ptr [si], ah
mov byte ptr [si+0001h], al
jmp p0
p3: mov si, dx
add si, 000eh
mov byte ptr [si], 00h
mov byte ptr [si+0001h], 00h
jmp p4
perr1: print msga
p4: pop si
pop dx
pop cx
pop bx
pop ax
ret
endp

; ------------ procdure to display the list ---------------------

disp proc near


push si
push ax
push dx
mov si, begin
write 0ah
write 0dh
write 0ah
print msgd
write 0ah
write 0dh
ep1: write 09h
mov ah, 09h
mov dx, si
int 21h
write 0ah
write 0dh
add si, 000eh
mov ah, byte ptr [si]
mov al, byte ptr [si+0001h]
cmp ax, 0000h
je ep2
mov si, ax
jmp ep1
ep2: pop dx
pop ax
pop si
ret
endp

;------------- procedure to search a name in the list --------------

srch proc near


push si
push bx
push dx
push cx
push di

lea di, srh_el


write 0ah
print msgg
q: read cl
cmp cl, 0dh
je r
mov byte ptr [di], cl
inc di
jmp q
r: mov byte ptr [di], '$'
lea di, srh_el
mov si, begin

sp4: xor bx, bx


sp5: mov dl, byte ptr [si+bx]
cmp dl, byte ptr [di]
jne sp2
inc di
inc bx
cmp dl, '$'
jne sp5
print msge
jmp sp3
sp2: print msgf
sp3: pop di
pop cx
pop dx
pop bx
pop si
ret
endp

_code ends
end start

;---------------------------------------------------------------------------

; end of program
;---------------------------------------------------------------------------

;---------------------------------------------------------------------------

; program to create and display linear linked list


;---------------------------------------------------------------------------
; programmed by indranil gupta
;---------------------------------------------------------------------------

read macro x ; macro to read a character in x


push ax ; x cann`t be either of ah or al
mov ah, 01h
int 21h
mov x, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

; ------------- data segment ------------------------

_data segment
msg1 db 0ah,0dh,' program to demonstrate linked list
operations :-$'
msg2 db 0ah,0dh,' the options are :-$'
msg3 db 0ah,0dh,' enter 1 to create$'
msg4 db 0ah,0dh,' enter 2 to search an item$'
msg5 db 0ah,0dh,' enter 3 to display the list$'
msg6 db 0ah,0dh,' enter 4 to exit$'
msg7 db 0ah,0dh,' enter your option : $'
msg8 db 0ah,0dh,' make your entry : $'
msg9 db 0ah,0dh,' do you want to continue ( press y if yes )
$'
msga db 0ah,0dh,' do you want to insert ( press y if yes )
$'
msgb db 0ah,0dh,' enter the item to be searched : $'
msgc db 0ah,0dh,' search is successful $'
msgd db 0ah,0dh,' search is not successful $'
msge db 0ah,0dh,' the list is as follows :-$'
err1 db 0ah,0dh,' memory allocation error.$'
err2 db 0ah,0dh,' wrong option entered.$'
begin dw 0000h
s_itm db 14d dup (0)
_data ends
; --------- stack segment ------------------------

_stack segment stack


dw 180 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
lea sp, stack_top ; initialise stack pointer

print msg1
l1: write 0ah
print msg2
print msg3
print msg4
print msg5
print msg6
print msg7
read dl
cmp dl, 31h
jne l2
call create
jmp l5
l11: jmp l1
l2: cmp dl, 32h
jne l3
print msgb
lea di, s_itm
s1: read dl
cmp dl, 0dh
je s2
mov byte ptr [di], dl
inc di
jmp s1
s2: mov byte ptr [di], '$'
call search
jmp l5
l3: cmp dl, 33h
jne l4
call disp
jmp l5
l4: cmp dl, 34h
je last
print err2
l5: print msg9
read dl
cmp dl, 'y'
je l11
last: mov ax, 4c00h
int 21h

;------------- procedure to create linked list -------------------

create proc near


push si
push ax
push bx
push dx
mov ah, 48h
mov bx, 0001h
int 21h
jc cre_err1
mov begin, ax
crep1: mov si, ax
print msg8
xor bx, bx
crep2: read dl
cmp dl, 0dh
je crep3
mov byte ptr [si+bx], dl
inc bx
jmp crep2
crep3: mov byte ptr [si+bx], '$'
print msga
read dl
cmp dl, 'y'
jne crep4
mov ah, 48h
mov bx, 0001h
int 21h
jc cre_err2
add si, 000eh
mov byte ptr [si], ah
mov byte ptr [si+0001h], al
jmp crep1
crep4: add si, 000eh
mov byte ptr [si], 00h
mov byte ptr [si+0001h], 00h
jmp crelst
cre_err2: mov byte ptr [si], 00h
mov byte ptr [si+0001h], 00h
cre_err1: print err1
crelst: pop dx
pop bx
pop ax
pop si
ret
endp

;--------------- procudure to display linked list ------------------

disp proc near


push si
push ax
print msge
write 0ah
write 0dh
mov si, begin
dis1: cmp si, 0000h
je dis2
write 09h
mov ah, 09h
mov dx, si
int 21h
write 0ah
write 0dh
add si, 000eh
mov ah, byte ptr [si]
mov al, byte ptr [si+0001h]
mov si, ax
jmp dis1
dis2: pop ax
pop si
ret
endp

;------------- procedure to search for an item in the list --------

search proc near


push si
push di
push bx
push dx
mov si, begin
lea di, s_itm
sr1: cmp si,0000h
je nf
xor bx, bx
sr2: mov dh, byte ptr [si+bx]
mov dl, byte ptr [di+bx]
inc bx
cmp dh, dl
jne sr3
cmp dh, '$'
je fnd
jmp sr2
sr3: add si, 000eh
mov dh, byte ptr [si]
mov dl, byte ptr [si+0001h]
mov si, dx
jmp sr1
nf: print msgd
jmp sr4
fnd: print msgc
sr4: pop dx
pop bx
pop di
pop si
ret
endp

_code ends
end start

;---------------------------------------------------------------------------

; end of program
;---------------------------------------------------------------------------

;---------------------------------------------------------------------------

; program to create and display linear linked list


;---------------------------------------------------------------------------

; programmed by indranil gupta


;---------------------------------------------------------------------------

read macro x ; macro to read a character in x


push ax ; x cann`t be either of ah or al
mov ah, 01h
int 21h
mov x, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

; ------------- data segment ------------------------

_data segment
msg1 db 0ah,0dh,' program to demonstrate linked list
operations :-$'
msg2 db 0ah,0dh,' the options are :-$'
msg3 db 0ah,0dh,' enter 1 to create$'
msg4 db 0ah,0dh,' enter 2 to search an item$'
msg41 db 0ah,0dh,' enter 3 to insert an item$'
msg5 db 0ah,0dh,' enter 4 to display the list$'
msg6 db 0ah,0dh,' enter 5 to exit$'
msg7 db 0ah,0dh,' enter your option : $'
msg8 db 0ah,0dh,' make your entry : $'
msg9 db 0ah,0dh,' do you want to continue ( press y if yes )
$'
msga db 0ah,0dh,' do you want to insert ( press y if yes )
$'
msgb db 0ah,0dh,' enter the item to be searched : $'
msgc db 0ah,0dh,' search is successful $'
msgd db 0ah,0dh,' search is not successful $'
msge db 0ah,0dh,' the list is as follows :-$'
err1 db 0ah,0dh,' memory allocation error.$'
err2 db 0ah,0dh,' wrong option entered.$'
begin dw 0000h
s_itm db 14d dup (0)
_data ends

; --------- stack segment ------------------------

_stack segment stack


dw 180 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
lea sp, stack_top ; initialise stack pointer

print msg1
l1: write 0ah
print msg2
print msg3
print msg4
print msg41
print msg5
print msg6
print msg7
read dl
cmp dl, 31h
jne l2
call create
jmp l5
l11: jmp l1
l2: cmp dl, 32h
jne l3
print msgb
lea di, s_itm
s1: read dl
cmp dl, 0dh
je s2
mov byte ptr [di], dl
inc di
jmp s1
s2: mov byte ptr [di], '$'
call search
jmp l6
l3: cmp dl, 33h
jne l6
call insert
jmp l6
l4: cmp dl, 34h
jne l6
call disp
jmp l6
l5: cmp dl, 35h
je last
print err2
l6: print msg9
read dl
cmp dl, 'y'
je l11

last: mov ax, 4c00h


int 21h

;------------- procedure to create linked list -------------------

create proc near


push si
push ax
push bx
push dx
mov ah, 48h
mov bx, 0001h
int 21h
jc cre_err1
mov begin, ax
crep1: mov si, ax
print msg8
xor bx, bx
crep2: read dl
cmp dl, 0dh
je crep3
mov byte ptr [si+bx], dl
inc bx
jmp crep2
crep3: mov byte ptr [si+bx], '$'
print msga
read dl
cmp dl, 'y'
jne crep4
mov ah, 48h
mov bx, 0001h
int 21h
jc cre_err2
add si, 000eh
mov byte ptr [si], ah
mov byte ptr [si+0001h], al
jmp crep1
crep4: add si, 000eh
mov byte ptr [si], 00h
mov byte ptr [si+0001h], 00h
jmp crelst
cre_err2: mov byte ptr [si], 00h
mov byte ptr [si+0001h], 00h
cre_err1: print err1
crelst: pop dx
pop bx
pop ax
pop si
ret
endp

;--------------- procudure to display linked list ------------------

disp proc near


push si
push ax
print msge
write 0ah
write 0dh
mov si, begin
dis1: cmp si, 0000h
je dis2
write 09h
mov ah, 09h
mov dx, si
int 21h
write 0ah
write 0dh
add si, 000eh
mov ah, byte ptr [si]
mov al, byte ptr [si+0001h]
mov si, ax
jmp dis1
dis2: pop ax
pop si
ret
endp

;------------- procedure to search for an item in the list --------

search proc near


push si
push di
push bx
push dx
mov si, begin
lea di, s_itm
sr1: cmp si,0000h
je nf
xor bx, bx
sr2: mov dh, byte ptr [si+bx]
mov dl, byte ptr [di+bx]
inc bx
cmp dh, dl
jne sr3
cmp dh, '$'
je fnd
jmp sr2
sr3: add si, 000eh
mov dh, byte ptr [si]
mov dl, byte ptr [si+0001h]
mov si, dx
jmp sr1
nf: print msgd
jmp sr4
fnd: print msgc
sr4: pop dx
pop bx
pop di
pop si
ret
endp

_code ends
end start

;---------------------------------------------------------------------------

; end of program
;---------------------------------------------------------------------------

;--------------------------------------------------------------------------
; program for matrix operations
;--------------------------------------------------------------------------
; programmed by indranil gupta ( regn no. 98011015 )
; j:\tasm\bin\matrix.asm ( 8086 program )
; dated : 30-11-2000.
;--------------------------------------------------------------------------

read macro x ; macro to read a character in x other


than ax
push ax
mov ah, 01h
int 21h
mov x, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm
print macro x ; macro to display a string
push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

take_in macro x ; macro to input a two digit no in x


push ax
push dx
push bx
read bl
mov dh, bl
read bl
mov dl, bl
mov ah, dh
mov al, dl
and ax, 0f0fh
aad
pop bx
pop dx
mov x, al
pop ax
endm

con macro x ; macro to convert binary x to decimal


and display
push ax
mov al, x
xor ah, ah
aam
or ax, 3030h
write ah
write al
pop ax
endm

; ------------- data segment ------------------------

_data segment
fir_mat db 4 dup (0)
sec_mat db 4 dup (0)
msg1 db 0ah,0dh,' enter a element for first matrix :- $'
msg2 db 0ah,0dh,' enter a element for second matrix :- $'
msg3 db 0ah,0dh,' the resulting matrix is :-$'
msg4 db 0ah,0dh,' the various operations for 2 x 2 matrix
are :-$'
msg5 db 0ah,0dh,' enter 1 to add two 2x2 matrices.$'
msg6 db 0ah,0dh,' enter 2 to multiply two 2x2
matrices.$'
msg7 db 0ah,0dh,' enter 3 to transpose a 2x2
matrix.$'
msg8 db 0ah,0dh,' wrong choice entered. retry . . . $'
msg9 db 0ah,0dh,' do you wish to continue ( press 1 if yes
) : $'
msga db 0ah,0dh,' your option is : $'
msg00 db 0ah,0dh,' position (0,0) : $'
msg01 db 0ah,0dh,' position (0,1) : $'
msg10 db 0ah,0dh,' position (1,0) : $'
msg11 db 0ah,0dh,' position (1,1) : $'
_data ends

; --------- stack segment ------------------------

_stack segment stack


dw 80 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
lea sp, stack_top ; initialise stack pointer

l1: print msg4


print msg5
print msg6
print msg7
print msga
read cl
cmp cl, 31h
jne l2
call mat_add
jmp l5
l11: jmp l1
l2: cmp cl, 32h
jne l3
call mat_mul
jmp l5
l3: cmp cl, 33h
jne l4
call mat_trp
jmp l5
l4: print msg8
l5: print msg9
l6: read cl
cmp cl, 31h
je l11

last: mov ax, 4c00h


int 21h

mat_add proc near ; procedure to perform matrix addition


push si
push di
push cx
lea si, fir_mat
print msg1
call inp
lea si, sec_mat
print msg2
call inp
lea si, fir_mat
lea di, sec_mat
xor cl, cl
al1: write 0ah
write 0dh
write 09h
write 0b3h
write 20h
jmp al12
al11: jmp al1
al12: mov ch, byte ptr [si]
add ch, byte ptr [di]
con ch
write 20h
inc si
inc di
mov ch, byte ptr [si]
add ch, byte ptr [di]
con ch
write 20h
write 0b3h
inc cl
inc si
inc di
cmp cl, 02h
jne al11
pop cx
pop di
pop si
ret
endp

inp proc near ; procedure to input values to matrix


pointed by si
push si
push cx
print msg00
take_in ch
mov byte ptr [si], ch
inc si
print msg01
take_in ch
mov byte ptr [si], ch
inc si
print msg10
take_in ch
mov byte ptr [si], ch
inc si
print msg11
take_in ch
mov byte ptr [si], ch
pop cx
pop si
ret
endp

mat_mul proc near ; procedure for matrix multiplication


push si
push di
push ax
push cx
lea si, fir_mat
print msg1
call inp
lea si, sec_mat
print msg2
call inp
lea si, fir_mat
lea di, sec_mat
write 0ah
write 0dh
write 09h
write 0b3h
write 20h
xor ax, ax
mov al, byte ptr [si]
mul byte ptr [di]
mov ch, al
inc si
add di, 0002h
xor ax, ax
mov al, byte ptr [si]
mul byte ptr [di]
add ch, al
con ch
write 20h
dec di
dec si
xor ax, ax
mov al, byte ptr [si]
mul byte ptr [di]
mov ch, al
inc si
add di, 0002h
mov al, byte ptr [si]
mul byte ptr [di]
add ch, al
con ch
write 20h
write 0b3h
write 0ah
write 0dh
write 09h
write 0b3h
write 20h
inc si
sub di, 0003h
mov al, byte ptr [si]
mul byte ptr [di]
mov ch, al
inc si
add di, 0002h
mov al, byte ptr [si]
mul byte ptr [di]
add ch, al
con ch
write 20h
dec si
dec di
mov al, byte ptr [si]
mul byte ptr [di]
mov ch, al
inc si
add di, 0002h
mov al, byte ptr [si]
mul byte ptr [di]
add ch, al
con ch
write 20h
write 0b3h
pop cx
pop ax
pop di
pop si
ret
endp

mat_trp proc near ; procedure for transpose of matrix


push si
push cx
lea si, fir_mat
print msg1
call inp
lea si, fir_mat
write 0ah
write 0dh
write 09h
write 0b3h
write 20h
mov cl, byte ptr [si]
con cl
write 20h
add si, 0002h
mov cl, byte ptr [si]
con cl
write 20h
write 0b3h
write 0ah
write 0dh
write 09h
write 0b3h
write 20h
dec si
mov cl, byte ptr [si]
con cl
write 20h
add si, 0002h
mov cl, byte ptr [si]
con cl
write 20h
write 0b3h
pop cx
pop si
ret
endp

_code ends
end start

;-------------------------------------------------------------------------
; end of program
;-------------------------------------------------------------------------

;--------------------------------------------------------------------------
; program to change directory using command line arguments
;--------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; c:\tasm\bin\indranil\my_cd.asm ( 8086 program )
; dated : 22-11-2000.
;--------------------------------------------------------------------------

data segment
msg1 db ' invalid directory. $'
msg2 db ' required parameter missing. $'
dir_nm db 15 dup (0)
data ends

code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialise ds register

mov ah, 62h


int 21h
mov es, bx
mov di, 0080h
mov cl, byte ptr es:[di] ; cl contains the no. of
characters in argument
cmp cl, 00h
je err1

lea si, dir_nm


xor ch, ch
mov di, 005dh
mov dl, byte ptr es:[di] ; read the content of argument
cmp dl, 21h
jl err1
l0: mov byte ptr [si], dl
inc si
inc di
inc ch
mov dl, byte ptr es:[di]
cmp dl, 21h
jl l1
cmp ch, cl
jne l0

l1: mov byte ptr [si], 00h


mov ah, 3bh
mov dx, offset dir_nm
int 21h ; set the current directory
jnc last

mov ah, 09h


mov dx, offset msg1
int 21h
jmp last

err1: mov ah, 09h


mov dx, offset msg2
int 21h

last: mov ax, 4c00h


int 21h ; terminate program

code ends
end start

;--------------------------------------------------------------------------
; end of program
;--------------------------------------------------------------------------

;---------------------------------------------------------------------------
; program to delete a file using command line arguments
;---------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; c:\tasm\bin\indranil\my_del.asm ( 8086 program )
; dated : 22-11-2000.
;---------------------------------------------------------------------------

data segment
msg1 db 0ah,0dh,'file not found.$'
msg2 db 0ah,0dh,'required parameter missing - $'
filename db 15 dup (0)
data ends

code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialise ds register
mov ah, 62h
int 21h

mov es, bx ; initialise es register with


base addr of psp
mov di, 0080h
mov cl, byte ptr es:[di] ; cl contains the no. of
characters in the argument

cmp cl, 00h


je err1

lea si, filename ; offset of filename in si


mov di, 005dh ; starting address of command
argument
xor ch, ch
l0: mov dl, byte ptr es:[di]
inc ch
cmp ch, cl
je err1
inc di
cmp dl, 21h
jl l0 ; neglecting space characters
dec di

l1: mov byte ptr [si], dl ; command characters stored in


filename
inc si
inc di
inc ch
cmp ch, cl
jg err2
mov dl, byte ptr es:[di] ; read next command character
cmp dl, 20h
jg l1

mov byte ptr [si], '.' ; insert '.' after the filename
inc si

l2: mov di, 0065h ; filename extension lies from


65h
l3: mov dl, byte ptr es:[di]
cmp dl, 21h
jl l4
mov byte ptr [si], dl ; copy extension
inc si
inc di
inc ch
cmp ch, cl
jg err2
jmp l3

l4: mov byte ptr [si], 00h ; insert null at last

mov ah, 41h


mov dx, offset filename
int 21h ; dos interrupt to delete file
jnc last

err2: mov ah, 09h


mov dx, offset msg1
int 21h
jmp last

err1: mov ah, 09h


mov dx, offset msg2
int 21h

last: mov ax, 4c00h ; terminate process


int 21h

code ends
end start

;---------------------------------------------------------------------------
; end of program
;---------------------------------------------------------------------------

;---------------------------------------------------------------------------
; program to delete a file using command line arguments
;---------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; c:\tasm\bin\indranil\my_del.asm ( 8086 program )
; dated :
;---------------------------------------------------------------------------

ctail equ 080h ; psp offset, command tail

read macro ; macro to read a character in bl


push ax
mov ah, 01h
int 21h
mov bl, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

; ------------- data segment ------------------------

_data segment
msg2 db ' file not found.$'
msg1 db ' required parameter missing$'
buffer db 85 dup (0)
filenm db 15 dup (0)
_data ends

; --------- stack segment ------------------------

_stack segment stack


dw 80 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack , es : _data
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
mov ax, _data
mov es, ax
lea sp, stack_top ; initialise stack pointer

mov ah, 62h


int 21h

mov ds, bx
mov si, offset ctail
mov di, seg buffer
mov es, di
mov di, offset buffer
mov cl, byte ptr [si]
mov dh, cl
cmp dh, 00h
je errmsg1
inc cl
xor ch, ch
xor si, si
cld
rep movsb

lea si, filenm

mov cl, dh
xor ch, ch
mov di, offset buffer
add di, offset 006dh
l1: mov bl, byte ptr [di]
cmp bl, 20h
je l2
mov byte ptr [si], bl
inc si
l2: inc di
inc ch
cmp ch, cl
jne l1
mov byte ptr [si], 00h

mov ax, _data ;


mov ds, ax ;

mov ah, 41h


mov dx, offset filenm
int 21h
jc errmsg2
jmp last

errmsg1: print msg1


jmp last
errmsg2: print msg2

last: mov ax, 4c00h


int 21h

_code ends
end start

;---------------------------------------------------------------------------
; end of program
;---------------------------------------------------------------------------

data segment
buffer db 50 dup (?)
filename db '*.*',0
msg db 0ah,0dh,'invalid switch$'
data ends

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

mov ah, 62h


int 21h
mov es, bx
xor bx, bx
mov di, 80h
mov bl, byte ptr es:[di]
cmp bl, 00h
je l1
mov di, 005dh
xor cx, cx
l0: mov ch, byte ptr es:[di]
inc cl
inc di
cmp ch, cl

l1: mov ah , 1ah


mov dx, offset buffer
int 21h

mov ah, 4eh


mov cx, 0000h
mov dx, offset filename
int 21h
jc last

lea si, buffer


add si, 001eh
xor cl,cl
loop1: mov dl, byte ptr [si]
cmp dl, 21h
jl loop2
mov ah, 02h
int 21h
inc si
inc cl
cmp cl, 0ch
jne loop1

loop2: mov ah, 4fh


int 21h
jc last

lea si, buffer


xor cl,cl
add si, 001eh ;;;;
loop3: mov dl, byte ptr [si]
cmp dl, 21h
jl loop4
mov ah, 02h
int 21h
inc si
inc cl
cmp cl, 0ch
jne loop3
loop4: mov ah, 02h
mov dl, 0ah
int 21h
mov dl, 0dh
int 21h
inc ch
cmp ch, 16h
jl loop2
mov ah, 01h
int 21h
xor ch, ch
jmp loop2

last : mov ax, 4c00h


int 21h

code ends
end start

;--------------------------------------------------------------------------
; program to create new sub-directory using command line arguments
;--------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; c:\tasm\bin\indranil\my_md.asm ( 8086 program )
; dated : 22-11-2000.
;--------------------------------------------------------------------------

data segment
msg1 db ' invalid directory. $'
msg2 db ' required parameter missing. $'
dir_nm db 15 dup (0)
data ends

code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialise ds register

mov ah, 62h


int 21h
mov es, bx
mov di, 0080h
mov cl, byte ptr es:[di] ; cl contains the no. of
characters in argument
cmp cl, 00h
je err1

lea si, dir_nm


xor ch, ch
mov di, 005dh
mov dl, byte ptr es:[di] ; read the content of argument
cmp dl, 21h
jl err1
l0: mov byte ptr [si], dl
inc si
inc di
inc ch
mov dl, byte ptr es:[di]
cmp dl, 21h
jl l1
cmp ch, cl
jne l0

l1: mov byte ptr [si], 00h


mov ah, 39h
mov dx, offset dir_nm
int 21h ; set the current directory
jnc last

mov ah, 09h


mov dx, offset msg1
int 21h
jmp last

err1: mov ah, 09h


mov dx, offset msg2
int 21h

last: mov ax, 4c00h


int 21h ; terminate program

code ends
end start

;--------------------------------------------------------------------------
; end of program
;--------------------------------------------------------------------------

;--------------------------------------------------------------------------
; program to remove directory using command line arguments
;--------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; c:\tasm\bin\indranil\my_rd.asm ( 8086 program )
; dated : 22-11-2000.
;--------------------------------------------------------------------------

data segment
msg1 db ' invalid directory or directory not empty. $'
msg2 db ' required parameter missing. $'
dir_nm db 15 dup (0)
data ends

code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialise ds register

mov ah, 62h


int 21h
mov es, bx
mov di, 0080h
mov cl, byte ptr es:[di] ; cl contains the no. of
characters in argument
cmp cl, 00h
je err1
lea si, dir_nm
xor ch, ch
mov di, 005dh
mov dl, byte ptr es:[di] ; read the content of argument
cmp dl, 21h
jl err1
l0: mov byte ptr [si], dl
inc si
inc di
inc ch
mov dl, byte ptr es:[di]
cmp dl, 21h
jl l1
cmp ch, cl
jne l0

l1: mov byte ptr [si], 00h


mov ah, 3ah
mov dx, offset dir_nm
int 21h ; set the current directory
jnc last

mov ah, 09h


mov dx, offset msg1
int 21h
jmp last

err1: mov ah, 09h


mov dx, offset msg2
int 21h

last: mov ax, 4c00h


int 21h ; terminate program

code ends
end start

;--------------------------------------------------------------------------
; end of program
;--------------------------------------------------------------------------

;---------------------------------------------------------------------------
; program to rename a file using command line arguments
;---------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; c:\tasm\bin\indranil\my_ren.asm ( 8086 program )
; dated : 22-11-2000.
;---------------------------------------------------------------------------

data segment
fl_old db 15 dup (0)
fl_new db 15 dup (0)
msg1 db ' required parameter missing. $'
msg2 db ' file not found. $'
data ends

code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialise ds register

mov ah, 62h


int 21h
mov es, bx ; es contains psp address

lea si, fl_old


mov di, 005dh
xor ch, ch
mov dl, byte ptr es:[di]
cmp dl, 21h
jl err1
l0: mov byte ptr [si], dl
inc si
inc di
mov dl, byte ptr es:[di] ; read the first filename
cmp dl, 21h
jl l1
cmp ch, 08h
jne l0

l1: mov byte ptr [si], '.'


inc si
mov di, 0065h
xor ch, ch
l2: mov dl, byte ptr es:[di] ; read the extension of first filename
cmp dl, 21h
jl l4
mov byte ptr [si], dl
inc si
inc di
cmp ch, 03h
jl l2

err1: mov ah, 09h


mov dx, offset msg1
int 21h ; display error msg
jmp last

l4: mov byte ptr [si], 00h


lea si, fl_new
mov di, 006dh
xor ch, ch
mov dl, byte ptr es:[di] ; read next filename
cmp dl, 21h
jl err1
l5: mov byte ptr [si], dl
inc si
inc di
mov dl, byte ptr es:[di]
cmp dl, 21h
jl l6
cmp ch, 08h
jne l5

l6: mov byte ptr [si], '.'


inc si
mov di, 0075h
xor ch, ch
l7: mov dl, byte ptr es:[di] ; read extension of next file
cmp dl, 21h
jl l8
mov byte ptr [si], dl
inc si
inc di
cmp ch, 03h
jl l7

l8: mov byte ptr [si], 00h


mov ax, data
mov es, ax
mov ah, 56h
mov dx, offset fl_old
mov di, offset fl_new
int 21h ; interrupt to rename file
jnc last

mov ah, 09h


mov dx, offset msg2
int 21h

last: mov ax, 4c00h ; terminate process with return code


int 21h

code ends
end start

;---------------------------------------------------------------------------

; end of program
;---------------------------------------------------------------------------

;-----------------------------------------------------------------------------
; program to type the contents of a file to the screen
;-----------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no 98011015 )
; j:\tasm12\bin\indranil\my_type.asm ( 8086 program )
; dated : 27-11-2000.
;-----------------------------------------------------------------------------

data segment
msg1 db ' file not found $'
msg2 db ' required parameter missing. $'
fil_nm db 15 dup (0)
buffer db ?
fhan dw ?
data ends
code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialise ds register

mov ah, 62h


int 21h

mov es, bx ; initialise es register with


base addr of psp
mov di, 0080h
mov cl, byte ptr es:[di] ; cl contains the no. of
characters in the argument

cmp cl, 00h


je err2

lea si, fil_nm ; offset of filename in si


mov di, 005dh ; starting address of command
argument
xor ch, ch
l0: mov dl, byte ptr es:[di]
inc ch
cmp ch, cl
je err1
inc di
cmp dl, 21h
jl l0 ; neglecting space characters
dec di

l1: mov byte ptr [si], dl ; command characters stored in


filename
inc si
inc di
inc ch
cmp ch, cl
jg l4
mov dl, byte ptr es:[di] ; read next command character
cmp dl, 20h
jg l1

mov byte ptr [si], '.' ; insert '.' after the filename
inc si

l2: mov di, 0065h ; filename extension lies from


65h
l3: mov dl, byte ptr es:[di]
cmp dl, 21h
jl l4
mov byte ptr [si], dl ; copy extension
inc si
inc di
inc ch
cmp ch, cl
jg l4
jmp l3
err2: jmp err1
l4: mov byte ptr [si], 00h ; insert null at last

mov ah, 3dh


mov al, 80h
mov dx, offset fil_nm
int 21h ; open file in reading mode
jnc l41
mov ah, 09h
mov dx, offset msg1
int 21h
jmp last
l41: mov fhan, ax
l5: mov ah, 3fh
mov bx, fhan
mov cx, 0001h
mov dx, offset buffer
int 21h ; read file content
cmp ax, 0000h
je l6
mov ah, 02h
mov dl, buffer
int 21h ; display file content
jmp l5
l6: mov ah, 3eh
mov bx, fhan
int 21h ; close file
jmp last
err1: mov ah, 09h
mov dx, offset msg1
int 21h
jmp last

last: mov ax, 4c00h


int 21h ; terminate process
code ends
end start

;-----------------------------------------------------------------------------
; end of program
;-----------------------------------------------------------------------------

ctail equ 080h ; psp offset, command tail

read macro ; macro to read a character in bl


push ax
mov ah, 01h
int 21h
mov bl, al
pop ax
endm

write macro x ; macro to write a chararacter x


push ax
push dx
mov dl, x
mov ah, 02h
int 21h
pop dx
pop ax
endm

print macro x ; macro to display a string


push ax
push dx
mov dx, offset x
mov ah, 09h
int 21h
pop dx
pop ax
endm

; ------------- data segment ------------------------

_data segment
msg1 db 0ah,0dh,' file not found.$'
buffer db 80 dup (0)
filenm db 15 dup (0)
_data ends

; --------- stack segment ------------------------

_stack segment stack


dw 80 dup (0)
stack_top label word
_stack ends

; ----------- code segment -------------------------

_code segment
assume cs : _code , ds : _data , ss : _stack , es : _data
start: mov ax, _data
mov ds, ax ; initialise ds register with segment
address of data
mov ax, _stack
mov ss, ax ; initialise ss register with segment
address of stack
mov ax, _data
mov es, ax
lea sp, stack_top ; initialise stack pointer

write 0ah
write 0dh

mov ah, 62h


int 21h

mov ds, bx
mov si, offset ctail
mov di, seg buffer
mov es, di
mov di, offset buffer
mov cl, byte ptr [si]
mov dh, cl
inc cl
xor ch, ch
xor si, si
cld
rep movsb

lea si, filenm

mov cl, dh
xor ch, ch
mov di, offset buffer
add di, offset 006dh
l1: mov bl, byte ptr [di]
cmp bl, 20h
je l2
mov byte ptr [si], bl
inc si
l2: inc di
inc ch
cmp ch, cl
jne l1
mov byte ptr [si], 00h

mov ah, 41h


mov dx, offset filenm
int 21h

last: mov ax, 4c00h


int 21h

_code ends
end start

data segment
buffer db 50 dup (?)
filename db '*.*',0
data ends

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

mov ah, 02h


mov dl, 0ah
int 21h
mov dl, 0dh
int 21h

mov ah , 1ah
mov dx, offset buffer
int 21h

mov ah, 4eh


mov cx, 0
mov dx, offset filename
int 21h
jc last

lea si, buffer


add si, 001eh
xor cl,cl
loop1: mov dl, byte ptr [si]
cmp dl, 21h
jmp loop2
mov ah, 02h
int 21h
inc si
inc cl
cmp cl, 0ch
jne loop1

loop2: mov ah, 4fh


int 21h
jc last

lea si, buffer


xor cl,cl
add si, 001eh ;;;;
loop3: mov dl, byte ptr [si]
cmp dl, 21h
jl loop4
mov ah, 02h
int 21h
inc si
inc cl
cmp cl, 0ch
jne loop3
loop4: mov ah, 02h
mov dl, 0ah
int 21h
mov dl, 0dh
int 21h
inc ch
cmp ch, 16h
jl loop2
mov ah, 01h
int 21h
xor ch, ch
jmp loop2

last : mov ax, 4c00h


int 21h

code ends
end start
maxi equ 07h

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

read macro
mov ah, 01h
int 21h
endm

write macro x
mov ah, 02h
mov dl, x
int 21h
endm

data segment
msg1 db ' enter any octal no. (max 7 digits) : $'
msg2 db ' the binary equivalent is $'
msg3 db ' invalid entry$'
octal db maxi dup (0)
data ends

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

print msg1

xor cl, cl
lea si, octal

loop1: read
cmp al, 0dh
je loop2
cmp al, 20h
je loop1
cmp al, 30h
jl errormsg
cmp al, 37h
jg errormsg
mov [si], al
inc si
inc cl
cmp cl, maxi
jne loop1

loop2: cmp cl, 00h


je loop6
write 0ah
write 0dh
print msg2
lea si, octal
xor ch, ch
loop3: and byte ptr [si], 0fh
xor bl, bl
shl byte ptr [si], 05h
write 20h
loop10: shl byte ptr [si], 01h
jc loop4
write 30h
jmp loop5
loop4: write 31h
loop5: inc bl
cmp bl, 03h
jne loop10
inc ch
inc si
cmp ch, cl
jne loop3
write 62h
jmp loop6

errormsg: print msg3

loop6: mov ax, 4c00h


int 21h
code ends
end start

;------------------------------------------------------------------------
; program to convert a octal no. to its decimal
;------------------------------------------------------------------------
; programmed by indranil gupta ( regn. no. 98011015 )
; c:\tasm\bin\indranil\oct_dec.asm ( 8086 program )
; dated : 30-10-2000.
;------------------------------------------------------------------------

print macro x ; macro to display a string


mov ah, 09h
mov dx, offset x
int 21h
endm

read macro ; macro to read a character


mov ah, 01h
int 21h
endm

write macro x ; macro to write a character


mov ah, 02h
mov dl, x
int 21h
endm
data segment
msg1 db ' enter any octal no. (<143o) : $'
msg2 db ' the decimal equivalent is $'
msg3 db ' invalid entry$'
octal db 3 dup (0)
data ends

code segment
assume cs:code , ds:data
start: mov ax, data
mov ds, ax ; initialise ds register

print msg1

xor cl, cl
lea si, octal
loop1: read ; read the inputs
cmp al, 0dh
je l1
cmp al, 20h
je loop1
cmp al, 30h
jl errormsg
cmp al, 37h
jg errormsg
mov byte ptr [si], al ; store the data in array octal
inc si
inc cl
cmp cl, 03h
jne loop1
sub si, 0003h
cmp byte ptr [si], 31h
jg errormsg
jmp l1

errormsg: print msg3


jmp loop4

l1: xor bl, bl


xor ch, ch
lea si, octal
loop2: and byte ptr [si], 0fh ; mask higher nibble
shl byte ptr [si], 05h ; shift 5 bits left of content of si
xor bh, bh
loop3: shl byte ptr [si], 01h
rcl bl, 01h
inc bh
cmp bh, 03h ; rotate 3 bits and store in bl
jne loop3
inc si
inc ch
cmp ch, cl
jne loop2
mov al, bl
cmp al, 63h
jg errormsg
aam ; convert binary to unpacked bcd
mov cx, ax
or cx, 3030h

write 0ah
write 0dh ; move cursor to next line
print msg2
write ch
write cl
write 64h

loop4: mov ax, 4c00h ; terminate process


int 21h
code ends
end start

;------------------------------------------------------------------------
; end of program
;------------------------------------------------------------------------

;program to convert octal to decimal


; by sanjib das regn no 98011031
data segment
msg1 db 'enter the octal number$'
msg2 db 'the equivalent decimal no is :$'
deci db 3 dup(?)
data ends

code segment
assume cs:code ,ds:data
begin : mov ax,data
mov ds,ax
mov dx,offset msg1
mov ah,09h
int 21h
mov si,offset deci
xor cl,cl

entry : inc cl
mov ah,01h
int 21h
sub al,30h
mov [si],al
inc si
cmp cl,02h
jne entry

mov ah,09h
mov dx,offset msg2
int 21h

xor ax,ax

mov si,offset deci


mov ah,[si]
mov al,[si+1]
shl ah,03h
add al,ah

aam
xor bx,bx
; mov cl,03h
mov bl,al
mov bh,ah
; shr bh,cl
add bh,30h
; and bl,00000111b
add bl,30h
mov ah,02h
mov dl,bh
int 21h
mov dl,bl
int 21h

mov ax,4c00h
int 21h
code ends
end begin

;program to convert octal to decimal


; by sanjib das regn no 98011031
data segment
msg1 db 'enter the octal number$'
msg2 db 'the equivalent decimal no is :$'
deci db 3 dup(?)
data ends

code segment
assume cs:code ,ds:data
begin : mov ax,data
mov ds,ax
mov dx,offset msg1
mov ah,09h
int 21h
mov si,offset deci
xor cl,cl

entry : inc cl
mov ah,01h
int 21h
sub al,30h
mov [si],al
inc si
cmp cl,02h
jne entry

mov ah,09h
mov dx,offset msg2
int 21h

xor ax,ax

mov si,offset deci


mov ah,[si]
mov al,[si+1]
shl ah,03h
add al,ah

aam
xor bx,bx
; mov cl,03h
mov bl,al
mov bh,ah
; shr bh,cl
add bh,30h
; and bl,00000111b
add bl,30h
mov ah,02h
mov dl,bh
int 21h
mov dl,bl
int 21h

mov ax,4c00h
int 21h
code ends
end begin

; program to find whether a string is a palindrome or not

print macro msg ;macro for displaying message


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

better_display macro ;macro for better display


mov ah,02h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
endm

print1 macro rr
mov ah,02h
mov dl,rr
int 21h
endm

input_data macro ;macro for inputting characters


mov ah,01h
int 21h
endm

data segment
msg1 db "enter the string = $"
msg2 db "its a palindrome $"
msg3 db "its not a palindrome $"
user_stack db 20 dup(?)
data ends
code segment
assume cs:code,ds:data

start : mov ax,data


mov ds,ax
mov si,offset user_stack
mov di,si
better_display
print msg1
mov ch,0h
mov cl,0h ;counter for the string length

input: input_data
mov [si],al
inc si
inc cl
cmp al,0dh
jne input

dec si
compare: inc ch
mov ah,[si]
mov al,[di]
print1 ah
print1 al
cmp ah,al
jne loop2
dec si
inc di
jmp compare

loop1 : cmp ch,cl


je loop3

loop2: better_display
print msg3
jmp last

loop3: better_display
print msg2

last : mov ax,4c00h


int 21h

code ends
end start

Das könnte Ihnen auch gefallen