MPL EXP5
MPL EXP5
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
Aim:
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
.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
After:
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.
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.