WiiRd forum

Wii & Gamecube Hacking => Wii Game hacking help => Topic started by: Bonzai7 on May 31, 2009, 01:59:14 PM

Title: asm branches (I think there was another thread like this)
Post by: Bonzai7 on May 31, 2009, 01:59:14 PM
Okay, I want to have something like this:

b       0x80012488

from, what I gathered, that is a big no-no, as that address comes out negative. Could someone explain what I should have in layman's terms? Also, the values must be written in decimal if I'm using Link' awesome tool correct? If so, does that apply to addresses too?  Thank you prior.
Title: Re: asm branches (I think there was another thread like this)
Post by: Y.S. on May 31, 2009, 02:28:30 PM
Quote from: Bonzai7 on May 31, 2009, 01:59:14 PM
Okay, I want to have something like this:

b       0x80012488

from, what I gathered, that is a big no-no, as that address comes out negative. Could someone explain what I should have in layman's terms? Also, the values must be written in decimal if I'm using Link' awesome tool correct? If so, does that apply to addresses too?  Thank you prior.

You can specify hex numbers by prefixing 0x to them.
e.g. these two have exactly the same meaning:

li r0,99
li r0,0x63

As for branch instruction, you need to specify the offset to the target address instead of the target address itself.
But the offset cannot be calculated in C2 code because we cannot know where the C2 code will be stored.
So I recommend using absolute branch macro like the following:

/*Absolute branch*/

.macro  ab symbol
lis r12,\symbol@h
ori r12,r12,\symbol@l
mtctr r12
bctr
.endm


Just copy/paste the code to the left box in the ASM <> Wiird convertor, and modify the branch instruction as follows:

ab       0x80012488
Title: Re: asm branches (I think there was another thread like this)
Post by: Bonzai7 on May 31, 2009, 06:50:25 PM
Ah, the great Y.S. Thanks for explaining that. So the final code would be:
C2000000 00000003
3D808001 618C2488
7D8903A6 4E800420
60000000 00000000

correct?
Title: Re: asm branches (I think there was another thread like this)
Post by: paprika_killer on May 31, 2009, 07:21:37 PM
wait, can the the convertor work with macros?
Title: Re: asm branches (I think there was another thread like this)
Post by: Romaap on May 31, 2009, 08:08:05 PM
Quote from: paprika_killer on May 31, 2009, 07:21:37 PM
wait, can the the convertor work with macros?
lol, yeah
Title: Re: asm branches (I think there was another thread like this)
Post by: Y.S. on June 01, 2009, 12:14:34 AM
Quote from: Bonzai7 on May 31, 2009, 06:50:25 PM
Ah, the great Y.S. Thanks for explaining that. So the final code would be:
C2000000 00000003
3D808001 618C2488
7D8903A6 4E800420
60000000 00000000

correct?

The format is correct, but you need to specify the location into which the instructions are inserted.
(The top left box in the convertor)
Title: Re: asm branches (I think there was another thread like this)
Post by: paprika_killer on June 01, 2009, 01:03:07 PM
Quote from: Romaap on May 31, 2009, 08:08:05 PM
Quote from: paprika_killer on May 31, 2009, 07:21:37 PM
wait, can the the convertor work with macros?
lol, yeah

is there a guide on that somewhere?
Title: Re: asm branches (I think there was another thread like this)
Post by: Bonzai7 on June 01, 2009, 10:40:30 PM
Quote from: Y.S. on June 01, 2009, 12:14:34 AM
Quote from: Bonzai7 on May 31, 2009, 06:50:25 PM
Ah, the great Y.S. Thanks for explaining that. So the final code would be:
C2000000 00000003
3D808001 618C2488
7D8903A6 4E800420
60000000 00000000

correct?

The format is correct, but you need to specify the location into which the instructions are inserted.
(The top left box in the convertor)

Good, I was only concerned with the format anyway (a code that only branches would be kinda lame wouldn't it?)

Thanks for the help.  :cool:


Edit :How would I write:

beq-   0x80012848

with that method?


Title: Re: asm branches (I think there was another thread like this)
Post by: Y.S. on June 02, 2009, 12:55:14 PM
Here it goes:

/*Absolute branch if equal*/

.macro  abeq   symbol
lis   r12,\symbol@h
ori   r12,r12,\symbol@l
mtctr   r12
beqctr-
.endm

abeq 0x80012848
Title: Re: asm branches (I think there was another thread like this)
Post by: paprika_killer on June 03, 2009, 12:33:51 AM
ah I see how the marco stuff roughly works, but what does the @h and @l mean?
Title: Re: asm branches (I think there was another thread like this)
Post by: Romaap on June 03, 2009, 02:27:07 AM
i'm not sure, but i think they mean "high word" and "low word".
so @h is the first 16bit and @l is the last 16bit
Title: Re: asm branches (I think there was another thread like this)
Post by: Bonzai7 on June 03, 2009, 09:09:30 PM
Thanks Y.S., you have been an absolute help to me. (if only you could fix stupid  :p )