How does LONG work?
Dr_Acula
Posts: 5,484
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:
I replaced it with this code which seems to work fine:
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.
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
And aaaaaarrrrrggghhh http://forums.parallax.com/showthread.php?138010-Bugs-in-quot-Parallax-Serial-Terminal-quot-object
That is the hex debug code I was using. Debugging is fun!
I think you can write this as:
Andy
I'm working on fixing the font file so it is aligned with longs. Neater that way and easier to read in a hex editor.