gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > Some problems with storing data

#25926 - ProblemBaby - Tue Aug 31, 2004 8:32 pm

Iam trying to store some values in a C-struct.

This works fine
Code:

LDR r3, =myStruct
STRH r0, [r3]


But this doesnt I got junk
Code:

LDR r3, =myStruct
STR r0, [r3]


The Variable in the struct is s32 I cant understand!

#25929 - sajiimori - Tue Aug 31, 2004 10:37 pm

Is r3 4-byte aligned?

#25933 - phonymike - Wed Sep 01, 2004 6:34 am

if the varialbe loaded isn't signed, it's because you need to use LDRSH (load a signed 16bit value)

#25934 - ProblemBaby - Wed Sep 01, 2004 9:25 am

r0 is a signed value
and r3 should be 4-byte aligned.

The thing was that it works fine if I use STRH but
I want to be able to set it to bigger and negative values too.

Code:

STRH r0, [r3]
STRH r0, [r3,#2]


this also works

#25936 - ProblemBaby - Wed Sep 01, 2004 11:30 am

when I do like this:

Code:

LDR r3, =myStruct
loop:
B loop:


and look at the value in VBA disassembler
r3 = 7
how is that possible???
it works when I do in thumb code.
then r3 isnt 4-byte aligned how do I fix it?

#25939 - sajiimori - Wed Sep 01, 2004 5:24 pm

In GNU C:
Code:

#define ALIGN __attribute__((aligned (4)))
int x ALIGN;

Or in GNU ARM:
Code:

.align
x: .word 0

#25957 - ProblemBaby - Wed Sep 01, 2004 9:24 pm

Thanks