Shop OBEX P1 Docs P2 Docs Learn Events
Using IND as register -- works with all instructions? — Parallax Forums

Using IND as register -- works with all instructions?

ZootZoot Posts: 2,227
edited 2008-08-11 16:25 in General Discussion
I'm modifying this project -- http://forums.parallax.com/showthread.php?p=703230 -- so that in addition to running servos, the SX board handles encoders, velocity control, real-time ramping, etc. (the final output goes to an MD22 motor controller). I've got everything pretty much the way I want, but had to convert much of the code to assembly so I could get it all to fit, esp. when dealing with lots of variables across all the banks.

So.... I have a number of cases where my code space is much much tighter presuming that I can use IND whereever I would use a normal register (presuming FSR is set correctly ahead of time).

E.g.

MOV W, #registers
ADD W, globalIndex
MOV FSR, W

CJA IND, globalB1, @:decit
CJB IND, globalB1, @:incit
JMP @:done

:decit
DEC IND
SKIP
:incit
INC IND

:done




Presuming this will work? Most of the code I see with IND tends to be CLRs and MOVs, etc.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php

Comments

  • BeanBean Posts: 8,129
    edited 2008-08-11 13:09
    Zoot,
    As long as FSR doesn't change, yes you can use IND as a global byte variable.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson

    "It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter

    www.iElectronicDesigns.com

    ·
  • ZootZoot Posts: 2,227
    edited 2008-08-11 15:19
    Cool. I'm actually getting a real handle on FSR manipulation. Gets me much more compact code.

    Quasi related question re: FSR and IND.

    The BANK instruction (ASM) sets only the upper 3 bits (SX28) or upper 4 bits (SX48) and *leaves the lower 4 bits alone*. Is that right? If so then I can really compact my code because I have a number of routines where the app needs to access the same indexed registers from more than one bank (in this case, say, I have servo ramp values, positions, accumulators, stored in 4 banks). In the past I've set bits manually on the FSR to jump back and forth and realized there has to be a better way smile.gif

    I.E., would this work?

    ' say pos is BANK 1, ramp is BANK 2, acc is BANK 3
    ' I want to access the 3rd reg in B1, 3rd reg in B2, etc
    MOV globalIndex, #3 
    
    MOV W, #pos
    ADD W, globalIndex
    MOV FSR, W ' FSR = $33
    
    MOV IND, globalB1
    
    BANK #ramp    ' FSR = $53
    MOV globalB1, IND
    
    BANK #acc  ' FSR = $73
    MOV IND, globalB1
    
    



    And if that works, then can I also just use a MOV FSR followed by a bank for circumstances where that is convenient and clear (for me)i.e.

    MOV W, #3
    MOV FSR, W  ' FSR = $x3
    
    BANK #ramp    ' FSR = $53
    MOV globalB1, IND
    
    BANK #acc  ' FSR = $73
    MOV IND, globalB1
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-08-11 15:42
    Zoot,
    The banked memory allows for even better optimization for multiple identical code,
    for example receive uarts, because not only can you use IND but also direct addressing.
    See the attached file which is a header for a uart library that I am writing.
    Note the uart fields as being declared in the ram area $10-$1F.
    The code is written as a macro and will only be inserted once in the program.
    But this code can be called with FSR set to any bank, eg. $30, $40 or $E0 etc.
    The direct addressed registers are actual at the offsets in the bank addressed by FSR.
    So this code can support multiple receive uarts without writing code for each of
    those uarts seperately. All that needs to be done is to set some registers and this can be done
    from a datatable (that 's how I do it in my library).

    regards peter
  • ZootZoot Posts: 2,227
    edited 2008-08-11 16:25
    Peter -- sure. I get it! What an epiphany. Makes me want to go back and recode all my older (inefficient) projects smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.