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 > Globals help

#1930 - regularkid - Sun Jan 26, 2003 3:12 am

Hi. I'm using C and ASM together and am trying to do this: I have a global variable in one of my C files that I want to access in my ASM files. So, in my C file it looks like this:

Code:

...
u16* videoBuffer =(u16*)0x06000000;
...


and so this is what my ASM file looks like:
Code:

...
.EXTERN videoBuffer
...
ldr r0, =videoBuffer
ldr r1, =0xFFFFFFFF
str r1, [r0]
...


(the ... means that there is more code here but it's not important so I left it out). So this should put two white pixels at the top left corner of the screen (MODE 3). But this doesn't work. However, this DOES work:

Code:

...
.EXTERN videoBuffer
...
ldr r0, =0x06000000
ldr r1, =0xFFFFFFFF
str r1, [r0]
...


Can someone please explain to me how to use a global variable from a C file in my ASM files? Is there something I'm missing? Thanks!
_________________
- RegularKid

#1933 - zeuhl - Sun Jan 26, 2003 8:28 am

well, this piece of code :

Code:
ldr r0, =videoBuffer


will store the address of the videoBuffer variable into r0. to get its value (the 0x06000000 number), perform the following :

Code:
ldr r0, =videoBuffer
ldr r0,[r0]


I guess a "mov r0,#0x06000000" should be faster in this case.

#1951 - regularkid - Sun Jan 26, 2003 6:30 pm

Thanks!
_________________
- RegularKid