Shop OBEX P1 Docs P2 Docs Learn Events
Speed questions — Parallax Forums

Speed questions

UghaUgha Posts: 543
edited 2009-02-15 23:29 in General Discussion
What is faster when looking up 10 numbers:
lookup
data/read
on
if/else chain?

Or is there an even faster method?

Comments

  • InSilicoInSilico Posts: 52
    edited 2009-02-15 14:37
    the fastest method I know for looking up numbers is using a table, for example·in SX Assembly for the IEC 60063 E12 numbers:
    E12Table
      jmp     pc+w
      retw    10 ;0
      retw    12 ;1
      retw    15 ;2
      retw    18 ;3
      retw    22 ;4
      retw    27 ;5
      retw    33 ;6
      retw    39 ;7
      retw    47 ;8
      retw    56 ;9
      retw    68 ;10
      retw    82 ;11
    

    you load the index into w before calling this subroutine to get the indexed value:
    mov     w, #8
    call    E12Table
    ; w register now contains '47'
    

    hope this helps!
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-02-15 16:57
    You might want to explore SX/Sim -- it will help you answer these questions without having to connect to an SX. SX/Sim gets installed with the IDE and Guenther provides updates in a sticky post at the top of this forum.
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2009-02-15 23:29
    Ugha--

    The fastest way I know of to look up anything is in a look up table, no matter the language. My answer is overly simplistic because other factors are involved; type of data, data length, amount of data, and language are a few that come to mind. Many times, look up tables are appropriate in an application. Many times, look up tables are not appropriate in an application. That is why folks want to see your code, I imagine.

    If you ask me a specific question about SX/B, I cannot answer it. In fact, I would have to ask YOU the question! [noparse]:)[/noparse]

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
Sign In or Register to comment.