Assemble a stack
I thought it might be helpful to explain the stack instructions a bit more in detail. The stack instructions involve the following components:
- a memory area
- a base pointer
- an index value
- a PUSH instruction
- a POP instruction
- a value to push (or pop)
The base pointer (BP
) contains the address of some memory cell. The index register (IX
) contains the index of the element in the stack. Written together as BP[IX]
there refer to the address of a specific element in the stack. The address is the sum of BP
and IX
. Note that so far we could also write IX[BP]
and it would still refer to the same address. The difference starts when using the PUSH
/POP
instructions, which we will look at next time.
Here is an example for values of BP
and IX
pointing to some area of memory with unknown content.
BP: 0x0039
IX: 0x0000
0x38: ?
BP[IX] ---> 0x39: ?
0x3A: ?
0x3B: ?