Search code examples
assemblycompilationstackmotorola68000

Copy a byte from a stack without changing the stack pointer(Motorolla 68000)?


I'm asked the following question:

Three  bytes  are  pushed  onto  the  runtime  stack.  Copy  the  third  
byte  from  the  runtime  stack  to D0 without changing the stack pointer

So I have a stack that looks like this:

|   |
|   |
|cc | <-- SP points to cc
|bb |
|aa |

I'm not sure how I would copy the value of cc, into register D0. I know I can pop it off the stack like this ... MOVE.B (SP)+,D0, but this would change the stack pointer to point to bb

Also what's the difference between a user stack and a run time stack? For instance if I'm asked to pop a byte from a user stack(A6) but then push it into the run time stack, how would I do that? Any ideas?


Solution

  • You need to use an offset on the stack pointer. Also remember stacks go backwards (typically :) ) so

    move.b (sp), d0
    

    would yield $cc in your example

    move.b 2(sp), d0
    

    will get you $aa into d0

    Hope that helps