ASM CMP vs TEST INA
Jkane
Posts: 113
Hello,
Question How to test a pin in propeller asm?
I want to test pin 11 for 1 or 0 in assembler
I was thinking cmp ina,Pin_11, #1 would work but seems not
so I think that is has to be done with a test instruction
Test Value1,Value2 (and compare)
so I would define a mask,
:Pin_11_Bitmask long %00000000_00000000_00001000_00000000
Test ina,P_11, Pin_11 then jump on flags
but this does not work, (ie, I can't get this to work)
regards
Jeff
Question How to test a pin in propeller asm?
I want to test pin 11 for 1 or 0 in assembler
I was thinking cmp ina,Pin_11, #1 would work but seems not
so I think that is has to be done with a test instruction
Test Value1,Value2 (and compare)
so I would define a mask,
:Pin_11_Bitmask long %00000000_00000000_00001000_00000000
Test ina,P_11, Pin_11 then jump on flags
but this does not work, (ie, I can't get this to work)
regards
Jeff
Comments
Use: TEST <mask>,INA wc,wz ' or whatever combination of flags you want
The reason is that INA is a read-only register and must be specified in the source field of an instruction. If you put it in the destination (first) field of an instruction, what you're really referencing is the COG RAM location (shadow memory) corresponding to the INA register's address. This is also true of other read-only registers like CNT.
This is the asm code: The idea is to read bits off pin 11, write the data to an array and then write the array to spin for processing
Probably a little messy, but I'll see if it works
regards
Jeff
-- As Tom pointed out, the cog sees the hub as an array of bytes, not longs, so you need to update that line, e.g., add addr, #(28 * 4)
-- jump labels need to be preceded with #, e.g., jmp #skip_low
-- It appears you want to move the state of the rx pin into rxdata -- I would do this:
The second line is a little redundant; if you do it at initialization it doesn't need to be in this loop. You just need to set rxdata to zero before you use this loop.
Finally... the colon proceeding a label makes it local to the previous simple label; this allows you to use the same generic names in a listing -- like this:
The point is: use colons to denote local labels; using them otherwise is an easy way to introduce errors (IMHO).
ok,
on the spin side: rxdata is an array
on the assembler side:
so my intention was to capture the status of Pin 11, every 100us, write the status (high or low) to the RX data (which is an array), on both sides. (when I did arrays in assembler on other machines, it was set the absolute base address of the array, load a value, then relative offset the width of the array type (long, int and so on)) to the next position, and in this case loop 128 times and stop.
then on the spin side print the array.
so I cleaned up the code, but I'm not sure about the bytes, vs long, when I pass parms to and from asm i use rdlong and wdlong, but updating a array in assembler I use bytes? even if the array is long?
I originally did this in spin but the timing was not precise enough... so I moved on to asm.
regards
Jeff
I think this can be done in Spin if you structure your code properly. Have a look at the attached test program. It captures the RX pin to a byte array every 100us -- the timed portion of the code (capture loop) took 12824 microseconds. That very small error has to do with initializing t and starting the loop; the time between samples is 100us (using waitcnt and constant).
Spin certainly isn't as fast as PASM, but for a 100us loop with very little to do, it's no problem.
The last line has changed -- and it's 1.4us faster than the version using pointer and post incrementing (maybe that's where the speed is coming from). Anyway, when one is worried about microseconds, these things matter.
One of the [many] things I love about the Propeller is that I can use it to explore code style versus performance.
thanks, code works fine, there is a little offset because my clock is a 6.25, but that is minor.
regards
Jeff
But I noticed a few things that might help you understand the prop a little better...