This document describes a lab experiment to write an assembly language program that reads a number and checks whether it is odd or even or prime. It includes the algorithm, flowchart, programming code, and a sample output. The program uses macros to read a number from the user, print strings, and checks the number for even/odd/prime status using division and modulo operations. It then prints the appropriate response string based on the results.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
23 views
Lecture #04, Microprocessor Lab
This document describes a lab experiment to write an assembly language program that reads a number and checks whether it is odd or even or prime. It includes the algorithm, flowchart, programming code, and a sample output. The program uses macros to read a number from the user, print strings, and checks the number for even/odd/prime status using division and modulo operations. It then prints the appropriate response string based on the results.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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 ;axal×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 ;alax/bl, ahax%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 ;axdx:ax/cx, dxdx: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.
Software Programs: Part A 1. Design and Develop An Assembly Language Program To Search A Key Element "X" in A List of N' 16-Bit Numbers. Adopt Binary Search Algorithm in Your Program For Searching