allignment of VARiables in memory
janb
Posts: 74
Hi,
I was expecting the memory allocated·in the VAR block matches seqence of definitions.
I'm puzzeld why
VAR
·· byte a[noparse][[/noparse]4]
·· word w1,w2
·· byte x···
results with
@x-@w2= 6
x·follows w2 and the difference in adresses should be equal to the size of word=2 ?
If I change dimention of a[noparse][[/noparse]4]-- >a[noparse][[/noparse]8] I'd get
@x-@w2= $A· which is 2+8
If I move decalartion of a[noparse]/noparse below declaration of x· I'd get 2 as difference - as expected.
The example code is attached.
Could you point where·my logic breaks?
Thanks
Jan
I was expecting the memory allocated·in the VAR block matches seqence of definitions.
I'm puzzeld why
VAR
·· byte a[noparse][[/noparse]4]
·· word w1,w2
·· byte x···
results with
@x-@w2= 6
x·follows w2 and the difference in adresses should be equal to the size of word=2 ?
If I change dimention of a[noparse][[/noparse]4]-- >a[noparse][[/noparse]8] I'd get
@x-@w2= $A· which is 2+8
If I move decalartion of a[noparse]/noparse below declaration of x· I'd get 2 as difference - as expected.
The example code is attached.
Could you point where·my logic breaks?
Thanks
Jan
Comments
-Phil
I see.
In the fullDuplexSerial code there is a bunch of variables allocated in SPIN and the actual data transmision is done in assembler, assuming the order of variables as in SPIN VAR-block. Does it mean it works correctly only because all variables·were declared as long?
In other words, if I want to use some set of variables as a FORTRAN-style common block and pass only address of the first one I'd better decalre all of them as long to avoid surprises?
Thanks
Jan