You are on page 1of 35

1

TITLE prb01.asm : DISPLAY ONE CHARACTER


dosseg
.model small
.stack
.code
main proc
mov ah,01h
int 21h
mov ah,02h
mov dl,al
int 21h
mov ah,4ch
int 21h
main endp
end main
TITLE prb02.asm : DISPLAY CONSTANT CHARACTER
dosseg
.model small
.stack
.code
main proc
mov ah,02h
mov dl,'*'
int 21h
mov ah,4ch
int 21h
main endp
end main

2
TITLE prb03.asm : DISPLAY CHARACTER with space
dosseg
.model small
.stack
.code
main proc
mov ah,01h ; for input
int 21h ; interrupt function
mov bl,al ; store temporarily value of ah into bl
mov ah,02h ; call output function
mov dl,' ' ; for display space
int 21h ;
mov dl,bl ; store value of bl into dl
mov ah,02h ; call output function
int 21h
mov ah,4ch
int 21h
main endp
end main
TITLE prb04.asm : DISPLAY CHARACTER with multiple space

dosseg
.model small
.stack
.code
main proc
mov ah,01h ; for input
int 21h ; interrupt function
mov bl,al ; saving value of al into bl
mov ah,02h ; for output
mov dl,' '
int 21h ; interrupt function
mov dl,bl
mov ah,02h
int 21h
mov ah,02h

3
mov dl,' '
int 21h
mov dl,bl
mov ah,02h
int 21h
mov dl,' '
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ah,02h
mov dl,' '
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ah,4ch
int 21h
main endp
end main
TITLE prb05.asm : DISPLAY CHARACTER WITH NEW LINE
dosseg
.model small
.stack
.code
main proc
mov ah,01h ; call input function
int 21h ; for Interrupt
mov bl,al ; saving value of al into bl
mov dl,0dh ; carriage return i.e., moves cursor position
mov ah,02h ; call output function
int 21h ; for Interrupt
mov dl,0ah ; new line feed
int 21h ; Interrupt
mov dl,bl ; transfer value of bl into dl

4
int 21h

; Interrupt

mov ah,4ch ; Return to DOS


int 21h ; for Interrupt
main endp
end main
TITLE prb06.asm : DISPLAY CONSTANT STRING
dosseg
.model small
.stack
.data
A db "COMPUTER SCIENCE$"
.code
main proc
mov ax,@data ; Transfer 16-bit address to ax register, initialize data segment
register
mov ds,ax ; Transfer contents of ax into ds register
lea dx,A ; Before using A define 16-bit address of variable of .data
mov ah,09h ; STRING display function
int 21h
; Interrupt
mov ah,4ch ; Return to DOS
int 21h
main endp
end main
TITLE prb07.asm : DISPLAY CONSTANT TEXT IN TWO LINES
dosseg
.model small
.stack
.data
A db "WELLDONE! $"
B db " YOU ARE WELCOME$"
main proc
mov ax,@data ; transfer 16-bit address to ax register, initialize data segment
register
mov ds,ax ; Transfer contents of ax to ds
lea dx,A ; Transfer address of A into dx rfegister
mov ah,09h ; STRING display function
int 21h

5
lea dx,B ; Transfer address of b into dx register
mov ah,09h ; STRING display function
int 21h
mov ah,4ch ;return to DOS
int 21h
main endp
end main
TITLE prb08.asm : DISPLAY CONSTANT TEXT WITH NEW LINES
dosseg
.model small
.stack
.data
A db 0dh,0ah,"COMPUTER SCIENCE",0dh,0ah,"$"
B db 0dh,0ah,"THIRD YEAR",0dh,0ah,"$"
.code
main proc
mov ax,@data ; Transfer 16-bit address of variable of data into ax register,initialize
data segment register
mov ds,ax ; Transfer contents of ax into ds register
lea dx,A ; Transfer address of A into dx register
mov ah,09h ; STRING display function
int 21h
lea dx,B ; Transfer address of B into dx register
mov ah,09h
int 21h
mov ah,4ch
int 21h
main endp
end main

