Stack Problems :(

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
Brill

Stack Problems :(

Post by Brill »

Hi, i'm trying to set-up my stack but i don't know what to do eactly and i'm fed up with trial and error with my machine resetting every time.
At the moment im declaring an uninitialized variable and then counting how many bytes are after it. Add them together, and move into esp.
so...

stack        RESB   10          ; Should be 10 bytes right?
stack_size   equ    $-stack     ; And this will count how many bytes from $-stack up to this point (10 bytes) if i understand the nasm manual correctly.

Then above this code i do in the .text section i write...

mov eax, [stack+stack_size]
mov esp, eax

I keep changing it around a little, and looked inside the intel manuals but they don't tell me much about stacks.
Can anyone please help my create my stack?
Oh, and ss has the orginal segment register value that was given to my os when grub booted it.
carbonBased

RE:Stack Problems :(

Post by carbonBased »

You've got:

mov eax, [stack+stack_size]
mov esp, eax

Which will load eax with the value at memory location (stack + stack_size).  You don't want the value at that location, you want the actual location.

Get rid of the square brackets, and you should be alright.

Jeff
Post Reply