How to learn assembely?


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Iran
    Posts
    94


    Did you find this post helpful? Yes | No

    Default

    Hi, i have done alot of project in picbasic but i found that it has some problem,for example i found that in conditional instruction (if... then..),intrupt doesn't work.
    i wrote a program to read the keyboard(4*4) with conditonal instruction but RB0 interrupt didin't work but when i used RB0 interrupt in other programs without conditional instructions it worked ver well.
    so i think the best langauge is assembly.it's faster. conversion of the C or Pic basic to assembely or hex file is not optimal. in some project speed is very important so the best choice is assembly.

  2. #2
    Join Date
    Mar 2006
    Location
    Hyderabad (India)
    Posts
    123


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by amindzo View Post
    Hi, i have done alot of project in picbasic but i found that it has some problem,for example i found that in conditional instruction (if... then..),intrupt doesn't work.
    i wrote a program to read the keyboard(4*4) with conditonal instruction but RB0 interrupt didin't work but when i used RB0 interrupt in other programs without conditional instructions it worked ver well.
    so i think the best langauge is assembly.it's faster. conversion of the C or Pic basic to assembely or hex file is not optimal. in some project speed is very important so the best choice is assembly.
    I admit that I am no expert in these languages, but , to my little knowledge, any program written in HLL has to be compiled and you know what happens if you compile such a file. it looks into a pre wriitten code and uses a judicious part of the code available there. Perhpas over a period these HLLs are revised to cover difficiencies. --that is the reason you find that a particular suppliers Basic otr 'C' is better than others etc,

    thus ifeel there is nothing wrong, ifct it is better to write(be able to write) in assy language. aprogram written by a skilled writer in assy is much better than a compiled Basic or C-- of course my personal feeling.
    Regards,
    Sarma

  3. #3
    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.

  4. #4
    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

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

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

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

  8. #8
    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.

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