indexing arrays in cog ram?
bob_g4bby
Posts: 546
In an in-line pasm2 method, I'm already using ptra and ptrb for indexing two arrays. But I need to read-modify-write some more small arrays in cog ram. I believe the ALTR instruction might help, but I could do with a simple example to make it clear. Please could someone write a little code to show how that might be done, please?
Cheers, bob

Comments
The PASM2 gurus will jump in if I'm wrong, but this seems to work. Note, though, that inline PASM code is transient so you this is impractical -- unless the need for the array is transient, too.
pub main() | x, y, z setup() wait_for_terminal(true) y := getct() repeat x from 0 to 7 y := ??y z := array_test(y, x) term.fstr3(@"%d %12d %12d\r", x, y, z) waitms(50) pub array_test(value, index) : result org ' write value to array altd index, #longarray mov 0-0, value ' read value from array alts index, #longarray mov result, 0-0 .done ret longarray long 0[8] endALTR would be used for indexed writes. ALTD is probably the one for read-modify-write. But if you're after indexing of both S and D operands together then ALTI is the only one that can do both at once. ALTx instructions always modify the next instruction, they can't be stacked like the AUGx or SETQ instructions can.
Thanks Jon, I expect that will get quite a lot of use. I'm currently writing a software defined radio. Your snippets will first get used in a method that corrects amplitude and phase imbalance in the i and q signals coming from the a/d converter at the receiver front end. If you don't correct, ghost images of strong signals can appear elsewhere in the band. I've seen this in action on a pc based radio when switching bands. On the spectrum display, the ghost signals fade over about 1/4 second as the correction iterates to a stable state.
Cheers, bob
Completely off-topic, I've just ordered an 8-way rotary encoder module. I've been recompiling every time a variable needed changing; so now it'll just be turning a knob. Each knob has a pushbutton built in and a multicolour LED alongside. The module speaks i2c, so your driver will get plenty of use. Seems like it's been raining continuously in the SW U.K. since new year - anyhow this is a fun wintertime project until the better weather comes in.