6
TITLE prb09.asm : ENTER A INPUT M OUTPUT IS M
dosseg
.model small
.stack
.data
A db 0dh,0ah,"ENTER an INPUT...",0dh,0ah,"$"
B db 0dh,0ah,"The OUTPUT is...",0dh,0ah,"$"
.code
main proc
mov ax,@data ; Transfer 16-bit address of variable of data into ax register,initialize
datasegment register
mov ds,ax ; Transfer contents of ax into ds
lea dx,A ; Transfer address of A into dx register
mov ah,09h ; STRING display function
int 21h
; Interrupt
mov ah,01h ; Call input function
int 21h
mov bl,al ; saving contents of al into bl register
lea dx,B ; Transfer address of B into dx register
mov ah,09h ; STRING display function
int 21h
; Interrupt
mov dl,bl ; Transfer contents of bl into dl register
mov ah,02h ; Call output function
int 21h
; Interrupt
mov ah,4ch ; Return to DOS
int 21h
; Interrupt
main endp
end main

7
TITLE prb10.asm : DISPLAY ENGLISH ALPHABET
dosseg
.model small
.stack
.code
main proc
mov cx,26
mov ah,02h
mov dl,'A'
L1:
int 21h
inc dl
loop L1
mov ah,4ch
int 21h
main endp
end main
TITLE prb11.asm : Display all English alphabet with space
DOSSEG
.MODEL SMALL
.STACK
.CODE
MAIN PROC
MOV CX,26
MOV AH,02H
MOV DL,'A'
L1:
INT 21H
INC DL
MOV BL,DL
MOV DL,' '
INT 21H
MOV DL,BL
LOOP L1
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

8
TITLE prb12.asm : Display a message for five times
DOSSEG
.MODEL SMALL
.STACK
.DATA
A db 0dh,0ah,"WELCOME TO THE ASSEMBLY LANGUAGE
PROGRAMMING",0dh,0ah,"$"
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV BX,5
SM:
LEA DX,A
MOV AH,09H
INT 21H
INC DL
DEC BX
JNZ SM
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

9
TITLE prb13.asm:Program to find the largest element in an array
DOSSEG
.MODEL SMALL
.STACK
.DATA
msg1 DB 0DH,0AH, "LARGEST ELEMENT IS :
ARRAY DB 5,9,6,7,1,3
LARGEST DB ?
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
LEA DI,ARRAY
MOV CX,5
MOV AL,[DI] ; memory location
MOV LARGEST,AL
STEP:
INC DI
MOV BL,[DI]
CMP LARGEST,BL
JGE L1
MOV LARGEST,BL
L1:
LOOP STEP
ADD LARGEST,30H ; integer to character
LEA DX,MSG1
MOV AH,09H
INT 21H
MOV DL,LARGEST
MOV AH,02H
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

$"

10
TITLE prb14.asm: Program to find the LARGEST and SMALLEST element in an
array
DOSSEG
.MODEL SMALL
.STACK
.DATA
msg1 DB 0DH,0AH, "LARGEST ELEMENT IS : $"
MSG2 DB 0DH,0AH, "SMALLEST ELEMENT IS : $"
ARRAY DB 5,9,6,7,1,3
LARGEST DB ?
SMALLEST DB ?
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
LEA DI,ARRAY
MOV CX,5
MOV AL,[DI]
MOV LARGEST,AL
MOV SMALLEST,AL
STEP:
INC DI
MOV BL,[DI] ; Memory location
CMP LARGEST,BL
JGE L1
MOV LARGEST,BL
L1:
CMP SMALLEST,BL
JLE L2
MOV SMALLEST,BL
L2:
LOOP STEP
ADD LARGEST,30H ; integer to character
ADD SMALLEST,30H
LEA DX,MSG1
MOV AH,09H
INT 21H
MOV DL,LARGEST
MOV AH,02H

11
INT 21H
LEA DX,MSG2
MOV AH,09H
INT 21H
MOV DL,SMALLEST
MOV AH,02H
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

12
TITLE prb15.asm : REVERSE A STRING
DOSSEG
PRINT MACRO MSG
LEA DX,MSG
MOV AH,09H
INT 21H
ENDM
.MODEL SMALL
.STACK 100H
.DATA
MSG1 DB 0DH,0AH, "STRING REVERSE PROGRAM $"
MSG2 DB 0DH,0AH, "ENTER A STRING : $"
MSG3 DB 0DH,0AH, "REVERSE STRING IS : $"
.CODE
MOV AX, @DATA
MOV DS,AX
PRINT MSG1
PRINT MSG2
MOV CX,00
MOV AH,01H
INT 21H
AGAIN:
CMP AL,0DH
JE END_AGAIN
PUSH AX
INC CX
INT 21H
JMP AGAIN
END_AGAIN:
PRINT MSG3
MOV AH,02H
TOP:
POP DX
INT 21H
LOOP TOP
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

