Re: A89: More ASM help please


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

Re: A89: More ASM help please




In a message dated 11/24/1998 7:57:32 PM Pacific Standard Time,
BLoWh0Le@aol.com writes:

> Can someone explan the following code excerpt from the hello world program?
>  
>     move.w   #2,-(a7)               ; use font #2 (large font)
>  
>  <<<ok, I think this moves 2 into (a7), but what is the negative sign? is 
> that
>  like variable-- in C++?>>>

Correct. The a7 register is used as the stack pointer.  The stack is a
temporary place to store variables.   The negative sign is a predecrement.

>  
>      jsr      tios::FontSetSys       ; set the font
>  
>  <<< I'm guessing 2 is pushed into the stack and FontSetSys uses 2 as a
>  parameter, right?  When FontSetSys is called, is the 2 popped out or does
it
>  stay there?>>>

The 2 is not popped out.  The next line does that.

>  
>      add.l    #2,a7                  ; clean up the stack
>  
>  <<< How does adding 2 to a7 clean up the stack? What's going on? >>>

Since a7 is used as the stack pointer, this moves the stack pointer to its
previous position.

>  
>      move.w   #4,-(a7)               ; move the first param to the stack
>  
>  <<< Ok, here's another parameter, but for what? >>>

This is for tios:DrawStrXY.

>  
>      lea      string(pc),a0          ; move adress of string to the stack
>  
>  <<< What does lea do and why does string have a (pc) next to it? >>>

lea loads the memory address into the specified destination.  pc is the
program counter (ip register in Intel processors).  This is the instruction
currently being executed.  What this does is it takes the relative address of
string and adds the value of pc to it.

>  
>      move.l   a0,-(a7)
>  
>  <<< String is being pushed into the stack via a0, but why did we have to
use
>  a0 when it seems logical enough to just push string in directly?>>>

This is probably because it loads the address of string, not the data in it.

>  
>      move.w   #0,-(a7)               ; push position
>  
>  <<< Pushes 0 into stack as Y-position parameter >>>
>  
>      move.w   #0,-(a7)               ; push position
>  
>  <<< Pushes 0 into stack as X-position parameter >>>
>  
>      jsr      tios::DrawStrXY        ; call the DrawStrXY ROM function
>  
>  <<< Once again, is everything popped outta the stack, or is it still there?
>  >>>

Like before, no.  Tios uses the C calling convention, in which parameters are
pushed  in order from right to left.  Also, the C calling convention states
that the calling program is responsible for cleaning up the stack.

>  
>      add.l    #10,a7                 ; restore the stack pointer
>  
>  <<< How does this work too?  What does it mean by clearing and restoring
the
>  stack? >>>

Again, this is just like last time.  It changes the stqack pointer to its
previous position.

>  
>  Thanks.
>  


68k Asm really isn't that hard with all the library and Rom subroutines.  Like
all things, it just takes practice.

Daniel Imfeld


Follow-Ups: