Discovery Zone: Keeping Knowledge Free!
Search:
Keywords:
In Association with Amazon.com
Another great reference
cover 80X86 IBM PC and Compatible Computers: Assembly Language, Design and Interfacing Vol. I and II

ASSEMBLY PROGRAMMING AND OS DESIGN


2. Intro to Assembly
2.1 Data Types
2.2 Registers
2.3 DOS Int Calls
2.4 Basic Commands
2.4.1 DOS Hello World
2.5 BIOS Int Calls
2.5.1 BIOS Hello World
2.6 String Routines

<HOME>

 

 

 

 

Need a good reference?
cover
Assembly Language Step-by-Step: Programming with DOS and Linux, 2nd Edition

 

 

 

CH2.3 DOS Int Calls

<HOME><TOC><PREV><UP><NEXT>

The main call we will be concerned with for now is the DOS interrupt call of 21h. A call to this interrupt would look like:

              int    21h

This will transfer control of the computer to DOS in order for DOS to perform some useful task for us. In this case, we simply want DOS to return to the command prompt when we are done running our code. In order to do this, we must tell int 21h that is what we want. This is done by passing it a function number. The function number is passed in the high byte of AX which is AH. The function number for this task is 4ch. Don't worry about remembering this. You will see and use this so many times that you will not be able to forget it.

Let's look at example 1 again, except this time it will be a complete program that we can type in, compile, and execute.

Ex. 4

              org    100h
              mov    AX,2   ;move the number 2 into AX
              add    AX,2   ;add 2 to AX and store the result in AX

              mov    AH,4Ch ;function 4Ch will return us to the DOS prompt
              int    21h    ;call the function


Before you read any further, type in this code and call it ex4.asm. Compile it using the command line NASMW -o ex4.exe ex4.asm. This will compile your code and produce the executable ex4.exe. When you run the executable, it will seem like nothing happened. Although, with a closer look, you will realize that your program was not designed to produce any output and returned to the prompt as designed.

Now let's print something to the screen.

int 21h function 02h will output a character to the standard output which is by default the display screen.  AH contains the function number 02h and DL is the character you want to display.

Ex. 5

              org    100h
              mov    DL,'H' ;DL holds the letter to output
              mov    AH,02h ;function 02h
              int    21h
              mov    DL,'e'
              mov    AH,02h
              int    21h
              mov    DL,'l'
              mov    AH,02h
              int    21h
              mov    DL,'l'
              mov    AH,02h
              int    21h
              mov    DL,'o'
              mov    AH,02h
              int    21h
              mov    DL,' '
              mov    AH,02h
              int    21h
              mov    DL,'W'
              mov    AH,02h
              int    21h
              mov    DL,'o'
              mov    AH,02h
              int    21h
              mov    DL,'r'
              mov    AH,02h
              int    21h
              mov    DL,'l'
              mov    AH,02h
              int    21h
              mov    DL,'d'
              mov    AH,02h
              int    21h

              mov    AH,4Ch ;return to DOS prompt
              int    21h

The code can be compiled using NASMW -o ex5.exe ex5.asm.  Obviously this is a very painful way to write Hello World.  Lets start looking into the basic commands available to us to make this easier.

<HOME><TOC><PREV><UP><NEXT>
 

www.cynergysoft.com

Email any questions to the author, Nathan Daniels.

Copyright © 2001