discarding the value of sp. 
Author Message
 discarding the value of sp.

According to my book:
pusha -  push AX, CX, DX, BX, SP(AS IT WAS BEFORE THE PUSHA INSTRUCTION
BEGAN), BP, SI AND DI.
I don't get the things in the bracket means.

and

Popa pops the same registers in reverse order, DISCARDING THE VALUE OF SP.
Why does it DISCARDING THE VALUE OF SP.
Thank you.



Tue, 28 Oct 2003 08:42:20 GMT  
 discarding the value of sp.

Quote:

>According to my book:
>pusha -  push AX, CX, DX, BX, SP(AS IT WAS BEFORE THE PUSHA INSTRUCTION
>BEGAN), BP, SI AND DI.
>I don't get the things in the bracket means.

If you used separate push instructions instead of pusha, sp would change
with each push.  Instead when you use pusha, the sp value on the stack
is what it was before the first register was pushed.


Tue, 28 Oct 2003 12:52:18 GMT  
 discarding the value of sp.

Quote:
> According to my book:
> pusha -  push AX, CX, DX, BX, SP(AS IT WAS BEFORE THE PUSHA INSTRUCTION
> BEGAN), BP, SI AND DI.
> I don't get the things in the bracket means.

> and

> Popa pops the same registers in reverse order, DISCARDING THE VALUE OF SP.
> Why does it DISCARDING THE VALUE OF SP.

From 'Assembly Language Step By Step' by Jeff Duntemann page 348 :

<quote>
PUSHA pushes AX,CX,DX,BX,SP,BP,SI and DI on the stack in that order.
Something to keep in mind : the value of SP that is pushed onto the stack is
the value that SP held before the PUSHA instruction began pushing everything
onto the stack.  Don't forget this if you intend to pop registers from the
stack after pushing the whole crew with PUSHA.  If you do something like
this, you'll be in for a surprise :

PUSHA
POP DI
POP SI
POP BP
POP SP

Why ? The last instruction pops the saved value of SP back into SP.  That
value, remember, was the value SP had before PUSHA started to work.  Once
you use an individual POP instruction to pop the SP value off the stack,
you'll no longer be able to pop AX,BX,CX and DX.  The SP value pushed onto
the stack points above the AX value pushed by PUSHA.
Most of the time, if you use PUSHA to push all the registers onto the stack,
you'll use POPA to pop them off, again as one operation.  POPA reverses what
PUSHA did, and takes the values off the stack and plugs them into the
registers in reverse order.
POPA does something interesting : it simply pops and discards the value
pushed onto the stack for SP.  This prevents the problem I mentioned above
with popping registers after using PUSHA.  So why push SP at all ? In the
very peculiar way CPU chips operate internally, it was probably easier to
push SP on the stack and ignore the popped value that might have gone into
SP than leave SP out of the process entirely.  It's just that PUSHA and POPA
'step through' the registers, and it's easier to step throught them all than
to try and skip one.
</quote>

It makes sense, doesn't it ?

--

HTH

Chris



Tue, 28 Oct 2003 23:18:02 GMT  
 discarding the value of sp.
O, I see,
but I don't get how it discarding the SP??


Wed, 29 Oct 2003 05:07:35 GMT  
 discarding the value of sp.
Never Mind that.
Thank You.


| O, I see,
| but I don't get how it discarding the SP??
|
|
|


Wed, 29 Oct 2003 06:15:59 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Comparing DP/SP values

2. DP divide faster than SP, DP multiply a push with SP

3. SP-Prolog & SP-Object : brief descriptions

4. J: how do I discard leading axes?

5. Discard Duplicates on a Report CDD3.1

6. Testnews: discard

7. warning: discarding old <methodName>?

8. Ruby/Tk: how to discard excess messages

9. Bits discarded in Multiplication

10. test message please discard

11. test, discard

12. Unwanted discard by Expect

 

 
Powered by phpBB® Forum Software