Function of INT

Ok, as promised before, I'll explain about the INT in this post. So, check it out and understand it cause this will be used a lot in your programme you write.


Examples:
INT 21h ;calls DOS standard interrupt # 21h
INT 10h ;the Video BIOS interrupt..

INT is used to call a subroutine that performs some function that you'd rather not write yourself. For instance, you would use a DOS interrupt to OPEN a file. You would similiarly use the Video BIOS interrupt to set the screen mode, move the cursor, or to do any other function that would be difficult to program.

Which subroutine the interrupt preforms is USUALLY specified by AH. For instance, if you wanted to print a message to the screen you'd use INT 21h, subfunction 9 by doing this:

mov ah,9
int 21h

Yes, it's that easy. Of course, for that function to do anything, you need to specify WHAT to print. That function requires that you have DS:DX be a FAR pointer that points to the string to display. This string must terminate with a dollar sign. Here's an example:

MyMessage db "This is a message!$"
...
mov dx,OFFSET MyMessage
mov ax,SEG MyMessage
mov ds,ax
mov ah,9
int 21h
.....

The DB, like the DW (and DD) merely declares the type of a piece of data.

DB => Declare Byte (I think of it as 'Data Byte')
DW => Declare Word
DD => Declare Dword

Also, you may have noticed that I first put the segment value into AX and then put it into DS. I did that because the 80x86 does NOT allow you to put an immediate value into a segment register. You can, however, pop stuff into a Segment register or mov an indexed value into the segment register. A few examples:

LEGAL:
mov ax,SEG MyMessage
mov ds,ax

push SEG Message
pop ds

mov ds,[SegOfMyMessage]
;where [SegOfMyMessage] has already been loaded with
; the SEGMENT that MyMessage resides in


ILLEGAL:
mov ds,10
mov ds,SEG MyMessage

Well, that's about it for what you need to know to get started...

And here I also want you to understand how to use the goodies I give you in the last post that is Turbo Assembler. Here some example:

;===========-

DOSSEG ;This arranges the segments in order according DOS standards
;CODE, DATA, STACK
.MODEL SMALL ;dont worry about this yet
.STACK 200h ;tells the compiler to put in a 200h byte stack
.CODE ;starts code segment

ASSUME CS:@CODE, DS:@CODE

START: ;generally a good name to use as an entry point

mov ax,4c00h
int 21h

END START

;===========- By the way, a semicolon means the start of a comment.

If you were to enter this program and TASM & TLINK it, it would execute perfectly. It will do absolutly nothing, but it will do it well.

What it does:
Upon execution, it will jump to START. move 4c00h into AX, and call the DOS interrupt, which exits back to DOS.

That's nice, eh? If you've understood the majority of what was presented in the post before this, you are ready to start programming!

No comments: