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 > again variables in function

#12927 - shadow_gg - Mon Dec 01, 2003 1:24 pm

hello,got a problem accessing variables in a function
in fact still not resolved since last time :/
it compiles but it seems it doesn't read the variable sky
r3 don't get the correct value of sky
it displays me strange data

blitasm()
{
void *sky=(void *)(0x8000000+SIZE_ROM+SIZE_PAL+SIZE_IMAGE+SIZE_MAP);
asm volatile("
.ALIGN
.ARM

ldr r0,=screen
ldr r0,[r0]
ldr r3,%0
ldr r3,[r3]
ldr r2,=9600
boucle:
ldr r1,[r3],#4
str r1,[r0],#4
subs r2,r2,#1
bpl boucle
.pool
":/*no output*/:"m"(sky):"r0","r1","r2","r3");
}
but when declaring sky global
doing ldr r3,=sky
ldr r3,[r3] it works ?
:/
what happens?

I know it's better to write in a separate .s file,but more simple for me to write in C functions.

#12928 - Paul Shirley - Mon Dec 01, 2003 2:25 pm

removed

Last edited by Paul Shirley on Sun Mar 28, 2004 9:32 pm; edited 1 time in total

#12929 - shadow_gg - Mon Dec 01, 2003 2:45 pm

thx
but sky is not a constant bcs SIZE_ROM is a variable (int)
and I need to read from memory
wanna convert another function where there are lot of variables,
and I can't have all these variables at the same time in register

why %0 don't represent sky ?

#12932 - poslundc - Mon Dec 01, 2003 4:32 pm

Take out the fourth line:

Code:

   ldr r3,[r3]


Also, it's helpful to people if you post in the same thread you used before, so they can see what previous answers were.

Dan.

#12933 - DekuTree64 - Mon Dec 01, 2003 5:20 pm

Try this in a .s file:
Code:

.GLOBAL blitasm
.ALIGN
.ARM
blitasm:
ldr r0,=screen
ldr r0,[r0]
mov r3, #0x8000000
ldr r2, =SIZE_ROM
ldr r2, [r2]
add r3, r3, r2
ldr r2, =SIZE_PAL
ldr r2, [r2]
add r3, r3, r2
ldr r2, =SIZE_IMAGE
ldr r2, [r2]
add r3, r3, r2
ldr r2, =SIZE_MAP
ldr r2, [r2]
add r3, r3, r2
ldr r2,=9600
boucle:
ldr r1,[r3],#4
str r1,[r0],#4
subs r2,r2,#1
bpl boucle
.pool


Assuming that all those things are variables (you should really go with the standard naming style of variables starting with small letters, and constants being all caps with underscores for spaces, so it's clear to other people what things are), that will load them in and add them up to compute sky inside the ASM block. That way you don't need to use inline ASM at all, and thusly will have no weird problems that noone knows for sure how to fix.

ALthough I think Dan is right about just removing that ldr r3, [r3].
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#12934 - shadow_gg - Mon Dec 01, 2003 5:26 pm

yeah he was right
thx