Microsoft DOS has declined but to review those knowledge of writing DOS programs (starting from the simplest .COM binary) can help us learn better how computers work in the low level aspect. Previous articles [here] and [here] describe the experiments using DOSBox to write .COM programs using debug.exe
Today, we are going to explore a little bit more. We will show you how to print 26 upper case letters in using .COM assembly in just 15 bytes! Through this tutorial, you will learn how to use the powerful tool debug.exe to write assembly steps by steps. Also, you will be familiar with the simplest loop statement for creating an iteration.
Start from the shell prompt C:\ or anywhere as long as the PATH variable stores the correct path to look for the file debug.exe.
Type debug letters.com and this will give a message that the file does not exist. If it does exist, it will load the program into 0x100 location (the first 256 bytes stores the Program Segement Prefix, that is a data structure to represent the state of a program).
We use command n to set the filename for writing later with the command w. Then we can use a 100 to start writing assembly at address 100.
After we finish the program, we can press Enter twice that will return to the command mode of debug.exe. We can then use r cx to write value to the register CX that stores the length of code to write. Finally, the command w writes the code to disk (prior to this, n and r cx should be in place).
The source code is just 15 bytes, a few lines only and it iterates printing the upper case letter (starting with ‘A’, ASCII = 65, hexadecimal is 41h) then each iteration, increase the character by one and print it. After 26 times, the program terminates by using int 20h .COM exit interrupt.
mov cx, 1a mov dl, 41 rep: mov ah, 2 int 21h inc dl loop rep int 20h
The register CX stores the loop counter. Each time when loop is executed, it decrements the CX by one and checks whether CX = 0. If yes, it doesn’t jump but move forward one instruction. If no, jumps to the specified label. It can be translated into C code, which is more clear.
1 | if (--cx > 0) goto label; |
if (--cx > 0) goto label;
The command g in debug.exe will run the .COM program at address 100. Instruction inc dl increments the register DL by one. similarly, dec will decrement the specified register by one.
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: Lost Era - Microsoft DOS, 16 bit .COM Assembly
Next Post: Emerging Era, Win32 Assembly, MASM, Hello World!
how about loop in slant?
not sure what do you mean
Is that possible to make a loop inside other loop?
I’m trying to do so, but I can’t.
What I have to do is make a triangle of asterisks. I did the firs (top) but I need to do the next line and I don’t know how.
16 bit DOS only has a few registers, so for nested loops, it is better to create a sub routine e.g. push and pop.