Shop OBEX P1 Docs P2 Docs Learn Events
How does LONG work? — Parallax Forums

How does LONG work?

Dr_AculaDr_Acula Posts: 5,484
edited 2012-02-18 19:30 in Propeller 1
I came across something odd just now when playing around with font files.

This is my simple code but it doesn't seem to work all of the time:
result := long[address]

I replaced it with this code which seems to work fine:
result := byte[address] | byte[address+1] << 8 | byte[address+2] <<16 | byte[address+3] <<24

I thought I was going a bit crazy as the LONG instruction initially did work and then I changed some code elsewhere and it wouldn't work. So I did some more experiments. Firstly, the array this is working on is a byte array, not a long array.

Second (and I think this is relevant), the array has been created by another program, and some of the longs are aligned on multiples of 4 and some are not. This is why it worked initially as the longs happened to be aligned in byte 0,4,8 etc. But later they got offset by two bytes.

But there is something even more strange, and I haven't had time to fully debug this, but if you fill some bytes, and then shuffle the address up by one at a time, the values that come back seem to change every 2 bytes. So every WORD, not every BYTE or LONG.

The fix with bitshifting bytes into longs seems to have solved the problem, but now I am having doubts about using the the long (or the word) instruction in other parts of my program.

Any help here would be most appreciated.

Comments

Sign In or Register to comment.