I don't understand this piece of code:
mov ax, 07C0h ; Set up 4K of stack space above buffer
add ax, 544 ; 8k buffer = 512 paragraphs + 32 paragraphs (loader)
cli ; Disable interrupts while changing stack
mov ss, ax
mov sp, 4096
sti ; Restore interrupts
What for do we do all these manipulations, before we set stack pointer?
I think the comment on the last line sums it up:
buffer: ; Disk buffer begins (8k after this, stack starts)
The memory layout looks like this:
+-------------------+ <-- 07C0:0000, where the BIOS loads the boot sector
| 512 bytes of code |
+-------------------+
| 8KB set aside for |
| a disk buffer |
+-------------------+ <-- SS:0000
| 4KB of stack |
+-------------------+ <-- SS:1000 = SS:SP
The comment about paragraphs is slightly obtuse; I find it easier to think in bytes, where 16 bytes makes one paragraph.
The reason for these magic numbers:
Note that the number 4096 = 4KB appears as normal in the code, because the SP register needs a value in bytes. All the other values are in paragraphs because they relate to SS, which is a segment register.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With