0% found this document useful (0 votes)
4 views

Lab Report 2

Uploaded by

21225103141
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab Report 2

Uploaded by

21225103141
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

LAB REPORT

Course Title: Microprocessor and Microcontroller


Course Code: CSE 316
Lab Report No.: 02

Submitted by:

Ahnaf Abid Tawsif

Student ID: 22234103021

Intake: 49

Section:50/

Submitted

To:

Joyita Halder, Lecturer, CSE,

Bangladesh University of Business and Technology


Date : November 20, 2024
Objective:

The objective of this lab is to write a simple assembly program


that reads a single character from the keyboard and echoes it
back to the screen using DOS interrupts. This demonstrates
basic user input and output in assembly programming,
focusing on how interrupts are used to interact with the
system.

Materials:

● Assembler: EMU8086 Emulator/Assembler (or compatible


IDE for 16-bit x86 assembly)
● Environment: EMU8086, which simulates a DOS-like
environment for running 16-bit assembly programs
● Hardware/Software Requirements: A computer with
EMU8086 or similar emulator installed

Introduction:

In assembly programming, interacting with the keyboard and


displaying output to the screen can be done through DOS
interrupts, particularly INT 21h. This interrupt is a powerful tool
that allows the programmer to access many different operating
system services, such as reading from the keyboard or writing
to the console. In this program, we'll use INT 21h to perform
two basic operations:

1. Reading a character from the keyboard (function 1, AH =


1).
2. Displaying the character on the screen (function 2, AH = 2).

The program will be executed within the EMU8086


environment, which is a DOS-compatible emulator for
running 16-bit assembly code.

Task 1 :
1. MOV AH,1
○ This instruction sets the AH register to 1, which tells
the DOS interrupt INT 21h to use the "Read a
character from standard input" function.
○ The AL register will store the ASCII value of the key
pressed by the user.
2. INT 21h
○ This call invokes DOS interrupt 21h to read a single
character from the keyboard.
○ The result is stored in the AL register.
3. MOV DL,AL
○ After the key is pressed, the ASCII value of the
character is stored in the AL register.
○ This value is then moved to the DL register in
preparation for output, as INT 21h function 2
requires the character to be in the DL register.
4. MOV AH,2
○ This instruction sets the AH register to 2, which
specifies the DOS interrupt function to display a
character on the screen.
○ The character to be displayed is in the DL register.
5. INT 21h
○ The second call to DOS interrupt 21h is made
to output the character stored in DL to the
console.

Output:(without any space or newline)


Task 2:
Read a character from the
keyboard. Print a newline
Echo the character back to the screen.
1. MOV AH,1
○ This instruction sets the AH register to 1, telling DOS
interrupt 21h to read a character from the keyboard.
○ The character pressed by the user will be stored in the
AL register.
2. INT 21h
○ This is the DOS interrupt call that reads the
character from the user and stores its ASCII value in
the AL register.
3. MOV CL,AL
○ The value of the character in AL is moved into CL (a
general-purpose register) for later use. The character
will be echoed back to the screen later, so it's saved
in CL.
4. MOV AH,2
○ This sets AH to 2, specifying the DOS interrupt
function to display a single character on the screen.
5. MOV DL,10
○ The value 10 is the ASCII code for Line Feed (LF).
This character is used to create a new line in the
terminal. It is loaded into DL, which is the register
for the character to be printed.
6. INT 21h
○ This call outputs the Line Feed (LF) character,
creating a new line on the screen.
7. MOV DL,13
○ The value 13 is the ASCII code for Carriage
Return (CR). This character moves the cursor
back to the beginning of the line.
8. INT 21h
○ This call outputs the Carriage Return (CR)
character, which resets the cursor to the beginning
of the line.
9. MOV DL,CL
○ The stored character (from CL) is now moved into
DL, preparing it for output.
10.INT 21h
○ This final call displays the character (stored in DL) on
the screen.

Output:
Task 3:
Displays a prompt message asking the user to input
a number. Reads a single numeric character from the
user.
Displays a message with the input number echoed back to the
user.

MOV AX,@DATA and MOV DS,AX

● These instructions initialize the data segment (DS) by


loading the address of the data segment (@DATA) into
the AX register and then copying it
into the DS register. This is necessary to access data stored
in the .data section.

MOV AH,9 and INT 21h

● This sets up the DOS interrupt to display a string.


● The AH register is set to 9, which tells the DOS interrupt
21h to print a null-terminated string located at the
address in DX.
● LEA DX, string1 loads the address of the first
string ('Input first number:$') into DX.

MOV AH,1 and INT 21h

● This sets AH to 1, which specifies the read a single


character function.
● When INT 21h is called, it waits for the user to input a
single character. The character will be returned in the
AL register.

MOV CL,AL

● The character entered by the user is stored in the AL


register by the previous interrupt. This instruction
moves the value of AL into CL, so that the character
can be reused later.

MOV AH,2 and INT 21h (for Line Feed and Carriage Return)

● MOV DL,10 and MOV DL,13 prepare for line formatting


by setting DL to 10 (Line Feed) and 13 (Carriage Return),
respectively.
● These values create a new line after

the user input. Displaying the Second String:

● After the line break, the program displays the second


message: 'Your number is:$'. This is done with the same
process used for displaying the first string.

Echoing the Input:

● The final step is to echo the input back to the user. The
value stored in CL is moved to DL and then displayed
using the interrupt INT 21h with AH set to 2, which
outputs the character to the screen.
Output:

Conclusion:

The assembly program successfully demonstrates how to read


a single numeric character from the user, display messages
using DOS interrupt 21h, and echo the input back to the user
with proper formatting. This program is an excellent
introduction to using strings, handling user input, and
managing formatted output in assembly language.

You might also like