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

MPL EXP5

The document outlines Experiment No. 5, which involves writing an assembly language program to reverse the string 'Was it a car or a cat I saw?'. It includes the aim, theory, algorithm, program code, and conclusions regarding the implementation of stack operations for string manipulation. Additionally, it contains questions and answers related to interrupts in the 8086 microprocessor.

Uploaded by

saiesh.232793105
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

MPL EXP5

The document outlines Experiment No. 5, which involves writing an assembly language program to reverse the string 'Was it a car or a cat I saw?'. It includes the aim, theory, algorithm, program code, and conclusions regarding the implementation of stack operations for string manipulation. Additionally, it contains questions and answers related to interrupts in the 8086 microprocessor.

Uploaded by

saiesh.232793105
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Experiment No.

5
ALP to reverse a given string “Was it a car or a cat I saw?”.
Date of Performance: 20/02/2025
Date of Submission: 06/03/2025

CSL404: Microprocessor Lab


Experiment No. -5

Aim:

Write an ALP to reverse a given string “Was it a car or a cat I saw?”.


Objective:

To emphasize on instruction set and logic to build assembly language programs to reverse a
given string.
Theory:

To find the reverse, we just copy the string from one memory location to another in reverse
order and display it. First copy the first two bytes of the string array as it is in the new string,
since they remain same for the reversed string. Then position the SI pointer to the end of the
given string and copy character by character in the new string in reverse order. Finally, the
new string is displayed, which is the reverse of the original string.

Algorithm:

1. Start
2. Initialize the data segment
3. Display message-1
4. Input the string
5. Display message-1
6. Take character count in DI
7. Point to the end character and read it
8. Display the character
9. Decrement the count
10. Repeat until count is zero
11. To terminate the program, using DOS interrupt
a. Initialize AH with 4CH
b. Call interrupt INT 21H
12. Stop

CSL404: Microprocessor Lab


Program:

.model small
.stack 100h
.data
string db 'Was it a car or a cat I saw?'

.code
main proc
mov ax,@data
mov ds,ax
mov si,offset string
mov cx,40

l1:
mov bx,[si]
push bx
inc si
loop l1
mov cx,40

l2:
pop dx
mov ah,2
int 21h
loop l2

mov ah,4ch
int 21h
main endp
end main

CSL404: Microprocessor Lab


Output:
Before:

After:

CSL404: Microprocessor Lab


Conclusion:

In this experiment, we successfully implemented an assembly language program to reverse a


given string using stack operations. By pushing each character onto the stack and then
popping them in reverse order, we achieved the desired output. This experiment reinforced
key assembly language concepts such as memory addressing, loop execution, and DOS
interrupts for character display. It highlighted the efficiency of stack-based operations in
string manipulation and deepened our understanding of low-level programming techniques.

CSL404: Microprocessor Lab


Questions:

1. Explain the difference between maskable and non-maskable interrupts in the 8086
microprocessor. Provide examples of each.
Ans:

2. What is the function of the interrupt vector table (IVT) in the 8086 microprocessor? How
are interrupts handled using IVT?
Ans: The Interrupt Vector Table (IVT) in the 8086 microprocessor is a memory table located
at 0000H–03FFH that stores the addresses of interrupt service routines (ISRs) for various
interrupts. Each interrupt has a 4-byte entry (2-byte segment and 2-byte offset). When an
interrupt occurs, the CPU retrieves the corresponding ISR address from the IVT and jumps to
it for execution. This mechanism ensures efficient interrupt handling for hardware (e.g.,
timer, keyboard) and software interrupts.

CSL404: Microprocessor Lab


3. Describe the role of the INT 21H interrupt in MS-DOS. Give an example of its usage.
Ans: The INT 21H interrupt in MS-DOS provides various system services, including file
handling, input/output operations, and memory management. It acts as an interface between
programs and the operating system. Different functions are accessed by setting the AH
register with a specific value before calling INT 21H.
Eg. To print something on screen
mov ah, 09h
mov dx, offset msg
Int 21h
msg DB 'Hello, DOS!$'

4. Explain how the INT 0 (Divide Error) and INT 4 (Overflow) interrupts work in 8086. Provide
real-time applications where these interrupts are useful.
Ans: In the 8086 microprocessor, INT 0 (Divide Error) occurs when a division operation
results in a quotient too large to fit in the destination register or when attempting to divide
by zero. This interrupt halts execution or invokes an exception handler to prevent system
crashes. Similarly, INT 4 (Overflow) is triggered when an arithmetic operation sets the
Overflow Flag (OF), indicating that the result exceeds the allowed range. The INTO
instruction checks and calls INT 4 if overflow occurs. These interrupts are crucial in real-time
applications such as financial calculations, where division errors must be handled gracefully,
and sensor-based systems, where detecting arithmetic overflow ensures data integrity in
real-time signal processing.

CSL404: Microprocessor Lab

You might also like