13
TITLE prb16.asm : REVERSE AND FIND THE LENGTH OF A STRING
DOSSEG
.MODEL SMALL
.STACK 100H
PRINT MACRO MSG
LEA DX,MSG
MOV AH,09H
INT 21H
ENDM
.DATA
MSG1 DB 0DH,0AH, "STRING LENGTH AND REVERSE PROGRAM $"
MSG2 DB 0DH,0AH, "ENTER A STRING : $"
MSG3 DB 0DH,0AH, "REVERSE STRING IS : $"
MSG4 DB 0DH,0AH, "LENGTH = $"
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS,AX
PRINT MSG1
PRINT MSG2
MOV CX,00
MOV AH,01H
INT 21H
AGAIN:
CMP AL,0DH
JE END_AGAIN
PUSH AX
INC CX
INT 21H
JMP AGAIN
END_AGAIN:
MOV BX,CX
PRINT MSG3
MOV AH,02H
TOP:
POP DX
INT 21H
LOOP TOP

14
PRINT MSG4
MOV AH,02H
ADD BX,30H
MOV DX,BX
MOV AH,02H
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

15
TITLE prb17.asm : A program that read capital letter and display in small form
dosseg
.model small
.stack
.data
A db 0dh,0ah,"ENTER an INPUT...",0dh,0ah,"$"
B db 0dh,0ah,"The OUTPUT is...",0dh,0ah,"$"
.code
main proc
mov ax,@data
mov ds,ax
lea dx,A
mov ah,09h
int 21h
mov ah,01h
int 21h
add al,20h
mov bl,al
lea dx,B
mov ah,09h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ah,4ch
int 21h
main endp
end main

16
TITLE prb18.asm : A program that read small letter and display in capital form
dosseg
.model small
.stack
.data
A db 0dh,0ah,"ENTER an INPUT...",0dh,0ah,"$"
B db 0dh,0ah,"The OUTPUT is...",0dh,0ah,"$"
.code
main proc
mov ax,@data
mov ds,ax
lea dx,a
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,20h
mov bl,al
lea dx,B
mov ah,09h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov ah,4ch
int 21h
main endp
end main

17
TITLE prb19.asm : PROGRAM FOR UPPER TO LOWER CONVERSION AND
VICE VERSA
dosseg
.model small
.stack
.data
msg1 db 0dh,0ah,"ENTER an INPUT...",0dh,0ah,"$"
msg2 db 0dh,0ah,"The OUTPUT is...",0dh,0ah,"$"
.code
main proc
mov ax,@data
mov ds,ax
lea dx,msg1
mov ah,09h
int 21h
mov ah,01h
int 21h
mov bl,al
cmp bl,'A'
jge L1
cmp bl,'a'
jge L2
L1:
cmp bl,'Z'
jle L3
L2:
cmp bl,'z'
jle L4
L3:
add bl,20h
lea dx,msg2
mov ah,09h
int 21h
mov dl,bl
mov ah,02h
int 21h
jmp L5

18
L4:
sub bl,20h
lea dx,msg2
mov ah,09h
int 21h
mov dl,bl
mov ah,02h
int 21h
L5:
mov ah,4ch
int 21h
main endp
end main

19
TITLE prb20.asm : Calculate the following expression
; (M-N)P if x>y
; M/N + P if x<=y
dosseg
.model small
.stack
print macro msg
lea dx,msg
mov ah,09h
int 21h
endm
; end of macro
.data
msg1 db 0dh,0ah," M = $"
msg2 db 0dh,0ah,' N = $'
msg3 db 0dh,0ah,' P = $'
msg4 db 0dh,0ah,' X = $'
msg5 db 0dh,0ah,' Y = $'
msg6 db 0dh,0ah,' Z = (M-N)P = $' ; if x > y
msg7 db 0dh,0ah,' Z = (M/N)+P = $' ; if x <= y
.code
main proc
mov ax,@data
mov ds,ax
print msg1
mov ah,01h
int 21h
sub al,30h
push ax
print msg2
mov ah,01h
int 21h
sub al,30h
push ax
print msg3
mov ah,01h
int 21h
sub al,30h
push ax

