3

Im writing a bootloader and I set up my stack up as such...

STACK_SEGMENT equ 0x0050
STACKP_OFFSET equ 0x03FF

mov ax, STACK_SEGMENT
mov ss, ax
mov sp, STACKP_OFFSET

Am I allocating 1024 bytes of stack space by doing this? and is it appropriate to load other stuff at 0x00900? 0x00900 should be right after my stack data...

TheFuzz
  • 2,607
  • 6
  • 29
  • 48

1 Answers1

1

Yes, this will provide you with 1024 bytes of stack space, as long as you didn't load anything else between 0x500 and 0x900. Also, yes it is safe to store data at 0x900 without overwriting the stack. One thing to remember is that, if the stack and data segments are different, you will need to use segment prefixes if you want to access data on the stack with any register other than sp or bp.

ughoavgfhw
  • 39,734
  • 6
  • 101
  • 123
  • what do you mean by prefixes? – TheFuzz Jul 10 '11 at 17:42
  • @TheFuzz You add a segment prefix to make data load from a segment other than the default. You can load data from `bx` using the stack segment by adding a `ss` prefix: `mov ax,ss:[bx]`. – ughoavgfhw Jul 10 '11 at 17:45
  • Why and when would I use registers other than `bp` and `sp` to access stack data? Sorry I'm not quite understanding. – TheFuzz Jul 11 '11 at 02:37
  • If you have need to pass a pointer to a local variable between functions, that variable is usually stored on the stack. But, unless it expects that, the other function will usually assume that it is stored in the data segment. This may or may not be something that you need to worry about, but you should be aware of it just in case. – ughoavgfhw Jul 11 '11 at 23:00