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 > Problem with macro for gas

#177754 - Jim - Thu Feb 07, 2013 8:00 pm

Hi,

I've worked on a project a while ago, where I dissassembled some ARM-Code and had some problems with bl-commands. Here is a copy of the description on what I worked.

Code:

/*
"blown" is my own bl-command, because the most
bls go to an adress that isn't already
dissassembled, so I had to write a function
that makes a command that goes to an address
that isn't already included.
      blown   0x3710, 0x2CC
Here we're at address 0x2CC and want to jump to 0x3710

y = current adress, where the command is
x = address where the jump goes to
*/
.macro   blown   x=0, y=0
.hword   0b1111000000000000 | ((((\x-\y)>>12)&0b11111111111))
.hword   0b1111100000000000 | ((((\x-(\y+2))>>1)&0b11111111111)-1)
.endm


I've searched for an automatic way to get the current address (so that I don't have to set "y"), but found nothing that worked. Maybe someone here knows how to do it. Although my code works, it will only work as long as I don't change the code too much.

#177755 - Dwedit - Thu Feb 07, 2013 8:43 pm

I'm having difficulty understanding what you're trying to do here. Are you trying to hack a NDS program? That's the only way I'd ever see valid addresses less than 02000000, since that might be a valid address in ITCM on the NDS.

You can use $ to get the current address, then you can subtract that from another label to get a relative address. Something like ($ - someLabel). The address and label must be in the same section in the same source file.

Absolute addresses aren't generated until link time. During link-time, only really simple math can be used on addresses, specifically, adding a constant. So to get around that, make your addresses relative to something instead of absolute.

But if you have your memory map set up correctly (including the custom linkscript), you should be able to directly use b and bl instructions exactly as they are written.
If you are patching code, you probably should be using a different assembler for that.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."