Chapter 13 - 16-bit MS-DOS Programming

We are now going into Real-address mode programs which have the following characteristics:

Let's look at the memory map on p. 459.

Interrupt - is an external request for service. In particular, an interrupt causes the microprocessor to stop executing the current procedure (saving the status) and continue on with the routine specified by the interrupt. When the interrupt has been fully serviced, control returns to the previously executing routine.

Two types of interrupts exist:
1) maskable - depending on the status of the interrupt flag, this interrupt can be ignored by the hardware.
2) nonmaskable - must be acknowledged by the hardware independent of the interrupt flag.

Remember, we are discussing interrupts in terms of the Real-address Mode. An interrupt has an integer in the range 0-255 associated with it. This integer is called the interrupt type. The addresses from 00000 to 003ff (0 to 1024) are reserved for interrupt vectors. An interrupt vector is an address (segment & offset) of a particular interrupt service routine.

Interrupt Vector Type		Stored At
0				00000:00003
1				00004:00007
....
t				4t   : 4t+3

We see that each interrupt vector requires four bytes. The first two bytes contain the offset (bytes reversed). The next two bytes contain the segment (bytes reversed).

How do interrupts work?

The answer to this question lies in the fact that at the end of most instructions, the microprocessor checks for any pending interrupt requests. If an interrupt is detected by the hardware, the following occurs:

1) Push the flags register on the stack (why?)
2) Clear the interrupt and trap flags (why?)
3) Push CS
4) Determine the interrupt location based on the type
5) CS = second word of the interrupt vector
6) Push IP
7) IP = first word of the interrupt vector

When the interrupt routine has completed, the IRET instruction is used to transfer control back to the caller. The general form is:

(i77) [<label>] IRET

Software Interrupt - is an OS procedure call most of which provide I/O capability to applications. The following instruction is used to call a software interrupt.

(i78)[<label>] INT <int-type> (where int-type is an integer in the range of 0 to 255.

Internal interrupts are examples of nonmaskable interrupts meaning the IF flag does not affect whether the interrupt is taken or not.

Discuss Common interrupts on pp.462.

Let's take a look at the Hello World program from Assembly Language for Intel-based computers:

TITLE Hello World

.model small
.stack 100h
.386

.data
message BYTE "Hello, world!",0dh,0ah

.code
main PROC
     mov ax,@data
     mov ds,ax
     mov ah,40h
     mov bx,1
     mov cx, SIZEOF message
     mov dx, OFFSET message
     int 21h
     .exit
main ENDP
END  main
P#1: There are no instructions that directly manipulate the TF bit in the flags register. If the TF bit is set, then the microprocessor goes into single step mode. Write an assembly language program segment that will place the microprocessor in single step mode by setting the TF bit without modifying any other bits in the flags register.


© Douglas J. Ryan ryandj@pacificu.edu