Coal Lab 13
Coal Lab 13
Exercise 01:
Perform the above examples on MASM and run .exe file.
EXAMPLE 1 CODE:
.model small
.stack 100h
.data
MSG1 db 0ah,0dh,"Enter first number:$"
MSG2 db 0ah,0dh,"Enter first number:$"
MSG3 db 0ah,0dh,"Result of addition is :$"
.code
main proc
mov ax,@data
mov ds,ax
LEA DX,MSG1
MOV ah,9
int 21h
mov ah,1
int 21h
mov bl,al
LEA DX,MSG2
MOV ah,9
int 21h
mov ah,1
int 21h
add bl,al
sub bl,48
LEA DX,MSG3
MOV ah,9
int 21h
mov ah,2
mov dl,bl
int 21h
main endp
end main
Ret
OUTPUT:
EXAMPLE 2 CODE:
.model small
.stack 100h
.data
MSG1 db 0ah,0dh,"Enter first number:$"
MSG2 db 0ah,0dh,"Enter first number:$"
MSG3 db 0ah,0dh,"Numbers are equal :$"
MSG4 db 0ah,0dh,"Numbers are un-equal :$"
.code
main proc
mov ax,@data
mov ds,ax
LEA DX,MSG1
MOV ah,9
int 21h
mov ah,1
int 21h
mov bl,al
LEA DX,MSG2
MOV ah,9
int 21h
mov ah,1
int 21h
cmp bl,al
je exit
jmp quit
quit:
LEA dx,msg4
mov ah,9
int 21h
jmp stop
exit:
lea dx,msg3
mov ah,9
int 21h
stop:
main endp
end main
ret
OUTPUT:
Exercise 02:
Write a program to display your bio data using carriage return and line feed macro
CODE:
.model msmall
.stack 100h
.data
MSG db 0ah,0dh," ***BIO-DATA***$"
MSG2 db 0ah,0dh,"Enter First name: Haifa$"
MSG3 db 0ah,0dh,"Enter Last name: Tabbasum Shah$"
MSG4 db 0ah,0dh,"Enter Age:20$"
MSG5 db 0ah,0dh,"Enter Nationality:Pakistani$"
.code
main proc
mov ax,@data
mov ds,ax
LEA DX,MSG
MOV ah,9
int 21h
LEA DX,MSG2
MOV ah,9
int 21h
LEA DX,MSG3
MOV ah,9
int 21h
LEA DX,MSG4
MOV ah,9
int 21h
LEA DX,MSG5
MOV ah,9
int 21h
main endp
end main
OUTPUT:
Exercise 03:
Write a program that converts lower case character into upper case character
CODE:
org 100h
.model small
.stack 100h
.data
MSG1 db 0ah,0dh,"Enter alphabet in lower case: $"
MSG2 db 0ah,0dh,"Not an alphabet!$"
MSG3 db 0ah,0dh,"Upper case alphabet:$"
.code
main proc
mov ax,@data
mov ds,ax
LEA DX,MSG1
MOV ah,9h
int 21h
mov ah,1h
int 21h
mov bl,al
cmp bl, 'a'
jl noalpha
cmp bl,'z'
jg noalpha
LEA DX, MSG3
MOV ah,9
int 21h
sub bl,32
MOV dl,bl
mov ah,2
int 21h
jmp stop
noalpha:
LEA DX, MSG2
mov ah,9
int 21h
stop:
main endp
ret
OUTPUT:
Exercise 04:
Take a number from user and check if it is positive or negative
CODE:
.model small
.stack 100h
.data
.code
main proc
mov ax,@data
mov ds,ax
LEA DX,MSG1
MOV ah,9
int 21h
mov ah,1
int 21h
cmp al,'-'
je inp
cmp al,0
jnp pos
inp:
mov ah,1h
int 21h
jmp neg
pos:
LEA DX,MSG3
mov ah,9h
int 21h
jmp stop
neg:
LEA DX,MSG4
mov ah,9h
int 21h
jmp stop
stop:
end main
ret
OUTPUT:
Exercise 05:
Write a program to multiply two 8-bit numbers
CODE:
.model small
.stack 100h
.data
MSG1 db 0ah,0dh,"Enter first number:$"
MSG2 db 0ah,0dh,"Enter second number:$"
MSG3 db 0ah,0dh,"Result of multiplication is :$"
RESULT db 6 dup('$')
.code
main proc
mov ax, @data
mov ds, ax
lea dx, MSG1
mov ah, 9
int 21h
mov ah, 1
int 21h
sub al, '0'
mov bl, al
lea dx, MSG2
mov ah, 9
int 21h
mov ah, 1
int 21h
sub al, '0'
mov bh, al
mov al, bl
mul bh
lea si, RESULT + 5
mov byte ptr [si], '$'
dec si
mov cx, 0
mov bx, 10
convert_loop:
xor dx, dx
div bx
add dl, '0'
mov [si], dl
dec si
inc cx
test ax, ax
jnz convert_loop
inc si
lea dx, MSG3
mov ah, 9
int 21h
lea dx, [si]
mov ah, 9
int 21h
mov ah, 4Ch
int 21h
main endp
end main
OUTPUT:
Exercise 06:
Write a program to generate positive number from 1-20 using loop concept
CODE:
.MODEL SMALL
.STACK 100H
.DATA
NUM DW ?
MSG1 DB 'POSITIVE NUMBERS FROM 1 TO 20:$'
SPACE DB ' '
lbk db 13,10,'$'
numstr db '$$$$$$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH, 9
LEA DX, MSG1
INT 21h
MOV NUM, 1
START:
CMP NUM, 20
JA END_
mov si, offset numstr
mov ax, num
call number2string
mov ah, 9
mov dx, offset numstr
int 21h
mov ah, 9
mov dx, offset space
int 21h
INC NUM
JMP START
END_:
MOV AX, 4C00H
INT 21h
MAIN ENDP
number2string proc
call dollars
mov bx, 10
mov cx, 0
cycle1:
mov dx, 0
div bx
push dx
inc cx
cmp ax, 0
jne cycle1
cycle2:
pop dx
add dl, 48
mov [ si ], dl
inc si
loop cycle2
ret
number2string endp
dollars proc
mov cx, 6
mov di, offset numstr
dollars_loop:
mov bl, '$'
mov [ di ], bl
inc di
loop dollars_loop
ret
dollars endp
END MAIN
OUTPUT: