Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

EEE-3104: Microprocessor and Interfacing Lab

Dept. of Electrical and Electronic Engineering


University of Dhaka

Prof. Sazzad M.S. Imran, PhD


sazzadmsi.webnode.com
&
Dr. Sakhawat Hussain
Lab Experiment #02 (Part-1)
Name of the Experiment: Write and execute an assembly language program that reads a
number and checks whether it is odd or even or prime.

Algorithm of the Program:


Write algorithm of the program by yourself.

Flowchart of the Algorithm:


Draw flowchart of the algorithm by yourself.
Lab Experiment #02 (Part-1)
Programming Code:
readnum macro num
mov ah, 01h
int 21h
sub al, ‘0’
mov bh, 0ah
mul bh ;axal×bh
mov num, al
mov ah, 01h
int 21h
sub al, ‘0’
add num, al
endm

printstring macro msg


mov ah, 09h
mov dx, offset msg
int 21h
endm
Lab Experiment #02 (Part-1)
Programming Code:
_DATA segment
cr equ 0dh
lf equ 0ah
msg1 db ‘Enter number <XX>: ’, ‘$’
msg2 db cr, lf, ‘Even number.’, ‘$’
msg3 db cr, lf, ‘Odd number.’, ‘$’
msg4 db cr, lf, ‘Prime number.’, ‘$’
msg5 db cr, lf, ‘Not prime number.’, ‘$’
num db ?
_DATA ends
Lab Experiment #02 (Part-1)
Programming Code:
_CODE segment
assume cs: _CODE, ds: _DATA
start: mov ax, _DATA
mov ds, ax
printstring msg1
readnum num
mov ah, 00
mov al, num
mov bl, 02
div bl ;alax/bl, ahax%bl
mov bh, 00
mov bl, al
cmp ah, 00
je evennum
printstring msg3
jmp checkprime
evennum: printstring msg2
Lab Experiment #02 (Part-1)
Programming Code:
checkprime: and dx, 00
mov ah, 00
mov al, num
cmp al, 01
jle notprime
cmp al, 02
je isprime
mov ch, 00
mov cl, 02
chkprm2: div cx ;axdx:ax/cx, dxdx:ax%cx
cmp dx, 00
je notprime
and dx, 00
mov ah, 00
mov al, num
inc cx
cmp bx, cx
jge chkprm2
Lab Experiment #02 (Part-1)
Programming Code:
isprime: printstring msg4
jmp skip
notprime: printstring msg5
skip: mov ah, 4ch
mov al, 00h
int 21h
_CODE ends
end start

Sample Output:
Enter number <XX>: 43 Enter number <XX>: 34
Odd number. Even number.
Prime number. Not prime number.

Enter number <XX>: 02 Enter number <XX>: 27


Even number. Odd number.
Prime number. Not prime number.

You might also like