Using IND as register -- works with all instructions?
Zoot
Posts: 2,227
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.
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
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
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
·
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
I.E., would this work?
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php