Mpilab 17
Mpilab 17
19.
20.
0
Program 1. Write a Program to Print character A to Z
Code:
.model small
.stack 100h
.data
.code
main proc
mov cx , 26
mov dx , 65
l1:
mov ah , 2
int 21h
add dx , 1
loop l1
mov ah , 4ch
int 21h
main endp
end main
Output:
1
Program 2. Write a Program to Print 0 to 9
Code:
.model small
.stack 100h
.code
main proc
mov cx , 10
mov dx , 48
l1:
mov ah , 2
int 21h
add dx , 1
loop l1
mov ah , 4ch
int 21h
main endp
end main
Output:
2
Program 3. Write a Program to Add two Number by taking input
Code:
.model small
.stack 100h
.code
main proc
mov ah , 1
int 21h
mov bl , al
mov ah ,1
int 21h
mov cl , al
add bl , cl
sub bl , 48
mov dl , bl
mov ah , 2
int 21h
main endp
end main
Output:
3
Program 4. Write a Program to Subtract 2 Number in assembly language
Code:
.model small
.stack 100h
.data
.code
main proc
mov bl , 10
mov cl, 2
sub bl , cl
add bl , 48
mov dl , bl
mov ah , 2
int 21h
mov ah , 4ch
int 21h
main endp
end main
Output:
4
Program 5. Write a Program to find square of a number.Code:
.model small
.stack 100h
.data
a db 03h
assume CS:abc
abc segment
start:
mov ax , @data
mov ds , ax
mov al , a
mul al
add al , 30h
mov dl, al
mov ah , 02h
int 21h
mov ax , 4c00h
int 21h
abc ends
end start
end
Output:
5
Program 6. Write a Program to Take a Input Character and Print it
Code:
.model small
.stack 100h
.data
.code
main proc
mov ah , 1
int 21h
mov dl , al
mov ah , 2
int 21h
main endp
end main
Output:
6
msg2 db 'world$'
.code
main proc
mov ax , @data
mov ds , ax
mov dx , offset msg1
mov ah , 9
int 21h
mov dx , 10
mov ah , 2
int 21h
mov dx , 13
mov ah , 2
int 21h
mov dx , offset msg2
mov ah , 9
int 21h
mov ah , 4ch
int 21h
main endp
end main
Output:
7
Program 8. Write a Program to Convert Lower Character To Capital Character
Code:
.model small
.stack 100h
.data
msg1 db "Enter any character in lower Case:$"
msg2 db "Enter any character in lower Case:$"
.code
main proc
mov ax , @data
mov ds , ax
lea dx , msg1
mov ah , 09h
int 21h
mov ah , 1
int 21h
mov cl , al
mov dx , 10
mov ah , 2
int 21h
sub cl , 20h
lea dx , msg2
mov ah , 09h
int 21h
mov dl , cl
mov ah , 2
int 21h
main endp
end main
8
Output:
9
loop l2
mov ah , 4ch
int 21h
main endp
end main
Output:
10
Program 10. Write a Program to Print Factorial of a number
Code:
.model small
.stack 100h
.data
a db 03h
assume CS:abc
abc segment
start:
mov ax , @data
mov ds , ax
mov cl , a
mov al , 0001h
back:
mul cl
loop back
add al , 30h
mov dl ,al
mov ah ,02h
int 21h
mov ax , 4c00h
int 21h
abc ends
end start
end
Output:
11
Program 11. Write a Program to Check the String is Polindrome or NOT.
Code:
.model small
.stack 100h
.data
msg1 db 'String is polindrome','$'
msg2 db 'String is not polindrome','$'
string db , "kook$" , 0
.code
assume CS:abc
abc segment
start:
mov ax , @data
mov ds , ax
mov cx , 0000h
find_len:
mov al , [si]
cmp al , '$'
je len_found
inc si
12
inc cx
jmp find_len
len_found:
dec si
mov di , bx
chk_polindrome:
cmp di, si
jge polindrome_found
mov al , [di]
mov dl , [si]
cmp al , dl
jne not_polindrome
inc di
dec si
jmp chk_polindrome
polindrome_found:
mov dx , offset msg1
mov ah , 09h
int 21h
jmp done
13
not_polindrome:
mov dx , offset mgs2
mov ah , 09h
int 21h
jmp done
done:
mov ah , 4c00h
int 21h
abc ends
end start
end
Output:
14
Program 12. Write a Program To display ASCII character in rows and columns for a
given range
Code:
.model small
.stack 100h
.code
assume CS:abc
abc segment
start:
mov ax , @data
mov ds , ax
mov dx , 0000h
mov dl , 10h
mov cx , 000fh
mov ax , 0000h
row:
mov ah , 02h
push cx
mov cx , 0010h
col:
int 21h
push dx
mov dl , 00h
15
int 21h
pop dx
inc dx
loop col
pop cx
push dx
mov dl , 0dh
int 21h
mov dl , 0ah
int 21h
pop dx
loop row
mov ax , 4c00h
int 21h
abc ends
end start
end
Output:
16
Program 13. Write a Program to store array and find the largest element in array
Code:
.model small
.stack 100h
.data
array db 1,2,7,9,6,4
.code
assume CS:abc
abc segment
start:
mov ax , @data
mov ds , ax
mov cx , 6
mov bl , 0
LEA si , array
up:
mov al , [si]
cmp al , bl
jbe nxt
mov bl , al
nxt:
17
inc si
loop up
mov dl , bl
add dl , 48
mov ah , 02h
int 21h
mov ax , 4c00h
int 21h
abc ends
end start
end
Output:
18
Program 14. Write a Program to print a string using iteration
Code:
.model small
.stack 100h
.data
msg1 db 'Hansraj_Kishore','$'
.code
assume CS:abc
abc segment
start
mov ax , @data
mov ds , ax
lea si,msg1
mov cx , 000Fh
iter:
mov dx , [si]
mov ah , 02h
int 21h
inc si
dec c
jnz iter
mov ax , 4c00h
int 21h
abc ends
end start
end
19
Output:
Code:
.model small
.stack 100h
.data
msg1 db 'hello$'
msg2 db 'world$'
.code
main proc
mov ax , @data
mov ds , ax
mov dx , offset msg1
mov ah , 9
int 21h
mov dx , 10
mov ah , 2
int 21h
mov dx , 13
mov ah , 2
int 21h
mov dx , offset msg2
mov ah , 9
20
int 21h
mov ah , 4ch
int 21h
main endp
end main
Output:
.code
assume CS:abc
abc segment
21
start:
mov ax , @data
mov ds , ax
curr:
push cx
mov cx , 0007h
nxt:
mov ah , 02h
mov dl , [bx]
int 21h
inc bx
dec cx
jnz nxt
mov dl , 00h
int 21h
pop cx
22
loop curr
mov ax , 4c00h
int 21h
abc ends
end start
end
Output:
23
Program 17. Write a Program to find the sum of two number without using
arithmetic operation
Code:
.model small
.stack 100h
.data
CR EQU 0DH
LF EQU 0AH
num1 db 4
num2 db 5
.code
assume CS:abc
abc segment
start:
mov ax , @data
mov ds , ax
mov al , num1
mov bl , num2
l1:
mov dl , al
and dl , bl
xor al , bl
24
shl dl , 1
mov bl , dl
jnz l1
add al , '0'
mov dl , al
mov ah , 02h
int 21h
mov ax , 4c00h
int 21h
abc ends
end start
end
Output:
25
Program 18. Write a Program to Print Character from a to z.
Code:
.model small
.stack 100h
.data
.code
main proc
mov cx , 26
mov dx , 97
l1:
mov ah , 2
int 21h
add dx , 1
loop l1
mov ah , 4ch
int 21h
main endp
end main
Output:
26
27