Stacks and CALLs

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Eric

Stacks and CALLs

Post by Eric »

currently Im writin a bootloader but I got a question. In some source I downloaded I found that they were using CALL some times. But CALL needs a stack and they used CALL before they set the stack-pointers and all that. Something like
[16 BITS]
[ORG ...]
jmp start
method:
...
...
ret
start:
call method

but without a stackpointer, how can they use CALL? Is there already a stack when running in real mode?
GT

RE:Stacks and CALLs

Post by GT »

There is always a stack -- the SS and ESP registers exist no matter what.  The problem is, if you've just been handed control by the BIOS, who knows what they're set to.  Push a thing or two and for all you know you're overwriting your own code!  The BIOS *probably* left them set to something useable, at least for pushing a handful of bytes, but there is no guarentee.  Set up your own stack first unless you like living dangerously (and listening to users complain when your code doesn't work on their boxes)...
Post Reply