Re: ESP (stack) question (using HLA)???
- From: "randyhyde@xxxxxxxxxxxxx" <spamtrap@xxxxxxxxxx>
- Date: Fri, 28 Oct 2005 18:10:45 +0000 (UTC)
spamtrap@xxxxxxxxxx wrote:
> I've tried to create my own (mini)stack using 'rstack' and pop & push
> from it by assigning the ESP register then pop & push and then assign
> ESP back to it's orinal value:
>
> Wdeg: uns16 := 0;
> rstack: uns16[ 2 ];
> tesp: uns32;
You might want to make rstack just a little bit bigger :-).
Try something like
rstack:uns32[256];
Also, note that the x86 (in 32-bit mode) *really* likes the stack to be
dword-aligned. So you should also do this:
align(4);
rstack:dword[256];
(that's assuming that the stack is in the STATIC or STORAGE section.
See below if you want to put your stack in a VAR section.)
>
> ...
>
> mov( esp, tesp );
> lea( esp, rstack );
As others have pointed out, the stack grows *down* so you must
initialize ESP with the address of the first memory object *beyond* the
end of the stack. Also, this is a good place to guarantee dword
alignment, e.g.,
lea( esp, rstack[256*4] );
and( $ffff_fffc, esp ); // Aligns ESP to the next lower dword
> //stdout.put( "esp = ", ( type uns32 esp ), nl ); This causes a stack
> error!!!
Probably because you've switched to your local stack which is too small
(remember, stdlib routines use the stack too!). This might also be due
to the fact that the stack pointer is not dword aligned.
> push( ax );
> mov( tesp, esp );
> //stdout.put( "rstack = ", ( type uns16 rstack[ 0 ] ), nl );
>
> ...
>
> mov( esp, tesp );
> lea( esp, rstack );
> pop( Wdeg );
> mov( tesp, esp );
> stdout.put( "Wdeg = ", ( type uns16 Wdeg ), nl );
>
>
> Unfortunately, this isn't working. The value assigned to Wdeg is 0 not
> 82 (the value I thought I had pushed). Any ideas?
>
> ---John
In general, I do *not* recommend using the 80x86 hardware stack to
maintain a software stack. The problem is that the hardware stack gets
used for so many things and you really don't want to disturb it. The
overhead for a software stack (see Kain's code, for example) is
sufficiently low relative to the amount of use a typical stack gets in
a program that it should work just fine.
Cheers,
Randy Hyde
.
- References:
- ESP (stack) question (using HLA)???
- From: spamtrap
- ESP (stack) question (using HLA)???
- Prev by Date: Re: plz help!!!
- Next by Date: Re: improve strlen
- Previous by thread: Re: ESP (stack) question (using HLA)???
- Next by thread: plz help!!!
- Index(es):
Relevant Pages
|