Aliasing array names
Kurt
Posts: 7
Hi:
I want to call a subroutine to do some 32 bit math. I plan on using the Pbasic array funtion to define four byte variables for the input arguments. For the sake of this discussion, lets assume 3 different 32 bit variables defined as argA(4), argB(4), and argC(4).
Let's say that I want to multiply by 2 (<<) Here's the code:
So here's the question: How can I call "Shifter" for each of argA, argB, & argC? Is there a way to alias them to "argument" (in my sample code)? Or will I need to "hard code" this routine for each array?
Thanks in advance,
kk
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
kk
I want to call a subroutine to do some 32 bit math. I plan on using the Pbasic array funtion to define four byte variables for the input arguments. For the sake of this discussion, lets assume 3 different 32 bit variables defined as argA(4), argB(4), and argC(4).
Let's say that I want to multiply by 2 (<<) Here's the code:
Shifter: FOR index = 0 TO 2 ' Shift argument left (multiply by 2) temp.HIGHBYTE = argument(index) temp.LOWBYTE = argument(index + 1) temp = temp << 1 argument(index) = temp.HIGHBYTE NEXT argument(3) = temp.LOWBYTE RETURN
So here's the question: How can I call "Shifter" for each of argA, argB, & argC? Is there a way to alias them to "argument" (in my sample code)? Or will I need to "hard code" this routine for each array?
Thanks in advance,
kk
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
kk
Comments
byte argA(4)
use
notice that they are not defined explicitly as an array. Because of the way the Stamp works, you can still address them as an array. For example, argA0 can be addressed as argA0(0), and argA1 can be addressed as argA0(1), and argC1 can be addressed as argA0(5), or as argC0(1). You see? That method it turns out is actually much more flexible than defining array variables explicitly, and it is a frequent tool of intermediate to advanced PBASIC programmers.
If you define argA, argB and argC in that order, one right after another, then that is exactly how they will be arranged in Stamp memory, and you could write a routine like the following:
Note the last element in the first statement. argA0.bit0(x*16+7). This is where the flexibility of the implicit array addressing shows its steroids. That statement picks off the bit that has to be shifted up to the high word. Bits in words come in multiples of 16, and you want the 7th bit up in the least significant word.
I hope that helps with what you are trying to do.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
argA0.bit0(x*16 +7) '
in the above program, and he was right, I should have used
argA0.bit0(x*16+15) '
The idea is to pick off the msb of the least significant WORD, and transfer it up to become the lsb in the most significant WORD.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
kk
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
kk