                          Assembler coding - Lesson 1

                     Speed comparison between Machine Code                   
                               and BASIC programs                            
                                                                             
    Printing a character on the screen                                       
                                                                             
    This first example shows you how to print a character on the screen. In  
    the example you make use of the 'accumulator' acc. for short, and a      
    'Kernal Routine'. Here's the program                                     
                                                                             
      10 ORG 8192                                                            
                                                                             
      20 LDA #82                                                             
                                                                             
      30 JSR $FFD2                                                           
                                                                             
    Here's the breakdown                                                     
                                                                             
    10 - Assemble in location 8192 decimal (2000 hex) - Type SYS 8192 to run 
    from BASIC                                                               
                                                                             
    20 - Puts the value 82 decimal into the accumulator (value for the       
    letter R)                                                                
                                                                             
    30 - This jumps to a kernal subroutine that prints the value in the acc. 
    to the screen                                                            
                                                                             
                                                                             
                                                                             
    Ok, so know you could wite your name like this                           
                                                                             
      10 ORG 8192                                                            
                                                                             
      20 LDA #82                                                             
                                                                             
      30 JSR $FFD2                                                           
                                                                             
      40 LDA #79                                                             
                                                                             
      50 JSR $FFD2                                                           
                                                                             
      60 LDA #66                                                             
                                                                             
      70 JSR $FFD2                                                           
                                                                             
    More of the same, but this time it would print out ROB on the screen.    
                                                                             
                                                                             
                                                                             
    Right then, lets see the difference between assembler language and       
    BASIC.                                                                   
                                                                             
    First type and run the BASIC program below:-                             
                                                                             
      10 PRINT CHR$(147)                                                     
                                                                             
      20 PRINT"R"                                                            
                                                                             
      30 GOTO20                                                              
                                                                             
    You should see your screen fill with the letter R. Notice the speed at   
    which this happens.                                                      
                                                                             
                                                                             
                                                                             
    Now lets assemble the machine code equivalent and see the execution      
    speed difference.                                                        
                                                                             
    Type in the following in Zeus, assemble it and run it.                   
                                                                             
      10 ORG 8192                                                            
                                                                             
      20 LDA #147                                                            
                                                                             
      30 JSR $FFD2                                                           
                                                                             
      40 LDA #82                                                             
                                                                             
      50 LOOP JSR $FFD2                                                      
                                                                             
      60 JMP LOOP                                                            
                                                                             
    This is the assembler version of the basic program. When you have        
    assembled it, use:- SYS 8192 from BASIC to run it. Again the screen will 
    fill with the letter R, only this time much faster.                      
                                                                             
    The assembler version works like this :-                                 
                                                                             
    10 - Place in memory to put the code (Execute using SYS 8192 from BASIC) 
                                                                             
    20 - Place value for clear screen in accumulator                         
                                                                             
    30 - Print character by jumping to Kernal Subroutine                     
                                                                             
    40 - Place value for letter 'R' in accumulator                           
                                                                             
    50 - Print character by jumping to Kernal Subroutine                     
                                                                             
    60 - Jump to the label named loop (i.e. Line 50)                         

   [IMG]_[IMG]
