2. Print 'Hello'

Back Home Up Next

Okay, we've tried to create a basic, do-nothing program in a number of ways. Before we get more into the details of exactly what a program actually is, differences between .COM and .EXE programs, etc., let's extend the program to actually get something to happen that we can see. Like before, I'll take you through several different ways. It's handy to be skilled with a few, just in case.

Using DEBUG

Here's the second program built with DEBUG:

C>debug «
-a «
102D:0100 mov dx, 10b
102D:0103 mov ah, 9
102D:0105 int 21
102D:0107 mov ah, 4c
102D:0109 int 21
102D:010B db "Hello out there!", 0d, 0a, '$'
102D:011E «
-r cx «
CX 0000
:1e «
-n lesson02.com «
-w «
Writing 0001E bytes
-q «

C>

This program is quite similar to the first one, except that we've inserted three other assembler instructions at the beginning and added one at the end. These are designed to actually display a message on the screen when the program runs. Try it out by running lesson02:

C>lesson02 «
Hello out there!

C>

To appreciate exactly how this program works, you'll need to refer to the DOS reference manual mentioned on the previous page under Function 09h. I'll provide a copy of that page below.

Using GRDB

Here's the second program built with GRDB:

C>grdb «

Get Real Debugger Version 6.8  Copyright (c) 1997-2004 David Lindauer (LADSoft)
GRDB comes with ABSOLUTELY NO WARRANTY, for details type `?g'
This is free software, and you are welcome to redistribute it
under certain conditions; type `?gr' for details

History enabled
eax:00000000 ebx:00000000 ecx:00000000 edx:00000000 esi:00000000 edi:00000000
ebp:00000000 esp:0000FFEE eip:00000100 flag:00000202 NV UP EI PL NZ NA PO NC
ds:183F es:183F fs:183F gs:183F ss:183F cs:183F
183F:0100 B4 4C          mov          ah,004C

->a «
183F:0100  mov dx, 10b
183F:0103  mov ah, 9
183F:0105  int 21
183F:0107  mov ah, 4c
183F:0109  int 21
183F:010B  db "Hello out there!", 0d, 0a, '$'
183F:011E  «
->w @cs:0100 lesson02.com,1e «
->q «
C>

Again, the result will be a program in your directory called lesson02.com. Try and run it:

C>lesson02 «
Hello out there!

C>

This is just the same as with DEBUG.

Using ML

Now, let's try building this second program using Microsoft's ML.EXE assembler and LINK.EXE linker:

C>copy con: lesson02.asm «
.model tiny «
.code «
.startup «
mov dx, OFFSET msg «
mov ah, 9 «
int 21h «
.exit «
.data «
msg DB "Hello out there!", 13, 10, '$' «
end «
^Z
        1 file(s) copied

C>

Again, note that the last entered line shown above is really a control-Z and that it ends your input to the file. At this point, you now have an assembler source code file called lesson02.asm in your current file directory.

Now, to assemble this file:

C>ml /Fl /Sa lesson02.asm «
Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

 Assembling: lesson02.asm

Microsoft (R) Segmented Executable Linker  Version 5.60.339 Dec  5 1994
Copyright (C) Microsoft Corp 1984-1993.  All rights reserved.

Object Modules [.obj]: lesson02.obj /t
Run File [lesson01.com]: "lesson02.com"
List File [nul.map]: NUL
Libraries [.lib]:
Definitions File [nul.def]:

C>

We'll come back later and discuss the differences between the assembler syntax and the debugger syntax. For now, it's enough to know that they produce similar programs. (If you are observant and look at the size of lesson02.com in the directory and compare the size with the same program generated using DEBUG or GRDB. The program generated using ML will be one byte longer. This is due to a "segment alignment" issue, but it doesn't result in any important difference.)

What Does It All Mean?

In this second example program, we make another function call to DOS, namely Function 09h. Let's look at the documentation from the technical reference for DOS programmers mentioned at the top of my PC Docs web page:

09H -- Display String

Purpose
        Sends the characters in the string to the standard output device.

Examples

            MOV AX,SEG String
            MOV DS,AX          ; Set DS:DX to string
            MOV DX,OFFSET String
            MOV AH,09H         ; Function Call - Display String
            INT 21H            ; Issue request to DOS
     ----
     String DB "This string ends at the first Dollar"
            DB 0DH,0AH
            DB "$"

Comments

        The character string in memory must be terminated by a $ (24H).
        Each character in the string is output to the standard output
        device in the same form as function call 02H. ASCII codes 0DH
        and 0AH represent carriage return and line feed, respectively.

In .COM files, there's no need to perform the first two instructions mentioned in the example, here. This is because DS is already set to the right value.

I hope you had good luck getting all this to work out on this second program!

 

Last updated: Wednesday, July 07, 2004 11:38