LISTING4.TXT

From Atari Wiki
Revision as of 23:57, 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)                  *
*                                                                    *
*                           Second series                            *
*                                                                    *
*                         Listing number 4                           *
**********************************************************************
* Program self-modification
         INCLUDE   "B:\START.S"      startup routine
         MOVE.L    #MESSAGE1,-(SP)   introducing
         MOVE.W    #9,-(SP)          the program
         TRAP      #1
         ADDQ.L    #6,SP
START    MOVE.W    #7,-(SP)          waiting for a key press
         TRAP      #1
         ADDQ.L    #2,SP
         CMP.W     #" ",D0           space?
         BEQ       END               yes, so goodbye
         MOVE.W    #$4E71,VARIANT    places a NOP (by default)
         CMP.W     #"A",D0           press 'A'?
         BNE       HERE              no
         BSR       ROUTINE           yes, so long subroutine
         BRA       START             and start over
HERE     MOVE.W    #$4E75,VARIANT    places a RTS instead
         BSR       ROUTINE           of the NOP and goes to subroutine
         BRA       START             then starts over

END      MOVE.W    #0,-(SP)
         TRAP      #1
*--------------------------------------------*
ROUTINE  MOVE.L    #MESSAGE2,-(SP)
         MOVE.W    #9,-(SP)
         TRAP      #1
         ADDQ.L    #6,SP
VARIANT  NOP
         MOVE.L    #MESSAGE3,-(SP)
         MOVE.W    #9,-(SP)
         TRAP      #1
         ADDQ.L    #6,SP
         RTS
*--------------------------------------------*
         SECTION DATA
MESSAGE1 DC.B      27,"E","Press A for a long message,",13,10
         DC.B      "space to exit, another key",13,10
         DC.B      "for a shorter message",13,10,0
         EVEN
MESSAGE2 DC.B      13,10,"Here's the short message...",0
         EVEN
MESSAGE3 DC.B      "Oops, no, it's the long one!!!",0
         EVEN
         SECTION BSS
         DS.L      100
STACK    DS.L      1
         END

Back to ASM_Tutorial