home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / POWERMAG / POWER121.MSA / POWER_12.DK1_ASSEMBL3.PWR < prev    next >
Text File  |  1989-12-30  |  6KB  |  121 lines

  1.   ***********************************************************************
  2.   *                      Assembly Language Programming                  *
  3.   *                                    By                               *
  4.   *                                Chris Sharp                          *
  5.   ***********************************************************************
  6.  
  7.  
  8.   Hi there, and welcome to the tutorial that doesn't try to teach you
  9.   how to pre-shift sprites, before you can print a line of text to 
  10.   the screen!
  11.  
  12.   The whole point of this tutorial really is to teach the absolute novice
  13.   how to program in assembly language. Absolutely no prior knowledge is
  14.   assumed.
  15.  
  16.   As you probably know, Assembly language is the closest language to 
  17.   machine code, which means that  it can create the fastest programs,
  18.   which can be very important when programming a speed critical game
  19.   like space invaders, or a huge desktop publishing program, that needs
  20.   to run fast, in order to keep the users attention.
  21.  
  22.   This time, I am going to show you how to write a very primitive
  23.   password entry system.
  24.  
  25.   First of all, we have to decide what we want the program to do. In this
  26.   case, it is going to be the password protection system.
  27.  
  28.   Once we know what we want the program to do, we have to decide how to
  29.   do it. Right then, the program I am going to write is going to ask for
  30.   3 letters or numbers to be entered, before the system exits to DOS.
  31.   The password program will be copied to an AUTO folder, and so will run
  32.   when the disk is inserted into the computer.
  33.  
  34.   O.K. So, we know what the program is and what we want it to do. Now 
  35.   all we have to do is program it! Which of course is easy (once you 
  36.   know how, which is why I am trying to help you to learn)!
  37.  
  38.   The program is below. I have commented every line, so it should be
  39.   pretty obvious what everything is doing.
  40.  
  41.   I showed how to correct the stack in a previous issue of POWER, so if
  42.   you don't have that copy, you'd be wise to order it now, as a whole
  43.   column was given to show how to do this!
  44.  
  45.   Ignore the semi-colon's in the listing. I typed this program in, and
  46.   then wrote the text to go with the program. I needed the semi-colons
  47.   when I was programming the password system, and have simply not
  48.   bothered to take them out.
  49.  
  50.   Try typing in the program below, and running it.
  51.  
  52. ***************************************************************************
  53.  
  54. start:
  55.        PEA mess(PC)     Tell GEM where to find message in memory.
  56.        MOVE #9,-(A7)    Ask for Function 9... Print a string.
  57.        TRAP #1          Call GEMDOS (Tell computer to do the instruction)
  58.        ADDQ.L #6,A7     Correct Stack
  59. input:
  60.        BSR keypress    Get the users keypress
  61.        CMP #'4',D0     is it the number '4' ?
  62.        BNE input       If its not then branch to the label Input:
  63.                        ;if it is, then continue down the listing.
  64.        BSR keypress    Get the second keypress
  65.        CMP #'5',D0     is it the number '5' ?
  66.        BNE input       If its not, then go right back to the begining,
  67.                        ;where the user will have to enter the password
  68.                        ;all over again. However, if it is a 5, continue
  69.                        ;down the listing.
  70.        BSR keypress    Get the third keypress.
  71.        CMP #'8',D0     is it an '8' ?
  72.        BNE input       If it isn't, then go right back to the beginning,
  73.                        ;where the user has to enter the password all
  74.                        ;over again. If it is correct, then well done,
  75.                        ;the correct password has been entered!
  76.        
  77.        
  78.        BRA exit        Correct password has been entered, so this
  79.                        ;command will take us to the exit procedure
  80.                        ;which will end this program, and return us
  81.                        ;to TOS.
  82.        
  83. keypress:  
  84.        MOVE #8,-(A7)    Call function 8, which is c_necin  (get a keypress)
  85.        TRAP #1          Call GEMDOS to execute our command.
  86.        ADDQ.L #2,A7     tidy stack
  87.        RTS              return from subroutine       
  88.        
  89. exit: 
  90.        Move.w #0,-(a7)     call function 0.
  91.        TRAP #1             Call GEMDOS to execute our command.
  92.  
  93. mess  DC.B "Please enter the password.If you make a mistake,start again.: ",0
  94.  
  95. *****************************************************************************
  96.  
  97.   When you have got the program working, the best way to understand what is
  98.   happening is to modify lines of the program, assemble it, and then see
  99.   what happens. Only modify one line per go though, otherwise you won't know
  100.   which line had which effect!
  101.  
  102.   If you can't understand the program, and you DO have the other copies of 
  103.   POWER, with the tutorial parts 1 and 2, then write to me and I'll try to 
  104.   sort out your problem. Remember to enclose a stamp and an envelope.
  105.  
  106.   If you don't have the other copies of POWER, order them and read the
  107.   other tutorials first. If you still have no joy, write to me at the
  108.   following address -:
  109.  
  110.  
  111.                                    Chris Sharp
  112.                                  Supreme Software
  113.                                 4 Sunnycroft Lane
  114.                                    Dinas Powys
  115.                                  South Glamorgan
  116.                                       Wales
  117.                                      CF64 4QQ
  118.  
  119.  
  120.  
  121.