COURS 7.TXT

From Atari Wiki
Revision as of 22:31, 16 December 2023 by Olivier.jan (talk | contribs)
Jump to navigation Jump to search
   ******************************************************************
   *                                                                *
   *              68000 ASSEMBLER COURSE ON ATARI ST                *
   *                                                                *
   *                    by The Fierce Rabbit (from 44E)             *
   *                                                                *
   *                            Lesson number 7                     *
   *                                                                *
   ******************************************************************

   We now approach the seventh lesson in the series. The entire 
   course is in 2 series (well, at the time I'm typing these lines, 
   that's what is planned!), this one is the last of the first!

   At the end of this one and if you have very carefully and very 
   scrupulously followed the previous 6 lessons, you should be 
   able to display images, save files etc...

   But first let's go back to our stack and the question from the 
   previous lesson. Did you find the error?

   Well look at the value of A7 before stacking $12345678 and
   $23456, and compare it to the value at the end of the program. Alas!
   it is not the same! Normal, if we count the stackings and 
   the unstackings, we realize that we have stacked 8 
   bytes more than we have unstacked. Indeed, since we have
   retrieved our 2 numbers by first saving A7 in A0,
   we did not touch A7 at the time of recovery.
   Fortunately, though, because the routine return would have been modified!

   Based on the principle of unstacking in reverse order, we must
   therefore correct the stack once back from the subroutine. As we
   have stacked by doing -(SP) we must add so that the stack becomes
   as before. Having stacked 2 numbers of 4 bytes each, 
   we must add 8 bytes to the stack address to correct it
   as it should be. We have already seen how to increase an 
   address, with ADDA.

   It is therefore appropriate to add right after the line BSR AJOUTE an
   addition on SP, by doing ADDA.L #8,SP (which reads ADD ADDRESS 
   LONG 8 STACK POINTER)

   A call to a subroutine by passing parameters on the
   stack will therefore typically be of the kind:

          MOVE.W     #$1452,-(SP)
          MOVE.L     #$54854,-(SP)
          MOVE.L     #THING,-(SP)
          BSR        TINKERING
          ADDA.L     #10,SP

   We pass the word of value $1452 in the stack (modified thus
   of 2 bytes), the long word of value $54854 in the stack (modified
   of 4 bytes), the address spotted by the label THING in the stack
   (modified of 4 bytes) then we go towards our subroutine. Upon 
   return correction of 2+4+4=10 bytes of the stack pointer to return
   to the original state.

...

Back to ASM_Tutorial

Note: The translation provided here is a partial snippet of the larger technical text. Should you need further translation or any additional assistance regarding this content, please let me know!