Change of gear
The very last time I wrote a line into this diary, it was April 2015, and today is December 23th of 20191. Quite a while, isn't it? Well, my beautiful boy was born and since then I do spend much more time playing with him. I hope in 4 to 5 years from now I will be able to propose informatics to him as something to play together, in which case I will make progress again in my learning path, but right now building castles with Lego bricks has a much higher priority than building code with bytes bricks.
I wanted to name the title of this chapter as the moment when I changed gear in my working model. It was quite slow and heavily "hand made" until now. It was just like a car travelling in 1st gear with the engine running just above idle but then, I gave a little bit gas and changed to 2nd gear. I was still proceeding very slow with the car going in 2nd gear just above idle, but it was somehow faster than before. The fact is that I have just invented (or discovered? Who knows…) a programming technique that can help to build something a little bit more complex of all what I have done until now.
A different way of using DEBUG.EXE
When using the command a (assembly), DEBUG.EXE has the following noticeably behaviour that I used to my advantage:
- The character ";" is used to mark the beginning of a comment (DEBUG.EXE ignores all characters after ";" until the end of the line).
- DB is interpreted as a command during assembly and I can write a sequence of bytes after it.
- Jumps and calls can be written stating the absolute target address and DEBUG.EXE codes the relative increment in byte for the instruction pointer2.
Additionally, I knew about redirecting inputs and outputs in UNIX/LINUX with use of the characters "<" and ">" so I gave it a try with DOS and it worked exactly in the same way. Based on all the aforementioned points, I wrote again the code of out_a_nibble in the following way:
This time, I wrote the text into a simple txt-File with name "out_nbl.npp"3. This file is used as input for DEBUG.EXE and I am going to explain the commands, in the sequence as they are, in order to let you understand what is going on here. First of all, I filled a portion of memory in RAM with the opcode 0x 90 (exchange AX with AX or NOP) using the command f 100 17f 90. Soon after, I started assembling directly in RAM at location 0x 01 00 with the command a 100. From this point onwards, the character ; is interpreted as the beginning of a comment so that I could actually write comments. I marked the maximum length of a line to be 79 chars. By exceeding this length, DEBUG.EXE is still working fine but it produces very bad formatting in output. I coded everything without any empty line because an empty line is interpreted by DEBUG.EXE as the exit from assembly mode. In fact, after the command RET, I added an empty line and, from this point onward, I was back in command line mode of DEBUG.EXE. The command d 100 and u 100 are used to display the result of the assembly in memory and the disassembled version of it. The display occurs on file rather than on screen because I redirected the output to a file. The commands from rbx to q were used to create a binary file with the content of RAM starting at location 0x SEG:0100.
After the preparation of the file "out_nbl.npp", I went on the command
line of the DOS console and typed the following4:
debug < out_nbl.npp > out_nbl_dbg.npp
As result, I had three files in the folder:
- "out_nbl.npp", which is the original input file.
- "out_nbl_dbg.npp", which is the output file created by DOS based on the outputs streamed by DEBUG.EXE.
- "OUT_NBL.BIN", which is the binary output file created by DEBUG.EXE with the command w 100.
The output file "out_nbl_dbg.npp" created by MS-DOS with the stream of DEBUG.EXE contains \r\r\n at the end of every line which creates formatting problems. If you open the file with Microsoft notepad it looks like ok. If you print it, you see an additional empty line after each line (due to the first \r carriage return character). If you open the file with NOTEPAD++ you see the same effect as if you would send the file later on to the printer (Fig. A).
Fig. A - \r\r\n creates bad formatting |
I understood the problem when I let me show the special chars in NOTEPAD++. To do that I selected from the menu "View", the "Show Symbol / Show All characters" option (Fig. B).
Fig. B - "Show All Characters" option in NOTEPAD++ |
I solved the problem by searching \r\r and replacing all of them with just \r (Fig. C).
Fig. C - Replacement of \r\r sequence |
Unfortunately, this is a procedure that must be repeated every time one creates a new output file by use of redirection of output.
What I really used a lot was the output file "out_nbl_dbg.npp" to see how DEBUG.EXE did the assembly. With this file, I read the locations in RAM where each command started and I used them as targets for the jumps (and calls) as if these addresses were numbers of lines (in the upcoming posts, I will explain this step more in detail and with examples).
CONCLUSION: the naming convention of files
By each procedure5, I always end having 3 files:
- fname.npp
- FNAME.BIN
- fname_dbg.npp
The "NPP-files" are just text files. The binary file is created
directly by DEBUG.EXE. Due to this fact, I have to use 8.3 file name
convention (8 chars for name and 3 chars for extension). In fact, I tried to
use long names for the "BIN-file" but DEBUG.EXE truncated all by
8.3.
"fname.npp" is always the source file6. It is a plain text file that can be opened and edited with any text editor.
The extension "NPP" is what I decide to use in order to make an automatic file
association with the NOTEPAD++ editor. There are a couple of features that I
like in NOTEPAD++ and this is the reason why I used it, but you can feel free
to use whatever text editor you like.
"FNAME.BIN" is the file that is created as the second one directly by
DEBUG.EXE with use of commands n and
w. It follows strictly the 8.3 filename
convention and DEBUG.EXE capitalizes always the filename when it creates
it.
"fname_dbg.npp" is the last file created by DOS with the technique of
redirecting the output to file. Since this file is created by DOS it is
allowed to have long names. The "_dbg" part of the name tells me that this is
the place to look at when I need information about the procedure. Here I see
the protocol of the assembly job done with DEBUG.EXE.
Comments
Post a Comment