What value should be used for SP to boot?

The boot sequence in the BIOS will load the first valid MBR, which it finds in the physical memory of the computer at 0x7C00.

What value should be used for SP for the boot process?

org 7c00h      ; set location counter.
mov ax, XXX    ; What is XXX?
mov sp, ax
; Now PUSH an POP are safe
+3
source share
2 answers

Any value SS:SPthat has enough stack space for your AND code . Interrupt service routines are OK.

And, of course, your stack should not run into any of your code or other data or run in ROM or in the address range of memory-mapped devices.

BIOS , SS:SP . , SP .

, , ( ):

...
mov ax, 0
mov ss, ax
mov sp, ax
...

SS:SP 0: 0. . SP 0 0xFFFE 0: 0xFFFE, 0: 0.

0x10000 - (0x7c00 + 0x200) = 33280 . .

, SS, SP , SS, SP ( ).

LSS SP, ..., , SS:SP - .

SS SP - PUSH RETF.

+2

0000: 0500 0007: FFFF . :

org 0x0600
...

cli
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7C00

; relocate itself
mov si, sp
mov di, 0x0600
mov cx, 256
rep movsw

; make sure we'are at 0000:0600+x
jmp 0:.reloc
.reloc:
push 2
popf    ; flags with all off

7C00, , . 7C00 , , , /​​.

Btw, MBR 0000: 0600 , VBR 7C00.

jmp.reloc, BIOS MBR 07C0: 0000, jmp , CS = 0

+3

All Articles