Reputation: 63
with the help of some tutorials, i wrote a little piece of code, to display me a string, after booting from my floppy.
my problem is now, that dont understand some lines, were i hope u can help me, or just tell me, if im right.
code:
mov ax, 07C0h
add ax, 288 ; (512 + 4096) / 16 = 288
mov ss, ax
mov sp, 4096
mov ax, 07C0h
mov ds, ax
thanks for your help.
Upvotes: 0
Views: 1774
Reputation: 8831
mov ax, 07C0h
add ax, 288 ; (512 + 4096) / 16 = 288
mov ss, ax
This puts the start of the stack segment (ss) at segment number 07C0h + 288. The bootloader is loaded at the start of segment number 07C0h. The size of a bootloader is 512 bytes and each segment is 16 bytes. This means that the stack segments starts 4096 bytes after the end of the bootloader.
mov sp, 4096
This sets the stack pointer to 4096. This means that the top of the stack is now 4096 bytes past the start of the stack segment. Effectively, this has allocated 4096 bytes for the stack.
mov ax, 07C0h
mov ds, ax
This sets the data segment to 07C0h (the segment where your bootloader starts). When you refer to data labels later in the bootloader, they will use the data segment, so your boot loader has to be at the start of the data segment to be able to find the right location in memory.
Upvotes: 6
Reputation: 2433
mov ax, 07C0h // copy the address 07C0h into the register ax
add ax, 288 // add the number 288 to the address in ax
mov ss, ax // copy the result to the stack segment register (07C0h + 288)
mov sp, 4096 // set the stack pointer to 4096
mov ax, 07C0h // copy the address 07C0h to ax again
mov ds, ax // copy the address 07c0h from ax into ds
.. that's all youve given.
Upvotes: 3