Writing Programs with Echo (DOS)
May 4th, 2008 | Published in Assembler, Debug, Languages, Programming, Retro | 6 Comments
Is that possible? Yes, it is. It's just a matter of redirecting echo output to a file. Writing the program with echo should be a straightforward task if we are able to produce the sequence of characters corresponding to the intended binary, executable file. Is that useful? Surely not. But it's a healthy way to waste your time
As suggested by a reader, this can be achieved by writing the characters of the executable file, using a simple text editor like notepad or even the old MS-DOS Editor. Of course, the program should be relatively small or we would adventure into the dangerous lands of masochism. By using the echo command of DOS we will be following the conceited style of doing things
But we'll restrict this post to the simple hello, world! program we have been reviewing in previous entries.
The hexadecimal code of our program is:
EB 12 0D 0A 68 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D 0A 24 B4 09 BA 02 01 CD 21 B4 00 CD 21 0D
Now, we only have to input and redirect these hexadecimal values to a file, that we'll name hello.com.
That would be fairly easy except for some values such as 00 and 09, which represent the NULL and TAB characters, respectively. How do you input those characters as parameters for the echo command? I found no way of doing that. If you know a way, please drop me a line. Therefore, I changed the code of the program in two ways:
- The
09character comes from the instructionmov ah,9. I replaced that by two instructions:mov ah,7andadd ah,2. The semantic stays intact, but the contrived approach allows us to discard the 09 character. - Regarding the NULL character (
00), it's a consequence of the linemov ah,00. But we can accomplish the effect of clearingahby executingxor ax,axinstead. And that's it.
Take a look at the complete command I used:

Nice

May 6th, 2008at 5:26 pm(#)
[...] [...]
May 9th, 2008at 8:21 pm(#)
wow, this is more advanced and well, WEIRD!
lol
May 9th, 2008at 11:30 pm(#)
I did not understand… what’s this for?
May 10th, 2008at 12:32 am(#)
Crazy
May 10th, 2008at 9:53 am(#)
mmmm… are you sure it’s not possible to input a 00 character in a file? There has to be way… without editing the file directly, of course
we can simply open the file in a hexadecimal editor and input the zero, but that’s not what you are trying to do…
May 11th, 2008at 11:46 pm(#)
[...] Later, we encoded such program directly in hexadecimal (no need for DEBUG). And finally, we abused the MS-DOS ECHO command to create a binary, executable hello, world! program directly from the DOS command line (again no [...]