OSDEV WIkI Babystep tutorial
Posted: Wed Apr 18, 2012 9:47 pm
Hello I wanted to bring up a question here about the below code from the Babystep4 page.
From what I understand of the stack and from the Intel information, the stack pointer is decremented when things are placed on the stack. So if the boot loader code starts at 0x07c0:0x0000 and extends to 0x07C0:0x0200 <-- sorry this is in real mode format , and the stack pointer is sitting at address 0x0000:9C00 which would be where the code for the boot loader ends wont putting anything on the stack cause it to move into memory that contains the boot loader?
The reason I say the SP is sitting where it is is because 0x0000:0x9c00 is the same address that 0x07c0:0x0200 is.
Its odd really there seam to be alot of confusion on the internet about how the stack pointer behaves when things are placed on it.
Code: Select all
[ORG 0x7c00] ; add to offsets
xor ax, ax ; make it zero
mov ds, ax ; DS=0
mov ss, ax ; stack starts at 0
mov sp, 0x9c00 ; 200h past code start <-- code in question
From what I understand of the stack and from the Intel information, the stack pointer is decremented when things are placed on the stack. So if the boot loader code starts at 0x07c0:0x0000 and extends to 0x07C0:0x0200 <-- sorry this is in real mode format , and the stack pointer is sitting at address 0x0000:9C00 which would be where the code for the boot loader ends wont putting anything on the stack cause it to move into memory that contains the boot loader?
The reason I say the SP is sitting where it is is because 0x0000:0x9c00 is the same address that 0x07c0:0x0200 is.
Its odd really there seam to be alot of confusion on the internet about how the stack pointer behaves when things are placed on it.