How to learn assembely?


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post Slightly more complex Select Case example

    Now consider the following:

    Code:
          Select Case JoystickDat.dwXpos
                 '//
                 'right?
                 '//
                 Case Is > 50000
                      If Boat_ID <> 2 Then                               'sound on condition
                         If Master_SND_EN Then
                            If AllowRowSND = 0 And Jumping = False And Allow_SND_Effects = True Then
                               SND = sndPlaySound(App.Path & "\Water.wav", CSNDaSync)
                               AllowRowSND = 1                           'sound effect once only
                            End If                                       '
                         End If
                         '//                                             '
                         Rowing_Forward = True                           'set flag
                         Rowing_Backward = False                         'set flag
                         '//                                             '
                         If Jumping Then                                 '
                            'lmitied control when airborne               '
                            PlayerX = PlayerX + (PlayerX < 375) * -1     'inc 1 pixel
                            Boat_ID = 4                                 'ors out img
                         Else                                            '
                         'maintain screen limitations and inc boat forward
                            PlayerX = PlayerX + (PlayerX < 250) * -(1 + Row_Speed)
                            Row_Speed = Row_Speed + (Row_Speed < 20) * -2
                            Boat_ID = 2                                 'row img
                         End If
                         '//                                             '
                      Else                                               '
                         '//                                             '
                         If Jumping Then                                 '
                            Boat_ID = 4                                 'ors in img
                         Else                                            '
                            Boat_ID = 1                                 'ors out img
                         End If                                          '
                      End If
                 '//
                 'joystick center?
                 '//
                 Case Is > 500 And JoystickDat.dwXpos < 50000
                      If Jumping = False Then
                         If Master_SND_EN Then
                            If Row_Speed = 5 And Allow_SND_Effects = True Then
                               SND = sndPlaySound(App.Path & "\Water B.wav", CSNDaSync)
                            End If
                         End If
                      '//
                         Row_Speed = Row_Speed + (Row_Speed > 0) * 1     'grad dec speed                          '
                      '//                                                '
                         If Rowing_Forward Then                          '
                            Boat_ID = Boat_ID + (Boat_ID = 2) * 1     'reset image
                            Rowing_Forward = False                       'flag
                            AllowRowSND = 0                              'en sound for next time
                         Else                                            '
                            Boat_ID = Boat_ID + (Boat_ID = 0) * -1    'reset image
                            AllowRowSND = 0                              'en sound
                            Rowing_Backward = False                      'flag
                         End If
                      End If
                 '//
                 'left?
                 '//
                 Case Is < 500
                      If Boat_ID <> 0 Then                               'sound on condition
                         If Master_SND_EN Then
                            If AllowRowSND = 0 And Jumping = False And Allow_SND_Effects = True Then
                               SND = sndPlaySound(App.Path & "\Water.wav", CSNDaSync)
                               AllowRowSND = 1                           'en sound
                            End If                                       '
                         End If
                         '//
                         Rowing_Backward = True                          'set action flag
                         Rowing_Forward = False                          'set flag
                         '//                                             '
                         If Jumping = False Then                         '
                            PlayerX = PlayerX + (PlayerX > 50) * 10      'inc 10 pixel backward
                            Row_Speed = Row_Speed + (Row_Speed > 0) * 2  'grad dec speed                          '
                            Boat_ID = 0                                  'row back img
                         Else
                            'lmitied control when airborne               '
                            PlayerX = PlayerX + (PlayerX > 50) * 1       '
                            Boat_ID = 4                                  'ors out
                         End If
                         '//
                      Else
                         '//
                         If Jumping Then
                            Boat_ID = 4                                  'ors out img
                         Else                                            '
                            Boat_ID = 1                                  'ors in img
                         End If
                      End If
          End Select
          '//---//
          'Y-axis
          '//---//
          Select Case JoystickDat.dwYpos
                 '//
                 'up?
                 '//
                 Case Is < 500
                      If Jumping Then
                         PlayerY = PlayerY + (PlayerY > 375) * 2         'inc 2
                      Else
                         PlayerY = PlayerY + (PlayerY > 375) * 5         'inc 5
                      End If
                 '//
                 'down
                 '//
                 Case Is > 50000
                      If Jumping Then
                         PlayerY = PlayerY + (PlayerY < 475) * -2        'inc 2 pixel
                      Else                                               '
                         PlayerY = PlayerY + (PlayerY < 475) * -5        'inc 5
                      End If
          End Select
    <hr/>
    Now, while Select Case itself isn't used for all decision making, its main role here is for structure. It greatly improves clarity and organization. It clearly separates the algorithm into much more easily manageable parts. It's perhaps not quite that obvious in this example because there's really on 2 parts in each Select Case.
    <br/>

  2. #2
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post Continued...

    Last example:
    Code:
       Select Case X
              
              Case 5 To 20
                   Col_Loc = 0
                   Cur_PosX = 5
                   Str_Day = "Sunday"
              
              Case 28 To 43
                   Col_Loc = 1
                   Cur_PosX = 28
                   Str_Day = "Monday"
              
              Case 51 To 66
                   Col_Loc = 2
                   Cur_PosX = 51
                   Str_Day = "Tuesday"
              
              Case 74 To 89
                   Col_Loc = 3
                   Cur_PosX = 74
                   Str_Day = "Wednesday"
        
              Case 97 To 112
                   Col_Loc = 4
                   Cur_PosX = 97
                   Str_Day = "Thursday"
                   
              Case 120 To 135
                   Col_Loc = 5
                   Cur_PosX = 120
                   Str_Day = "Friday"
        
              Case 143 To 166
                   Col_Loc = 6
                   Cur_PosX = 143
                   Str_Day = "Saturday"
       End Select
    Procedure taken from a calendar program that I made few months back relies totally on Select Case to do the job. Extremely tidy & extremely fast!
    <br/>

Similar Threads

  1. Can you teach a PIC to learn?
    By lew247 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st December 2009, 02:06
  2. help converting assembely program
    By ahmed_salah in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 7th August 2008, 16:28
  3. How do you learn best?
    By T.Jackson in forum Off Topic
    Replies: 41
    Last Post: - 30th May 2008, 15:32
  4. Who wants to learn...
    By Stoverus in forum Off Topic
    Replies: 1
    Last Post: - 21st October 2006, 08:08
  5. How to learn PIC BASIC compiler in 7 days?
    By luqman83salleh in forum General
    Replies: 2
    Last Post: - 13th August 2004, 15:15

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts