asm branches (I think there was another thread like this)

Started by Bonzai7, May 31, 2009, 01:59:14 PM

Previous topic - Next topic

Bonzai7

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.

Y.S.

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

Bonzai7

Ah, the great Y.S. Thanks for explaining that. So the final code would be:
C2000000 00000003
3D808001 618C2488
7D8903A6 4E800420
60000000 00000000

correct?

paprika_killer

[SIGPIC][/SIGPIC]

Romaap


Y.S.

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)

paprika_killer

[SIGPIC][/SIGPIC]

Bonzai7

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?



Y.S.

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

paprika_killer

ah I see how the marco stuff roughly works, but what does the @h and @l mean?
[SIGPIC][/SIGPIC]

Romaap

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

Bonzai7

Thanks Y.S., you have been an absolute help to me. (if only you could fix stupid  :p )