1- Perform the following arithmetic expression.
Result = -5 + (8 - 2)
.model small
.stack 100h
.data
.code
main proc
mov al,5
neg al ; al = -5
mov bl,8
sub bl,2 ; (8-2)=6
add al,bl ; -5 + 6 =1
mov ah,2
mov dl,al
add dl,30h
int 21h
main endp
end main
2- Take Two numbers from the user and add them; subtract them
.model small
.stack 100h
.data
.code
main proc
mov ah,1
int 21h
mov dl,al
;input second no
mov ah,1
int 21h
sub dl,al
mov ah,2
add dl,30h
int 21h
main endp
end main
3- Write a program to find if the number is Even or Odd.
include ‘emu8086.inc’
.model small
.code
main proc
mov ah,1 ;input the number to be checked
int 21h
mov bl,2 ; divisor/source moved to bl
div bl
cmp ah,0 ; remainder goes to AH, check it
JE even ; remainder zero is even
JNE odd ; remainder zero is odd
even:
print ‘Even No’
jmp exit
odd:
print ‘Odd No’
exit:
main endp
end main
4- Compare two numbers and tell which one is bigger.
include ‘emu8086.inc’
.model small
.code
main proc
mov ah,1 ; input first number
int 21h
mov bl,al ; this number is saved to ‘bl’
mov ah,1 ; input second number
int 21h
CMP bl,al ; compare the first number with second
JG label1 ; if bl > al, goto label1
Print ‘Second no is bigger’
JMP exit
Label1:
Print ‘First no is bigger’
Exit:
Main endp
End main
5- Write a program to multiply two positive numbers by a ‘repeated
addition’ method. For example, to multiply 5ⅹ 3, the program evaluates
the product by adding 5 three times, or 5 + 5 + 5.
model small
.stack 100h
.data
.code
main proc
mov bl,5
mov cx,3
mov al,0
label1:
add al,bl
LOOP label1
mov bh,10
div bh
mov bl,ah
mov dl,al
add dl,30h
mov ah,2
int 21h
mov dl,bl
add dl,30h
mov ah,2
int 21h
main endp
end main
6- To input a string at the prompt, and display it in reverse order.
.model small
.stack 100h
.data
array db '?'
.code
main proc
mov ax,@data
mov ds,ax
lea si,array
mov cx,0
l1:
mov ah,1
int 21h
cmp al,0dh
je label1
mov [si],al
inc si
inc cx
jmp l1
inc si
mov [si],'$'
label1:
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
dec si
rev1:
mov ah,2
mov dl,[si]
int 21h
dec si
loop rev1
mov ah,4ch
int 21h
main endp
end main
7- ‘Assembly’ Application Programs
• Password-protected application, used to sign in to a computer.
.model small
.stack 100h
.data
prompt db 'Enter Password$'
correct db 'Correct Password$'
wrong db 'Wrong Password$'
password db 'Asim$'
.code
main proc
mov ax,@data
mov ds,ax
lea si,password
mov cx,4 ;limit cx=4 character password only
mov ah,9
LEA dx, prompt
int 21h
mov ah,2 ; new line
mov dl,0ah
int 21h
mov dl,0dh
int 21h
input:
mov ah,8 ;Function # 8 hides character input at run time
int 21h
cmp al,[si]
jne finish
mov ah,2
mov dl,'*' ;display * in case of password
int 21h
inc si
inc di
loop input
mov ah,2 ; new line code
mov dl,0dh
int 21h
mov dl,0ah
int 21h
mov ah,9
LEA dx, correct
int 21h
jmp terminate
finish:
mov ah,2
mov dl,’*’
int 21h
mov dl,0dh ; new line code
int 21h
mov dl,0ah
int 21h
mov ah,9
LEA dx, wrong
int 21h
terminate:
mov ah,4ch
int 21h
main endp
end main
o Count the capital characters in a defined string.
.model small
.stack 100h
.data
msg db 'BDEFg$'
.code
main proc
mov ax,@data
mov ds,ax
lea si,msg
mov cx,5 ;length of string except $
mov bl,0 ;set character count to zero
inrange: ;check if character falls in-ragne
mov al,[si]
inc si ;next character in string
cmp al,41h ;code for 'A'
jl inrange ;if character is < 41h
cmp al,5ah ;value for 'Z'
jg end ;end if value is greater than Z, no increment
inc bl ;both conditions Ok the increment count
end:
loop inrange
mov ah,2 ;new line
mov dl,bl
add dl,30h
int 21h
mov ah,4ch
int 21h
main endp
end main
• Search and Replace a character in a string
.model small
.data
string db 'house$' ;we want to replace 'u' with 'r'
msg1 db 'Enter value to be searched: $'
msg2 db 'Enter its new value: $'
msg3 db 'Updated Sring is: $'
.code
main proc
mov ax,@data
mov ds,ax
lea si,string
mov cx,5
mov ah,9
lea dx,msg1
int 21h
mov ah,1 ;enter value to be searched in a string
int 21h
label1:
cmp [si],al ;search for the entered value
je update ;if found go to label to update it
inc si ;otherwise increment SI and keep on
searching
loop label1
update:
mov ah,9
lea dx,msg2
int 21h
mov ah,1 ;user will enter the new value to
update it
int 21h
mov [si],al ;value updated
mov ah,9
lea dx,msg3
int 21h
mov ah,9
mov dx,offset string
int 21h
main endp
end main
• Count the ‘Even’ numbers in an entered string
Program Flow: User will enter digits till Enter key is pressed.
Each digit will be divided by 2 to find if remainder is zero. Display
count.
Code:
.model small
.stack 100h
.code
main proc
mov cl,0 ;initialize even digits count to zero
mov bl,2 ;dividing a number by 2 reveals if its even or not
even:
mov ah,1 ;user will enter the digits
int 21h
cmp al,0dh ;enter key compare
je display
div bl
cmp ah,00h ;check remainder if it is zero, hence even number
je counter
jmp even
counter:
inc cl ;increment even digits counter value
jmp even
display:
mov ah,2 ; new line code
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov ah,2
mov dl,cl ;display the value of the count
add dl,30h
int 21h
main endp
end main
8-Display a capital letters string into small letters
.model small
.data
msg db 'master$'
.code
main proc
mov ax,@data
mov ds,ax
lea si,msg
mov cx,6
label:
mov al,[si]
AND al,11011111b
inc si
mov ah,2
mov dl,al
int 21h
loop label
main endp
end main
9-Write a procedure which displays a string in reverse order.
model small
.data
str db 'Master$'
.code
main proc
mov ax,@data
mov ds,ax
lea si,str
mov cx,9
read:
mov al,[si]
inc si
cmp al,'$'
je rev1
jne read
rev1:
call rev
loop rev1
mov ah,4ch
int 21h
rev proc
mov ah,2
mov dl,[si]
int 21h
dec si
ret
rev endp