Re: ESP (stack) question (using HLA)???




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

.



Relevant Pages

  • Re: HLA fileio.getf( ... ) question?
    ... values onto the fp-stack from a file where they are stored in binary ... sub esp, ... mov eax, 3; write ... straight onto the FPU stack?", I think the simple answer is "no". ...
    (comp.lang.asm.x86)
  • Re: further optimizations
    ... Mov is atomic right? ... routine which runs at PL=3 then the user stack becomes part of the story. ... Either there is one stack, in the one interrupt routine,`that is not seen and used elsewhere or there are two or more stacks? ... just an attempt to explain why ESP is always recommened to be preserved. ...
    (alt.lang.asm)
  • Re: Registers
    ... > automatically switches to a new stack. ... If you need to push several values on the stack, and don't need ESP to point ... MOV -4, ESI ...
    (alt.lang.asm)
  • Re: Conditional breakpoint based on caller / module
    ... When a function call is made, the caller function copies the following information ... ESP register is a pointer, which in normal circumstances always points ... to some area of the stack. ... When you set the breakpoint at the beginning ...
    (microsoft.public.vc.debugger)
  • Re: Stack frames
    ... > ESP with the common stack frame models. ... ESP, why not simply move the "MOV esp, ebp" ... You can't rely on "size(locals + align)" to keep the ...
    (alt.lang.asm)