Problem with MUXC instruction (I think)
I have hit a wall on the code segment below. From another Cog, I have populated a large area of HUB Ram and the Cog in question reads a portion of that HUB Ram and places it in a table "OutputImageTable" using MOVD in a loop. This table is 48 Longs.
I have verified using Gear, that all the data in the "OutputImageTable" is correct. I have also used PropTerm to verify this data.
The code segment loops and takes 1 word at a time from the table and based upon a Bit pointer, should set/clear one of the output pins based on the MUXC instruction. This is the area that seems to fail.
The MUX_BitPointer· pointer serves 2 functions. First it is used in an "AND" with the table word and if the single bit in MUX_BitPointer and a corresponding bit in the table word are both set, I believe that the "C" flag should be set as this would be an ODD number of bits [noparse][[/noparse]1]. I then use that "C" flag in the MUXC instuction to set/clear the proper output pin but what sounds good on paper does not work so my logic must be flawed.
If I can get the output bits set/cleared (they never get set) then the ClockSet and ClockClear calls will clock that data into 16 external shift registers.
The intent of the loop is to evaluate a given bit position on each of 16 table longs, set the output pin then repeat this 32 times until all the bits have been sent to the output pins.
I would appreciated if one of the group could spot my dumb mistake.
I have verified using Gear, that all the data in the "OutputImageTable" is correct. I have also used PropTerm to verify this data.
The code segment loops and takes 1 word at a time from the table and based upon a Bit pointer, should set/clear one of the output pins based on the MUXC instruction. This is the area that seems to fail.
The MUX_BitPointer· pointer serves 2 functions. First it is used in an "AND" with the table word and if the single bit in MUX_BitPointer and a corresponding bit in the table word are both set, I believe that the "C" flag should be set as this would be an ODD number of bits [noparse][[/noparse]1]. I then use that "C" flag in the MUXC instuction to set/clear the proper output pin but what sounds good on paper does not work so my logic must be flawed.
If I can get the output bits set/cleared (they never get set) then the ClockSet and ClockClear calls will clock that data into 16 external shift registers.
The intent of the loop is to evaluate a given bit position on each of 16 table longs, set the output pin then repeat this 32 times until all the bits have been sent to the output pins.
I would appreciated if one of the group could spot my dumb mistake.
PlaceDataToOutput
mov tmpOutImage, #0
mov MUX_BitPointer, #1
mov BitCounter, #0
NextSetOfBits
mov RankCntr, #0 'Clear Rank counter
mov tbl_Output_Ptr,#OutputImageTable 'Should move the first address of OutputImageTable to tbl pointer
add BitCounter, #1
mov MUX_BitPointer, #1
ReadTableRank_W1 'This routine reads the 1st word of each rank, shift all 32 bits to the outa register
call #ClockClear
movs ModifySrcAddr,tbl_Output_Ptr 'Change Source address for instruction @ label ModifySrcAddr
add tbl_Output_Ptr,#3 'Get 1st of 3 words for each rank (3 words/rank)
ModifySrcAddr mov tmp1, 0_0 'Pull data from table and place in tmp1. Source address is fed by MOVS above
and tmp1,MUX_BitPointer wc 'C flag should be set if odd number of bits in result
muxc outa, MUX_BitPointer 'Whatever bit is set in MUX_BitPointer will be set/cleared based on C flag
add RankCntr, #1
cmp RankCntr, #MAX_CHROMATIC_RANKS wc, wz, nr
if_b jmp #ReadTableRank_W1 'IF < than max number of ranks get next word from table
shl MUX_BitPointer, #1 'Check next bit position in every rank
call #ClockSet '16 output bits have been set clock them to external Shift Register
cmp BitCounter, #32 wc,wz, nr 'have all bits been set
if_nz jmp #NextSetOfBits
jmp #MainLoop 'REMOVE

Comments
Thanks for look at this.
When being unable to see the wood because of all the trees, I generally remove what is not relevant (the comments!!! If wrong they might terribly block you!
Second I start obtimizing, i.e. "transforming" the program. This is what came out:
PlaceDataToOutput mov MUX_BitPointer, #1 NextSetOfBits mov RankCntr, #MAX_CHROMATIC_RANKS MOVD ModifyDestAddr, #OutputImageTable mov MUX_BitPointer, #1 <---- The CULPRIT!!!!! REMOVE THIS LINE ReadTableRank_W1 ModifyDestAddr and 0-0, MUX_BitPointer wc, NR muxc outa, MUX_BitPointer add ModifyDestAddr, threeForDest DJNZ RankCntr, #ReadTableRank_W1 shl MUX_BitPointer, #1 WZ IF_NZ JMP #NextSetOfBitsAgain, thanks for looking at this.
Thanks for looking at this and I'll post the results.