Edit
an existing COM file
Create
the
Editing.Com
program
file with the Batch Stream
This exercise uses the
same procedute as the last exercise, to illustrate the assembly
function of Debug.
The Floppy Disk must already contain the following files.
Command.com
Debug.exe
Caller.bat
If these files are not already on the Floppy Disk, then use the
previous exercises to aquire them.
In this example, we will
create another Com file named Editing.Com.
on the Floppy Disk.
Copy the text below, into a file named Ediging.Txt
on the Floppy Disk.
a
mov ah,9
mov dx,010c
int 21
int 20
nop
nop
nop
nop
e 010c 0a 0d "__Hello__World_" 0A 0D
"$ "
n A:Editing.com
rcx
0030
w
q
Because of the previous presentation, the sequence of events in this
example should be clear. If a reminder is helpful, then preview the Summary section
at the end of this example. Otherwise, continue here.
Assemble
the new file named Editor.Com
Double click on Command.com
to open the DOS
Prompt program.
On prompt, type Caller
editor.txt to call the text file commands into Debug.
It will result in a file named Editor.Com
on the Floppy Disk.
This is the display that will be in the DOS prompt console window after
executing Caller.BAT......
A:\>a:debug.exe 0<a:Editing.bat
-a
0AEE:0100 mov ah,9
0AEE:0102 mov dx,010c
0AEE:0105 int 21
0AEE:0107 int 20
0AEE:0109 nop
0AEE:010A nop
0AEE:010B nop
0AEE:010C nop
0AEE:010D
-e 010c 0a 0d "__Hello__World_" 0A
0D "$ "
-
-n A:Editing.com
-rcx
CX 0000
:0030
-
-w
Writing 00030 bytes
-q
A:\>pause
Press any key to continue . . .
Testing
the
new
Editing.Com
program
If you have terminated the Command.Com
Interpreter program, then re-open the Dos Prompt program.
Type Editing
at the DOS Prompt.
Editing.Com
will execute and display the message into the Dos Prompt console window.
Many of the Debug programs
editing features are given below. It is suggested that a hare copy of
this example be used to play around with the editing commands. It will
take some time for the "fat finger" exercises below to become second
nature. When they do, editing will become very easy and you will find
yourself thinking with your finger tips. It becomes very easy to try
different things until you are satisfied with the way your program
functions.
Editing
the
existing
Editing.Com
file
No Batch string will be given for the editing exercise. It is something
that need be done from the keyboard.
On the floppy, click on Command.Com to open the DOS PROMPT command line
mode.
Microsoft(R)
Windows
DOS
(C)Copyright Microsoft Corp 1990-2001.
A:\>
Type in Debug on the prompt to run the Debug program.
Microsoft(R) Windows DOS
(C)Copyright Microsoft Corp
1990-2001.
A:\>debug
-
Name the file to be edited with the N instruction (at the Debug prompt,
a minus sign).
Load the file to be edited with the L instruction (both
lines followed with ENTER).
Microsoft(R)
Windows
DOS
(C)Copyright
Microsoft
Corp
1990-2001.
A:\>debug
-n editing.com
-l
-
To display the program, use the U instruction to un-assemble the
program.
0C58:0100
B409
MOV AH,09
0C58:0102
BA0C01
MOV DX,010C
0C58:0105
CD21
INT 21
0C58:0107
CD20
INT 20
0C58:0109
90 NOP
0C58:010A
90 NOP
0C58:010B
90 NOP
0C58:010C
0A0D
OR CL,[DI]
0C58:010E
5F
POP DI
0C58:010F
5F
POP DI
0C58:0110
48
DEC AX
0C58:0111
65
DB 65
0C58:0112
6C
DB 6C
0C58:0113
6C
DB 6C
0C58:0114
6F
DB 6F
0C58:0115
5F
POP DI
0C58:0116
5F
POP DI
0C58:0117
57
PUSH DI
0C58:0118
6F
DB 6F
0C58:0119
726C
JB 0187
0C58:011B
64
DB 64
0C58:011C
5F
POP DI
0C58:011D
0A0D
OR CL,[DI]
0C58:011F
2420
AND AL,20
-
The
first
instruction
loads the AH register with the interrupts 21s sub
function O9, Write a line of text to the monitor.
The second line loads the DX register with the location of the text to
be posted.
The Interrupt 21 instruction posts the message located at O1OC in this
example.
The last instruction to be executed is an Interrupt 21 that returns the
program to the program that called it.
The No Ops at location O1O9 through O1OB are only because I like to
leave space for editing later.
The next line at location O1OC is
ascii numbers for the text to be printed. Hard to read with an assembly
language display.
The first two bytes are OA OD , line feed and carriage return. The 5F
is an underscore.
Location O11F is a dollar sign, used as a delimiter and declares the
end of the line to be posted.
Memory
Dump
will
display the program using the D instruction.
-d 0100
0C58:0100 B4 09 BA 0C 01
CD 21 CD-20 90 90 90 0A 0D 5F 5F ......!. .....__
0C58:0110 48 65 6C 6C 6F
5F 5F 57-6F 72 6C 64 5F 0A 0D 24 Hello__World_..$
0C58:0120 20 20 20 20 20
20 20 74-E4 73 06 E8 7F DB E9
AD t.s......
0C58:0130 1B 2E 88 07 3C
3D 75 06-2E 80 0E A2 90 01 43 E8 ....<=u.......C.
0C58:0140 08 0A 73 C5 AC
2E 88 07-43 EB BE 4E 2E 89 36 98 ..s.....C..N..6.
0C58:0150 90 2E C6 07 00
2E 89 1E-A7 90 26 8B 1D 8D 36 AB ..........&...6.
0C58:0160 90 2E 80 3C 2F
74 36 2E-80 3C 22 74 08 2E F6 06 ...</t6..<"t....
0C58:0170 A2 90 01 75 54
26 8A 47-01 32 E4 2E 39 06 94 90 ...uT&.G.2..9...
The machine code from location 0100 to 010B is harder to read than the
pseudo code, but it is here.
The remaining text is still difficult to see win the Hex display, but
easy to read in the ascii display.
Any non printable ascii character in the ascii display is displayed as
a dot.
The text in the message is easy to read, from location 010C through
location 011C.
Line feed, carriage returns are ascii 0A 0D,
The delimiter , $ is the ascii hexidecimal 24, and is not posted in the
message.
The remaining code is random, resulting from the d function specifying
only the first location.
Defining both the first and last location is sometimes easier to
display the range of bytes of interest.
-d 0100 011f
0C58:0100 B4 09 BA 0C 01 CD 21 CD-20 90 90 90 0A 0D 5F
5F ......!. .....__
0C58:0110 48 65 6C 6C 6F 5F 5F 57-6F 72 6C 64 5F 0A 0D
24 Hello__World_..$
Testing the program can be done any time with the G= function with
program start specified.
It will provide a preview of what the program will do after it has been
saved to a Com file.
- g=0100
__Hello__World_
Program terminated normally
Editing the assembled machine code has already been covered in the A
function example.
The characters to be printed out can be edited easily with the E
function as well.
Enter E followed by the location of the bytes to be inserted into
program memory.
Hex numbers can be entered directly but text must be within quotation
marks.
-
-e 0110 "New
message" 0a 0d "$"
-d 0100 011f
0C58:0100 B4 09 BA 0C 01 CD 21 CD-20 90 90 90 0A 0D 5F
5F ......!. .....__
0C58:0110 4E 65 77 20 6D 65 73 73-61 67 65 0A 0D 24 67
65 New message..$ge
-g=0100
__New message
Program terminated normally
-
The example above has edited the text in the message, dumped the
program and run it.
When satisfied with the editing session, name it with the N function,
calculate its length with the H function and
write it out to the disk as a COM file with the W function and quit.
There are
many DOS interrupts that are available that can do anything that DOS
can do. Interrupts functions begin at INT 00 for Drivers, INT 01 for
Med, and so on through INT 67 and there are 108 sub functions for INT
21 alone. A good source of the software interrupts is availabl on the
web. Google Ralph's Interrupts or visit the Usefull Links section of
this tutorial. There are a wealth of programs that can be found with a
web search. A few more examples will also be given in this tutorial.
SUMMARY
This exercise is intended to
provide instructions to create an executable file that will run under
the Disc Operating System Using the DEBUG.exe program to create a
program file named Editing.Com. This program will present a message to
the DOS monitor in the DOS PROMPT mode. The basic programs needed are
copied onto the floppy disk to simplify the final location of these
files on the disks.
The most straignt forward method would be to enter the Dos Prompt mode
by calling Command.com from the floppy disk by executing.
command
While in the DOS mode, call the Debug.exe program by calling the
Debug program.
debug
While in the Debug program, type in the characters necessary to create
the Editor.Com program, subsequently closing Debug and returning to
Command.Com, the DOS PROMPT program.
The final product will be a new file on the floppy disk named
Editor.Com.
This program may be run while still in the DOS mode by calling it by
name.
Editing
The message will be presented to the monitor followed by a prompt to
execue the next DOS instruction.
TASK COMPLETE
A second method is to commit the text necessary for Debug into a plain
text file. We use the example text and put it into a file named
EDITOR.COM ; however any file name would work as well for this method.
From the floppy disk, in Windows we again call Command.Com with a
double click on its icon, or naming it with the START-RUN function
editor box.
command
In DOS PROMPT, on the DOS prompt, we call the Debug program,
redirecting the text file that we named Editor.bat....
debug
< editor.bat
The Editor.Com file is created as in the first method; however, we have
saved ourselves the need to type in the Debug commands.
A third method further automates the process. In older DOS systems, it
would only be necessary to call Editor.bat from the DOS prompt;
however, in the XP system it is necessary to call it with another batch
program that we named Caller.bat. We are able to do this same task by
executing the caller.bat program by clicking on its icon in the Window
tradition. The BATCH command named PROMPT further permits is to see the
keystrokes that are used in the Debug program for illustration purposes
and to return program execution to the Windows system on completion.
Whichever method is used, the final result will be a COM program that
will perform a set of DOS instructions using Debug.exe......