Confusion about @, @@, @@@, ...
David Betz
Posts: 14,516
I'm trying to debug some code that I wrote that requires a 16 byte aligned address. This is the code I wrote to accomplish that but I'm not sure it's working correctly. In particular, I'm not sure I'm using the @ operator correctly. The manual says something about runtime vs. compile time but I'm not sure I understand the difference. Should this work?
PUB init mm_data_ptr := (@mm_data_padded + 15) & !15 DAT mm_data_padded long 0[2048+15] mm_data_ptr long 0
Comments
-Phil
Andy
This will work since mm_data_padded is already long-aligned, so you just need to allocate 3 extra longs to allow for 16-byte, or 4-long alignment.
EDIT: Ariba's code looks good to me. I need more coffee.
EDIT2: Ariba's code would use slightly less memory if you replace "byte 0[15]" with "long 0[3]".
-Phil
long 0[3] might have padding before it, but it wouldn't have any padding after it.
EDIT: "byte 0[12]" or "long 0[3]" is sufficient.
-Phil
But there's nothing at all wrong with:
Note that I moved the label. It's because of the +15 in your (original) address computation. Without the +15, the label belongs on the following line.
-Phil
or like that:
Andy
The DAT section ends up first in the binary output of an object, and the compiler pads objects as well so the other objects DATs in the same binary will be aligned also. Even if it wasn't the only DAT in the file it's extremely like that it would be 4 byte aligned.
I agree that in the general case a byte 0[15] might not be the same a byte 0[16], but in the example given it is. That's all I was saying. Plus, the obvious choice is to use long 0[3] anyway.