Re: A86: More ASM Questions


[Prev][Next][Index][Thread]

Re: A86: More ASM Questions




In a message dated 1/23/99 6:07:48 PM Pacific Standard Time,
cflan@granitecity.com writes:

> I have a question about the logic of using the stack.

Here we go, as fast as possible, everything you need to know about the stack
to use it. :)

First of all, let's say that register a contains %00001010 (10) and register b
contains %00000111 (7). If you were to pass:

 push a

the stack would look like this:

%00001010

Then, if you did this:

push b

the stack would look like this:

%00000111
%00001010

a and b still contain their respective values.

Now, the stack is what is called a LIFO stack, which means Last In First Out.
It's like taking some cards and putting them in a pile. If you were to 'push'
a card onto an empty stack, that card would be at the top. If you 'push'ed
another card on top of the first one, that card would be on top. If you wanted
to remove a card, you'd take the one from the top, leaving the first card
there. Still with me? Good.

Now, if you wanted the top value back, you would pop it to a register. It does
not matter which one. Let's say, that for some reason, we needed d to have the
varaible that b was. We just pop that sucker off:

pop d

and now D contains %00000111, and the stack looks like this:

%00001010

If you wanted that value in e:

pop e

Now e contains %00001010 and the stack looks like this:



It's empty! Now, whatever you do, don't pop anything else off or nasty, nasty
things will happen!

I hope you got that. :)