home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1992 / USERAU92.MSA / ASSEMBLY_JUNE_PROG0005.S < prev    next >
Text File  |  1992-03-13  |  3KB  |  86 lines

  1. *****************************************************************
  2. *  Atari ST User Assembler Tutorial Series Program PROG0005.S   *
  3. *  This program should be assembled to disk as PROG0005.PRG or  *
  4. *  PROG0005.TOS. It can then be executed by double-clicking on  *
  5. *  the program file created.                    *
  6. *****************************************************************
  7. * This program is an example of using the CoMPare and Branch    *
  8. * instructions to control the execution of a program.        *
  9. * It will ask you to press two keys. It will then compare the   *
  10. * values of the two, and tell you which one was the higher.     *
  11. * To exit the program, simply press the same key twice.         *
  12. *****************************************************************
  13. start:
  14.     MOVE.L    #text1,-(SP)    ;Move the address of the text
  15.     MOVE.W    #9,-(SP)    ;GEMDOS 9 Prints a string
  16.     TRAP    #1        ;Call GEMDOS
  17.     ADDQ.L    #6,SP        ;Correct the stack
  18. *
  19.     MOVE.W    #1,-(SP)    ;GEMDOS 1 gets a keypress
  20.     TRAP    #1        ;Call GEMDOS
  21.     ADDQ.L    #2,SP        ;Correct the stack
  22.     MOVE.B    D0,D1        ;Store the first key in D1
  23. *
  24.     MOVE.L    #text2,-(SP)    ;Move the address of the text
  25.     MOVE.W    #9,-(SP)    ;GEMDOS 9 Prints a string
  26.     TRAP    #1        ;Call GEMDOS
  27.     ADDQ.L    #6,SP        ;Correct the stack
  28. *
  29.     MOVE.W    #1,-(SP)    ;GEMDOS 1 gets a keypress
  30.     TRAP    #1        ;Call GEMDOS
  31.     ADDQ.L    #2,SP        ;Correct the stack
  32.     MOVE.B    D0,D2        ;Store the second key in D2
  33. *
  34.     CMP.B    D1,D2        ;CoMPare the two keys
  35.     BEQ.S    exit        ;One = Two so exit
  36.     BGT.S    two_lt        ;Two was Less than One
  37.     BLT.S    one_lt        ;One was Less than Two
  38. *
  39. * The program can't drop through to here as one of the above three
  40. * must be satisfied. In fact, by re-ordering the tests, one test could
  41. * have been omitted, and the program left to drop through to the remaining
  42. * option. But that wouldn't have demonstrated three compare and branch
  43. * instructions.
  44. *
  45. two_lt:    MOVE.L    #text3,-(SP)    ;Move the address of the text
  46.     MOVE.W    #9,-(SP)    ;GEMDOS 9 Prints a string
  47.     TRAP    #1        ;Call GEMDOS
  48.     ADDQ.L    #6,SP        ;Correct the stack
  49. *
  50.     BRA    start
  51. *
  52. one_lt:    MOVE.L    #text4,-(SP)    ;Move the address of the text
  53.     MOVE.W    #9,-(SP)    ;GEMDOS 9 Prints a string
  54.     TRAP    #1        ;Call GEMDOS
  55.     ADDQ.L    #6,SP        ;Correct the stack
  56. *
  57.     BRA    start
  58. *
  59. exit:    MOVE.L    #text5,-(SP)    ;Move the address of the text
  60.     MOVE.W    #9,-(SP)    ;GEMDOS 9 Prints a string
  61.     TRAP    #1        ;Call GEMDOS
  62.     ADDQ.L    #6,SP        ;Correct the stack
  63. *
  64. *
  65.     MOVE.W    #1,-(SP)    ;GEMDOS 1 waits for a keypress
  66.     TRAP    #1
  67.     ADDQ.L    #2,SP
  68. *
  69. * .. and finally exit back to the desktop
  70.     CLR.W    -(SP)        ;0 is TERM
  71.     TRAP    #1        ;Call GEMDOS
  72. ******************************************************************
  73. * The section of program following contains the Data used by the *
  74. * program which is assembled and saved as part of the program.   *
  75.     SECTION DATA
  76. *
  77. text1:    DC.B    13,10,'Please press the first key: ',0
  78. text2:    DC.B    13,10,'Now press the second key: ',0
  79. text3:    DC.B    13,10,'The first key was less than the second.',0
  80. text4:    DC.B    13,10,'The second key was less than the first.',0
  81. text5:    DC.B    13,10,'Both keys were the same - Time to go.',0
  82.  
  83.  
  84.  
  85.     
  86. *****************************************************************