Hacker News new | ask | show | jobs
by raverbashing 1920 days ago
Nice, I'm old enough to know what the 2 first lines do (get off my lawn etc...)

For the rest it would take a while to understand the math and I'm not even sure where 0xa0000 would come from

2 comments

That confused me as well. The Mode 13h graphics framebuffer is at address A000:0000. How does this program get that value?

The key is the LES AX,[BX] opcode. BX is initialized to 0 by DOS, and the "Set video mode" BIOS call preserves BX's value. So the LES opcode sets ES:AX by reading a dword from DS:0.

What's there? A COM file is a single-segment program, so DS equals CS, and the code segment starts with the Program Segment Prefix. (The actual code is loaded at offset 100h.) So it loads the first two words of the PSP. What are those?

The first word is an "INT 20h" instruction, 20CDh, for compatibility with CP/M.

The second word is the segment number of the end of the memory allocated for the program. But DOS always allocates all memory to COM programs, so this will be 0x9FFF (assuming you have a full 640K conventional memory installed).

So ES:AX is set to 9FFF:20CD. And with x86 segmented memory 9FFF:0010 equals A000:0000.

Ha!

I’ve toyed through out the years that if I ever got a tattoo, it would be:

mov ax, 13h;

int 10h