20
print msg4
mov ah,01h
int 21h
sub al,30h
mov bl,al
print msg5
mov ah,01h
int 21h
sub al,30h
cmp bl,al
jle step1
pop cx
pop bx
pop ax
sub al,bl
mul cl
jmp step3
step1:
pop cx
pop bx
pop ax
mov ah,00
div bl
add al,cl
step2:
push ax
print msg7
pop ax
mov dl,al
add dl,30h
mov ah,02h
int 21h
jmp L4
step3:
push ax
print msg6
pop ax
mov dl,al

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

L4:
mov ah,4ch
int 21h
main endp
end main

22
TITLE prb21.asm : Calculate the following expression
; Y = M+N-P+1

print macro msg


lea dx,msg
mov ah,09h
int 21h
endm
; end of macro
dosseg
.model small
.stack
.data
msg1 db 0dh,0ah," M = $"
msg2 db 0dh,0ah,' N = $'
msg3 db 0dh,0ah,' P = $'
msg4 db 0dh,0ah,' Y = M + N - P + 1 = $'
.code
main proc
mov ax,@data
mov ds,ax
print msg1
mov ah,01h
int 21h
sub al,30h
push ax
print msg2
mov ah,01h
int 21h
sub al,30h
push ax
print msg3
mov ah,01h
int 21h
sub al,30h
push ax

23
pop cx
pop bx
pop ax
mov ah,00
add al,bl
sub al,cl
add al,01h
push ax
print msg4
pop ax
mov dl,al
add dl,30h
mov ah,02h
int 21h
mov ah,4ch
int 21h
main endp
end main

24
TITLE prb22.asm : To convert from Hex to Binary equivalent
dosseg
.model small
.stack
print macro msg
lea dx,msg
mov ah,09h
int 21h
endm
.data
msg1 db 0dh,0ah,"Enter two digit Hex no : $"
msg2 db 0dh,0ah,"The binary Number is : $"
.code
main proc
mov ax,@data
mov ds,ax
print msg1
xor bx,bx
mov cl,4
mov ah,01h
int 21h

; clear BX
; counter for 4 shifts
; input character function
; input a character

while_:
cmp al,0dh ; charcter?
je end_while ; yes, exit
cmp al,39h ; a digit?
jg letter ; no, a letter
jmp shift ; go to insert in BX
letter:
sub al,37h

; convert letter to binary value

shift:
shl bl,cl
; make room for new value
and al,0fh
or bl,al
; put value into low 4 bits of BX
int 21h
; input a character
jmp while_
; loop until character
end_while:
print msg2
mov ah,bl

25
mov cx,8
L1:
shl ah,1
mov dl,'0'
jnc L2
mov dl,'1'
L2:
push ax
mov ah,2
int 21h
pop ax
loop L1
mov ah,4ch
int 21h
main endp
end main

26
;prb23.asm : COMPUTE THE EXPRESSION Sum_of(XiYi)
dosseg
.model small
.stack 100h
print macro msg
lea dx,msg
mov ah,09h
int 21h
endm
.data
msg1 db "Result = $"
X db 2,3,4
Y db 3,2,4
S dw ?
.code
main proc
mov ax,@data
mov ds,ax
mov cx,3
; loop count 3 times
lea si,X
; assign address of x to si
lea di,y
; assign address of y to di
A1:
mov al,[si] ; value of si is placed into al
mov bl,[di] ; value of di is placed into bl
mul bl
add S,ax
mov ax,0000h
add si,1
add di,1
loop A1
print msg1
mov ax,s
call int2asc
mov ah,4ch
int 21h
main endp
int2asc proc
mov cx,00
mov bx,0ah ; 0ah=10

27
rpt:
mov dx,00h
div bx
add dl,30h
inc cx
push dx
cmp ax,0ah
jge rpt
add al,30h
inc cx
push ax
mov ah,02h
print_loop:
pop dx
int 21h
loop print_loop
ret ; return to main function
int2asc endp
end main

28
;prb24.asm : Compute the expression Sum_of(Xi / Yi)

