PDA

View Full Version : Array in Assembly Works Weird



Jamesx
02-05-2007, 12:28 AM
Team:

I amtrying to sort out an array in assembly, using methods outlines awhile ago in thread
http://forums.parallax.com/forums/default.aspx?f=25&m=148004

I've gotten something to work, but it works only partially and in a fashion that I do not understand.




'there is something wrong here. I cannot find it.
mov t2, #16
Loop_16
mov zz, #LED_0-1
add zz, t2 ' address of LED_0 - 1 in zz
movs yy16, zz ' address of LED_0 - 1 + t2 to yy16 source
yy16 mov ShiftVal, 0-0 ' LED_0[t2] > ShiftVal'
shl ShiftVal,#25 ' only lowest 7 bits to be shifted out
mov t3, #7 ' t3 is number of bits to shift out'
call #shiftBits
djnz t2, #Loop_16
'...

shiftBits nop
Bits rol ShiftVal,#1 wc ' C flag set to Value's original bit 31.
muxc outa, SIN ' mux it into SIN pin, and pulse SCLK pin
or outa, SCLK ' after Read, then cycle CLK High
andn outa, SCLK ' CLK Low
djnz t3, #Bits ' loop thru Bits 7 times
andn outa, SIN ' Leave SIN low at end of shiftout
shiftBits_Ret ret

'...
LED_0 long %00000000
LED_1 long %00000000
LED_2 long %00000000
LED_3 long %00000000
LED_4 long %00000000
LED_5 long %00000000
LED_6 long %00000000
LED_7 long %00000000
LED_8 long %00000000
LED_9 long %00000000 'this does not turn on LED
LED_10 long %00001000 'this turns on LED
LED_11 long %00000000
LED_12 long %00000000
LED_13 long %00000000
LED_14 long %00000000
LED_15 long %00000000




In the above code, the each LED_n indicates the power level of a different LED. These registers, 7 bits, are to be shifted out as to an LED driver chip (TLC5923) MSB first, starting with LED_15. There is an LED connected to a the 9 pin of the LED driver.

I would have thought the above code would adjust the LED on pin 10, but no. This code adjusts the LED on pin 9. There is something apparently something wrong somewhere but I am stumped. Any ideas would be appreciated.

Thanks,

Jim C

inservi
02-05-2007, 01:18 AM
Hello,
I not yet started to learn the Propeller assembly but i think that you must declaring each element as byte and not as long or initialize 32 bits not 8 ?

Best regards,
dro

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
in medio virtus

Jamesx
02-05-2007, 02:38 AM
dro

Thanks for the idea. But I don't think that's it. I am able to manage the 32 bit longs OK. It seems to be in the indirect addressing part (MOVS) of the first loop.

Jim C

Mike Green
02-05-2007, 02:40 AM
You have to have at least one instruction between something that modifies an instruction and the instruction itself. Try inserting a NOP just before yy16.

Jamesx
02-05-2007, 03:15 AM
Mike:

Ahh... It all becomes clear. It works now.

In the earlier thread mentioned, you had said "note there's a 1 instruction delay because the Propeller fetches instructions ahead of time." I couldn't figure out what you were talking about, as there is no mention of this being problem in the manual under MOVS. But after banking my head against the wall for an hour without success, and seeing it work with the silly NOP, it all makes sense.

Thanks!

Jim C