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.

Coding > Invalid constant error...

#8107 - regularkid - Wed Jul 02, 2003 6:37 am

I'm trying to write an assembly function to wait for the vertical retrace period. Here's what I have so far:

Code:

.ARM
.ALIGN

.GLOBAL WaitVSync

WaitVSync:
     wait:
   mov   r0, #0x04000006
   ldrh   r0, [r0]

   cmp   r0, #160
   bne   wait

   bx   lr


However, when I compile with gcc I get this error:

Code:

Video.s: Assembler messages:
Video.s:43: Error: Invalid constant
MAKE: *** [RK_Video_ASM.o] Error 1


referring to this: #0x04000006. Since I am using ARM mode rather than THUMB, there should be no reason why this constant is too big for the register. Am I wrong? Any ideas to fix this? Thanks!
_________________
- RegularKid

#8110 - tepples - Wed Jul 02, 2003 8:44 am

A constant can be $smallnumber significant bits, rotated right by any even number of places. You have to build larger constants by or'ing them from several pieces (ARM only) or loading them from a PC-relative pool (ARM or Thumb). The easiest way to access the I/O registers is to load 0x04000000 into a register and then offset from that.

[EDIT: factual corrections]
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.


Last edited by tepples on Wed Jul 02, 2003 8:49 pm; edited 1 time in total

#8111 - torne - Wed Jul 02, 2003 8:57 am

Try:
Code:
mov r0, #0x04000000
ldrh r0, [r0,#0x6]


This will work for the low-numbered registers.

Torne

#8134 - regularkid - Wed Jul 02, 2003 5:20 pm

Thanks! Makes sense to me.
_________________
- RegularKid

#8143 - Darkain - Wed Jul 02, 2003 11:14 pm

Code:
swi 0x50000


try this out too. it wont kill the CPU. :)
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#8147 - funkeejeffou - Thu Jul 03, 2003 1:05 am

By the way, if your code doesn't work(wich won't be a surprise), try this :

ldr r0, =0x4000006
v_blank_loop
ldrh r1, [r0]
cmp r1, #160
ble v_blank_loop
bx lr

you must reload for each loop the value contained in 0x4000006, otherwise it won't update.

#8148 - funkeejeffou - Thu Jul 03, 2003 2:43 am

OOps sorry!!!!
didn't read well your code :-)
it works, but if I were you, I would use an extra register to store 0x4000006 outside the loop, you don't need to reload it's value each time as it is constant.

Sorry again all, shame on me:(