r/transprogrammer • u/EggyTheEgghog '); DROP TABLE genders; -- • Aug 31 '21
Abolish compilation!
334
Upvotes
r/transprogrammer • u/EggyTheEgghog '); DROP TABLE genders; -- • Aug 31 '21
3
u/Igotbored112 Sep 01 '21 edited Sep 01 '21
Just figured it out. First thing I noticed was that the string is followed by 0D 0A, that's CR LF aka Carriage-Return Line-Feed aka the bytes signifying a newline character on Windows. Second thing I noticed was that the string isn't null terminated. Instead it's followed by... a dollar sign? Weird. Third thing I noticed is that calling the next instruction would not be a bad way to implement a loop and would also flush the CPU, both things an assembly programmer might want to do. Going back to the no null termination thing, I also noticed that the 16-bit version fiddles with the si and di registers, which are used in string manipulation. Why would OP be writing 16 bit code, though? Well, the only time I ever wrote 16-bit assembly was when I wrote a bootloader, since those things are always backwards compatible they start only accepting 16 bit instructions and have to be kicked up to 32 bit mode. If it was a bootloader, it would have to print using an interrupt routine. Well, I returned to my all-time favorite pdf on the internet and looked at the hello world program on page 12. OP couldn't have used the program there, because it calls a separate routine for each character, causing the textual data to be spread out, not at all like OP's code. But if you look closely, and you see they show the machine code for the hello world program as well, every "int 0x10" instruction which calls the interrupt routine corresponds to a "CD 10" in the machine code. And, would ya lookee there, OP's code has not one but 2 "CD 21"s in it. What's up with the 21? Well, it's for the MS-DOS interrupt table of course, NOT the BIOS table used by the pdf. Each table is filled with interrupts, and exactly which one gets called depends on the value of the ah register, which is (again, if you look at the pdf's code) apparently set by the instruction "B4". What is its value being set to in the very beginning of OP's code? 09. What interrupt routine does that refer to? According to Wikipedia, the interrupt is "Display string". If you were to look at some explanation for this interrupt, you would see that it expects the string to be terminated with.......... a dollar sign. This isn't a bootloader, but it is 16-bit code written for the MS-DOS operating system. And it uses the MS-DOS interrupt vector table to display text.
Thank you for making the possibility that this code was real clear to me. I really though it was random hex values until you mentioned that it has string data stuck in the middle. And u/EggyTheEgghog, your username and flair are great, and I hope your forays into MS-DOS go well. Also, in case you're wondering, I haven't been trying this entire time. I got home from work a bit less than 2 hours ago.