Our jump instruction will take an operand (the destination address), meaning it’s a 2-byte long assembly instruction. The data will come immediately after such jump instruction. What we will place at CS:0100 is a jump assembly instruction to skip the data (the “hello, world!!” string) and arrive to our actual code. So we can’t place the data at such address. Now, we want our program execution to begin at CS:0100. We begin with the newline (0D 0A) and end with the “$” (24). Notice that the full hexadecimal representation of such string is: 0D 0A 68 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 21 0D 0A 24 Therefore, we modify our DB instruction again: db 0d,0a,"hello, world",0d,0a,"$" ASCII value of “$” is 36, or 24 in hexadecimal. The function will print every character until finding a “$” character (i.e., “$” acts as the “zero” in null-terminated C strings). In short, I have to place the value 09h in register AH, and DS:DX should point to the beginning of our string. In order to effectively print the message to the standard output I’ll recur to the function 09h of INT 21h. Now our DB would be modified to look like this: db 0d,0a,"hello, world",0d,0a In hexadecimal, CR is 0Dh, and LF is 0Ah. A newline is in fact two characters: a carriage return (CR is ASCII 13) and a line feed (LF is ASCII 10). However, I want a prettier output, with a newline character before and after our string. With DB I can neatly provide the string using ASCII values, like this: db "hello, world!!" I’ll use the pseudo-instruction “DB” to define our string. That’s because I want the final program to occupy exactly 32 bytes we’ll see the reason for this later on. For this little program I only need the characters for “hello, world!!”. Equivalently, I could type “a 0100” or “a 100” to achieve the same result. By default, instructions will be placed starting from CS:0100, so I’ll use that address. The command for that is “a”, which might be optionally followed by a memory address. I want to assemble, i.e., I want to type assembly language instructions. After we execute DEBUG.COM we’ll meet a prompt with a “-” symbol. I don’t have any use for this, but it comes as a “relaxing” post after several weeks focused on the release of “DragonScales 3: Eternal Prophecy of Darkness” on Steam and the localization of “DragonScales 5: The Frozen Tomb”. Specifically what I want is to build a minimal “hello, world!” program using DEBUG.COM. You could create little programs, or inspect programs and peek memory areas. However, DEBUG looked pretty cool back then: it could assemble, disassemble and dump hexadecimal output. Heck, DEBUG isn’t even available on the Windows 10 machine I’m typing this on. So I’ll revisit this here, mostly as a self-imposed disciplinary measure, an exercise on programming, specifically, an exercise on programming futility. I wrote a post about this “hello, world” with DEBUG.COM elsewhere, and yesterday I found the time to reread it: I verified, first with awe, then with horror, and finally, with relief, that I had almost completely forgotten how to code in assembly. I remember trying to code, as expected, the traditional “hello, world!”, using a strange tool included in DOS, DEBUG.COM. First painful steps were taken and first crashes happily followed. The famous RBIL (Ralf Brown’s Interrupt List) was, back then, my favorite “reference”. I remember the masochist approach to learning the opcodes and the hardware architecture. More than two decades ago I used to code in x86 (Intel) assembly, almost daily. Or an exercise on retro, old-school coding. For each time any of these flags changes from 0 to 1 or 1 to 0, write an explanation for the change.Coding “Hello world” with DEBUG will be a blunt exercise on programming futility. Write on your printout the binary values (0 or 1) of the Sign, Zero, and Carry flags next to each step of the trace. Capture and print the program trace with the register dumps. Look at the register dumps and note the flag values after each instruction is executed. Use the "t" command to trace through the program one instruction at a time. Use the "a 100" command to enter the following short program: Text: Assembly Language using DOSBox and DEBUGġ0.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |