China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-27 09:54
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Messing Around with DEBUG! View 1,325 Replies 0
Original Poster Posted 2003-06-05 00:00 ·  中国 北京 东城区 联通
初级用户
Credits 105
Posts 1
Joined 2003-06-05 00:00
23-year member
UID 3756
Gender Male
Status Offline
I read a few posts on the forum about DEBUG, and I also wanted to mess around with DEBUG. It's a long story. DEBUG is really ancient, but if you use it well, it can be very powerful.
A few days ago SARS was going around, and I was afraid of being quarantined, so I ran back home. For a person like me who doesn't even want to live without a computer, how could I possibly stay home for long? So I tried every possible way to borrow a computer. This computer seemed even older than DEBUG. Not only did it have no CD-ROM drive, even the floppy drive was broken. I couldn't install any software at all. It didn't even have the most basic QBASIC. But after checking with DIR, there was still a DEBUG. Fine, I'd use it to write assembly. But it only supports basic assembly. After each press of Enter, the assembly is compiled into instructions right away, which makes it hard to modify. There aren't even labels, only addresses. Every time after finishing, I had to write down the jump addresses from the assembled program, then rewrite it all over again. Too tiring. So I thought of a method: first write the program with software like EDIT, then pass it to debug with DOS commands, put the output into a file, then modify the jump addresses in the source program, and then assemble it again, and it's OK!
Talking without doing won't do, so here's an example:
c:\>edit x.txt
Enter EDIT and edit x.txt
a
mov ah,9
mov dx,100
int 21h
int 20h
db 'Hello','$'

n x.com
rcx
20
w
q
Note that there must be a carriage return before n x.com above! Anyone who knows assembly knows this is a program that outputs a string, but before designing it it's hard to calculate the string address, so in DX I just randomly set it to 100, then execute the following command:
c:\>debug out.txt
After this command finishes, there will be an out.txt
-a

0BD4:0100 mov ah,9

0BD4:0102 mov dx,100

0BD4:0105 int 21

0BD4:0107 int 20

0BD4:0109 db 'Hello','$'

0BD4:010F

-n x.com

-rcx

CX 0000
:20

-w

Writing 00020 bytes
-q
We can see that the string address is 0109, so the value in DX must also be 0109. This program is F bytes long, so the line under RCX should not be 20, it should be F. This way, with just two passes you can generate an X.com.
I wonder whether any forum friends have an even better method than this? Say it out, and let's improve together!
Forum Jump: