How to learn assembely?


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Whatever the language you're using, just get the job done and that's it.

    mvs_sarma, you have many good points which i agree with. Writing in assembler , even if looks monster and painfull, have it's advantages. I wish i could go back and learn Assembler first.. bah too late

    At least, someone's beginning programming in assembler will probably learn better how to use, set-up, the internal PIC ressources... as there's nothing already done. Let's say ADCIN, HSEROUT etc etc. Better hardware understanding.

    Also it force the programmer to use it's brain a little bit much. Let's say someone want to compute a multicondition IF THEN ELSE like
    Code:
    IF (ByteA<300) AND (ByteC>=ByteA) AND (ByteC+ByteD<127) then...
    Obviously, knowing how many assembler instruction you have, and what's available, he will spend more time to write the code than with any compiler.

    But both will produce the same result, one will be faster to write.

    Better because it's written in assembler? no, 'cause both work. Maybe one may need more codespace... but less time to write.

    I will stop here and stick on my opinion. Nothing is better, if the final code/product works as expected and bug-free.

    Sure i don't reject any language advantages. You just have to trust the compiler you're using.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Code:
    IF (ByteA<300) AND (ByteC>=ByteA) AND (ByteC+ByteD<127) then...
    If ByteA really is a byte then the first condition will always be true

    Not having a dig Steve, just posting something to make the "you have not posted for a while" message go away. LOL
    Keith

    www.diyha.co.uk
    www.kat5.tv

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


    Did you find this post helpful? Yes | No

    Post Few Tips

    Quote Originally Posted by keithdoxey View Post
    Code:
    IF (ByteA<300) AND (ByteC>=ByteA) AND (ByteC+ByteD<127) then...
    This is an extremely inefficient, code space consuming argument.<hr/>
    Here's a better approach that will use much less code space and probably be a lot faster too.<hr/>
    Code:
    IF ByteA<300 THEN
       IF ByteC>=ByteA THEN
          IF (ByteC+ByteD<127 THEN
          'do something
          ENDIF
       ENDIF
    ENDIF
    Willing to bet this is about 20-30 bytes shorter.
    <br/>

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


    Did you find this post helpful? Yes | No

    Post Select Case - By far the best way!

    Using Select Case is by far the very best methodology for implementing well structured decision making procedures. I'm a little uncertain as to just how advantageous it can be in PBP, but in Visual Basic, it's a god sent!

    Consider the following:
    Code:
    SELECT CASE UserInput
    
       CASE 1
               GOSUB Temperature
               LOW LED
               
       CASE 2
               GOSUB LightLevel
               HIGH LED
    END SELECT
    <hr/>
    Much easier to read and much faster. Select Case is a much more efficient, IF statement equivalent. However they can at times be a bit quirky for certain things.
    <br/>

  5. #5
    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/>

  6. #6
    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/>

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default i knew this was going to happen...

    <table><tr><td></td><td>It wasn't meant to be a 'how to create efficient code' tutorial or contest, but just an example.

    Who i'm i anyway ?</td></tr></table>

    FYI, in PBP Select Case will be a little less code efficient (talking about code size) than multiple IF-THEN-ELSE... as with ALL other language anyway. Select Case is just easier to read, modify, implement. Save your finger nails...

    We are really far of the original question...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by mister_e View Post
    FYI, in PBP Select Case will be a little less code efficient (talking about code size) than multiple IF-THEN-ELSE... as with ALL other language anyway. Select Case is just easier to read, modify, implement. Save your finger nails...
    Try making a Nintendo Emulator in VB using IF's as opposed to Select Case. There's about a %25 difference in speed.

    Code:
       Select Case instruction(opcode)
              Case INS_JMP: ' jmp6502
                   adrmode opcode
                   PC = savepc
               Case INS_LDA: ' lda6502
                   adrmode opcode
                   a = Read6502(savepc)
                   SetFlags a
               Case INS_LDX:
                   adrmode (opcode)
                   x = Read6502(savepc)
                   SetFlags x
               Case INS_LDY
                   adrmode (opcode)
                   y = Read6502(savepc)
                   SetFlags y
               Case INS_BNE: bne6502
               Case INS_CMP: cmp6502
               Case INS_STA
                   adrmode (opcode)
                   Write6502 savepc, a
               Case INS_BIT: bit6502
               Case INS_BVC: bvc6502
               Case INS_BEQ: beq6502
               Case INS_INY: iny6502
               Case INS_BPL: bpl6502
               Case INS_DEX: dex6502
               Case INS_INC: inc6502
               Case INS_DEC: dec6502
               Case INS_JSR: jsr6502
               Case INS_AND: and6502
               Case INS_NOP:
        
               Case INS_BRK: brk6502
               Case INS_ADC: adc6502
               Case INS_EOR: eor6502
               Case INS_ASL: asl6502
               Case INS_ASLA: asla6502
               Case INS_BCC: bcc6502
               Case INS_BCS: bcs6502
               Case INS_BMI: bmi6502
               Case INS_BVS: bvs6502
               Case INS_CLC: p = p And &HFE
               Case INS_CLD: p = p And &HF7
               Case INS_CLI: p = p And &HFB
               Case INS_CLV: p = p And &HBF
               Case INS_CPX: cpx6502
               Case INS_CPY: cpy6502
               Case INS_DEA: dea6502
               Case INS_DEY: dey6502
               Case INS_INA: ina6502
               Case INS_INX: inx6502
               Case INS_LSR: lsr6502
               Case INS_LSRA: lsra6502
               Case INS_ORA
                    adrmode opcode
                    a = a Or Read6502(savepc)
                    SetFlags a
        
               Case INS_PHA: pha6502
               Case INS_PHX: phx6502
               Case INS_PHP: php6502
               Case INS_PHY: phy6502
               Case INS_PLA: pla6502
               Case INS_PLP: plp6502
               Case INS_PLX: plx6502
               Case INS_PLY: ply6502
               Case INS_ROL: rol6502
               Case INS_ROLA: rola6502
               Case INS_ROR: ror6502
               Case INS_RORA: rora6502
               Case INS_RTI: rti6502
               Case INS_RTS: rts6502
               Case INS_SBC: sbc6502
               Case INS_SEC: p = p Or &H1
               Case INS_SED: p = p Or &H8
               Case INS_SEI: p = p Or &H4
               Case INS_STX
                    adrmode (opcode)
                    Write6502 savepc, x
               
               Case INS_STY
                    adrmode (opcode)
                    Write6502 savepc, y
               Case INS_TAX: tax6502
               Case INS_TAY: tay6502
               Case INS_TXA: txa6502
               Case INS_TYA: tya6502
               Case INS_TXS: txs6502
               Case INS_TSX: tsx6502
               Case INS_BRA: bra6502
          End Select
    (This procedure is not my code, but I wish it was)
    Last edited by T.Jackson; - 6th May 2007 at 13:58.

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


    Did you find this post helpful? Yes | No

    Post Reason why Select Case is faster!

    Main reason why Select Case is faster than using multiple IF's is because not all conditions are checked, only the first true condition in a Select Case argument has its underlying block of code executed.

    That's my theory on it anyway.

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, 01:06
  2. help converting assembely program
    By ahmed_salah in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 7th August 2008, 15:28
  3. How do you learn best?
    By T.Jackson in forum Off Topic
    Replies: 41
    Last Post: - 30th May 2008, 14:32
  4. Who wants to learn...
    By Stoverus in forum Off Topic
    Replies: 1
    Last Post: - 21st October 2006, 07:08
  5. How to learn PIC BASIC compiler in 7 days?
    By luqman83salleh in forum General
    Replies: 2
    Last Post: - 13th August 2004, 14: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