dosseg
.model small
.stack 100h
print macro msg
lea dx,msg
mov ah,09h
int 21h
endm
.data
msg1 db "Result = $"
X db 4,6,8
Y db 2,3,4
S dw ?
.code
main proc
mov ax,@data
mov ds,ax
mov cx,3 ; loop count 3 times
lea si,X ; assign address of x to si
lea di,y ; assign address of y to di
A1:
mov ah,00
mov al,[si] ; value of si is placed into al
mov bh,00
mov bl,[di] ; value of di is placed into bl
div bl
add S,ax
mov ax,0000h
add si,1
add di,1
loop A1
print msg1
mov ax,s
call int2asc
mov ah,4ch
int 21h
main endp

29
int2asc proc
mov cx,00
mov bx,0ah ; 0ah=10
rpt:
mov dx,00h
div bx
; divide ax by default
add dl,30h ; int to char so add 30h
inc cx
push dx
cmp ax,0ah
jge rpt
add al,30h
inc cx
push ax
mov ah,02h
print_loop:
pop dx
int 21h
loop print_loop
ret ; return to main function
int2asc endp
end main

30
;prb25.asm :Sum_of_xi*yi + zi = (x1y1 +z1) + (x2y2 + z2) + ...+ (xnyn + zn)
;program to calculate the following expression Sum (XiYi+Zi)
dosseg
.MODEL SMALL
.STACK 100
PRINT MACRO MSG
LEA DX,MSG
MOV AH,09H
INT 21H
ENDM
.DATA
MSG1 DB " Result = $"
X DB 6,3,2
Y DB 4,7,5
Z DB 7,8,10
S DW ?
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV CX,3
MOV BX,0000H
MOV SI,0000H
A1:
MOV AL,X[BX]
MUL Y[BX]
MOV DL,Z[BX]
MOV DH,0
ADD AX,DX
ADD S,AX
MOV AX,0
INC BX
LOOP A1
MOV AX,S
PUSH AX
PRINT MSG1
POP AX
CALL INT2ASC
MOV AH,4CH
INT 21H

31
MAIN ENDP
INT2ASC PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV CX,0000H
MOV BX,0ah
RPT:
MOV DX,00H
DIV BX
ADD DL,'0'
INC CX
PUSH DX
CMP AX,0AH
JGE RPT
ADD AL,'0'
INC CX
PUSH AX
PRINT2:
POP DX
MOV AH,02H
INT 21H
LOOP PRINT2
POP DX
POP CX
POP BX
POP AX
RET ; return to main
INT2ASC ENDP
END MAIN

32
Title prb26.asm : Sort an array using Bubble sort algorithm
dosseg
.model small
.stack 100h
.data
A db 9,6,5,7,3
.code
main proc
mov ax,@data
mov ds,ax
lea si,A
mov bx,5
push bx
push si
dec bx
S1:
push si
mov dx,si
inc si
mov di,si
mov si,dx
mov cx,bx
SL1:
mov al,[di]
cmp [si],al
jng bb
xchg [si],al
mov [di],al
bb:
mov si,di
inc di
loop SL1
pop si
dec bx
jnz S1
pop si
pop bx
mov cx,bx
print:

33
mov dl,[si]
add dl,30h
mov ah,02h
int 21h
mov dl,' '
int 21h
inc si
loop print
mov ah,4ch
int 21h
main endp
end main

34
Title prb27.asm : fibonacci series
dosseg
.model small
.stack 100h
PRINT MACRO MSG
LEA DX,MSG
MOV AH,09H
INT 21H
ENDM
.data
msg1 db "fibonacci series : ",0dh,0ah," 00",0dh,0ah," 01 $"
msg2 db 0dh,0ah,' $'
.code
INT2ASC PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV CX,0000H
MOV BX,0ah
RPT:
MOV DX,00H
DIV BX
ADD DL,'0'
INC CX
PUSH DX
CMP AX,0AH
JGE RPT
ADD AL,'0'
INC CX
PUSH AX
PRINT2:
POP DX
MOV AH,02H
INT 21H
LOOP PRINT2
POP DX
POP CX
POP BX
POP AX
RET ; return to main
INT2ASC ENDP

35

fibonacci proc
mov al,1
mov bl,0
mov cx,8
step:
push ax
add al,bl
push ax
print msg2
pop ax
mov ah,00
call int2asc
pop bx
loop step
ret
fibonacci endp
start:
mov ax,@data
mov ds,ax
print msg1
call fibonacci
mov ah,4ch
int 21h
end start

You might also like