Set Value to ASM C2

Started by Deathwolf, June 21, 2010, 02:56:28 PM

Previous topic - Next topic

dcx2

Do you mean, for instance, to make r0 = 0xFFFFFFFF?

lis r0,0xFFFF
ori r0,r0,0xFFFF

If it gives you a syntax error, try -1 instead of 0xFFFF

lis = Load Immediate Shifted = fill the upper 16 bits with this
ori = OR with Immediate = fill the lower 16 bits with this

Deathwolf

 ???

yes 32 bit value

r0 = 0xFFFFFFFF
lolz

wiiztec

Quote from: Deathwolf on June 21, 2010, 05:23:50 PM
if I change it to li r0,99 and I lose a live, the game freez.
and if I change it to li r0,0x63, it says error (assembled instruction is li r0,99)

WiiRd does that, it makes you type it in decimal even though it's clear from the message that it understands 0x63
If there's any code at all that you want to be button activated, or even able to toggle on & off, and I have the game, just PM me and I'll make it happen

Skiller

Quote from: wiiztec on June 21, 2010, 08:03:52 PM
Quote from: Deathwolf on June 21, 2010, 05:23:50 PM
if I change it to li r0,99 and I lose a live, the game freez.
and if I change it to li r0,0x63, it says error (assembled instruction is li r0,99)

WiiRd does that, it makes you type it in decimal even though it's clear from the message that it understands 0x63

they could just try to do this .

80060674 38000063   li   r0,99

This should set there lives to 99 once it hits 0 ..
or if they want always 99 ..

80060670  40820000   bne-   0x80060674
80060674  38000063   li   r0,63

U could just nop the Bne but Meh  :P

Deathwolf

thanks but how to write a 32 bit code...
lolz

Romaap

Quote from: Deathwolf on June 22, 2010, 01:10:41 PM
thanks but how to write a 32 bit code...
here's your answer:

Quote from: dcx2 on June 21, 2010, 07:12:28 PM
Do you mean, for instance, to make r0 = 0xFFFFFFFF?

lis r0,0xFFFF
ori r0,r0,0xFFFF

If it gives you a syntax error, try -1 instead of 0xFFFF

lis = Load Immediate Shifted = fill the upper 16 bits with this
ori = OR with Immediate = fill the lower 16 bits with this

For writing 0x12345678 you would do:
lis r0,0x1234
ori r0,r0,0x5678

Deathwolf

#21
but this should also work or maybe not?

li r0,0x1234
lis r0,0x5678
lolz

dcx2

Pretend that r0 already has 0x87654321

The safest way to load a register with a 32-bit value is lis/ori.

nop                 =>    r0: 0x87654321
lis r0,0x1234     =>   r0: 0x12340000  <--- lis erased the lower 16 bits for us
ori r0,r0,0x5678 =>   r0: 0x12345678  <--- ori does not erase the upper 16 bits, so we keep 0x1234

Using lis/li together will not work.  lis always erases the lower 16 bits.  li always erases the upper 16 bits.

nop              =>    r0: 0x87654321
lis r0,0x1234   =>   r0: 0x12340000  <--- lis erased the lower 16 bits for us
li r0,0x5678    =>   r0: 0x00005678  <--- oh no!  li erased the upper 16 bits!  We lost 0x1234!

---

(detailed technical explanation below!)

li and lis are "mnemonics" or "shortcuts"; they are actually addi and addis.

li r3,4        =>  addi r3,r0,4
lis r12,63   =>   addis r12,r0,63

addi and addis are two instructions that behave differently when the source operand is r0.  Instead of using the value in r0, they use the actual value 0.

li r3,4        =>  addi r3,r0,4       => 0 + 4 -> r3
lis r12,63   =>   addis r12,r0,63  =>  (0 + 63)<<16 -> r12

(<< means "left shift", <<16 means left shift by 16 bits)

addi r0,r0,1 will not increment r0!  It will set r0 to 1 no matter what was in r0 before.  If you try to put this asm into WiiRD, it will complain.

Deathwolf

hmm another quick question [super mario galaxy 2 ntsc]

starbits
address = 80E40E7A

breakpoint:

804DE06C:  4E800020   blr   
804DE070:  A063000A   lhz   r3,10(r3)
804DE074:  38800000   li   r4,0
804DE078:  38A0270F   li   r5,9999
804DE07C:  4BB3BD84   b   0x80019e00
804DE080:  9421FFF0   stwu   r1,-16(r1)
804DE084:  7C0802A6   mflr   r0
804DE088:  38A0270F   li   r5,9999
804DE08C:  90010014   stw   r0,20(r1)
804DE090:  93E1000C   stw   r31,12(r1)
804DE094:  7C7F1B78   mr   r31,r3
804DE098:  A003000A   lhz   r0,10(r3)
804DE09C:  7C602214   add   r3,r0,r4
804DE0A0:  38800000   li   r4,0
804DE0A4:  4BB3BD5D   bl   0x80019e00
804DE0A8:  B07F000A   sth   r3,10(r31)
804DE0AC:  83E1000C   lwz   r31,12(r1)
804DE0B0:  80010014   lwz   r0,20(r1)
804DE0B4:  7C0803A6   mtlr   r0
804DE0B8:  38210010   addi   r1,r1,16
804DE0BC:  4E800020   blr   
804DE0C0:  A063000C   lhz   r3,12(r3)
804DE0C4:  38800000   li   r4,0
804DE0C8:  38A0270F   li   r5,9999
804DE0CC:  4BB3BD34   b   0x80019e00
804DE0D0:  9421FFE0   stwu   r1,-32(r1)
804DE0D4:  7C0802A6   mflr   r0
804DE0D8:  90010024   stw   r0,36(r1)
804DE0DC:  39610020   addi   r11,r1,32
804DE0E0:  48150089   bl   0x8062e168
804DE0E4:  A003000C   lhz   r0,12(r3)

I'm a little confussed because nothing will work....
lolz

dcx2

What are you trying to do?  What have you tried?

I noticed that you highlighted r0 in the add instruction.  add actually uses the value in r0; addi does not use the value in r0.

By the way, this is the complete "function".  Note that it begins with stwu/mflr ("Function Prologue") and ends with mtlr/addi/blr ("Function Epilogue").  The whole function is below

804DE080:  9421FFF0   stwu   r1,-16(r1)
804DE084:  7C0802A6   mflr   r0
804DE088:  38A0270F   li   r5,9999
804DE08C:  90010014   stw   r0,20(r1)
804DE090:  93E1000C   stw   r31,12(r1)
804DE094:  7C7F1B78   mr   r31,r3
804DE098:  A003000A   lhz   r0,10(r3)
804DE09C:  7C602214   add   r3,r0,r4
804DE0A0:  38800000   li   r4,0
804DE0A4:  4BB3BD5D   bl   0x80019e00
804DE0A8:  B07F000A   sth   r3,10(r31)
804DE0AC:  83E1000C   lwz   r31,12(r1)
804DE0B0:  80010014   lwz   r0,20(r1)
804DE0B4:  7C0803A6   mtlr   r0
804DE0B8:  38210010   addi   r1,r1,16
804DE0BC:  4E800020   blr   

Can you provide a copy of the values in the Registers at the instruction 804DE09C?

I think I see what's happening.  The current star bit value is put into r0, using a pointer in r3 that was provided by the caller.  r4 contains the number of star bits to add; 1 when you pick up a star bit and 0xFFFFFFFF when you shoot a star bit.  It is an "argument" - the caller loaded r4 with the value before calling this function, that's why you don't see it being loaded here.  You would need to follow the blr to see who loads r4.

bl   0x80019e00 is probably some function that makes sure your starbits are >= 0 (newly loaded in r4) and <= 9999 (in r5).

Deathwolf

#25
80E40E7A:

CR  : 88000822  XER : 00000000  CTR : 80314DA0  DSIS: 02400000
DAR : 80E40E7A  SRR0: 804DE0A8  SRR1: 0000A032  LR  : 804DE0A8
r0  : 00000456  r1  : 807F2F10  r2  : 807DECA0  r3  : 00000455
r4  : 00000455  r5  : 0000270F  r6  : 80727A68  r7  : 00000000
r8  : 636B0000  r9  : 0011C264  r10 : 0011C26C  r11 : 807F2F10
r12 : 80314DA0  r13 : 807D7320  r14 : 00000000  r15 : 00000000
r16 : 00000000  r17 : 00000000  r18 : 00000000  r19 : 00000000
r20 : 00000000  r21 : 00000000  r22 : 00000000  r23 : 00000000
r24 : 00000000  r25 : 00000000  r26 : 00000000  r27 : 00000000
r28 : 81243B68  r29 : 807F2FCC  r30 : FFFFFFFF  r31 : 80E40E70

f0  : C4B3715E  f1  : 42200000  f2  : C3992203  f3  : 00000000
f4  : 00000000  f5  : 00000000  f6  : 00000000  f7  : 00000000
f8  : BD89A4B9  f9  : 3E810440  f10 : 3E7EC2B4  f11 : BF6ECB1A
f12 : 3E77DFB8  f13 : 3D843960  f14 : 00000000  f15 : 00000000
f16 : 00000000  f17 : 00000000  f18 : 00000000  f19 : 00000000
f20 : 00000000  f21 : 00000000  f22 : 00000000  f23 : 00000000
f24 : 00000000  f25 : 00000000  f26 : 00000000  f27 : 00000000
f28 : 00000000  f29 : 00000000  f30 : 00000000  f31 : 43C80000

r0  : 00000456
r3  : 00000455
r4  : 00000455

-1 different

r5  : 0000270F <-- maximal 9999

we need r0 for add the value to the real register


804DE0A8:  B07F0000 <--sth r3,10(r31)
r3  : 00000455
r31 : 80E40E70 <-- address

mtlr r0
r0  : 00000456 <-- real
addi r1,r1,16 <-- r1  : 807F2F10
blr
lolz

dcx2

What do you want to do?  Max starbits?  Replace

804DE0A4:  4BB3BD5D   bl   0x80019e00

with

804DE0A4:  7CA32B78    mr r3,r5

This will copy r5 = 0x270F = 9999 into r3 every time.

The bl   0x80019e00 is supposed to make sure r3 is between r4 = 0 and r5 = 9999.  It makes sure we do not have less than 0 star bits or more than 9999 star bits.  r3 will have the result.  So instead of bl   0x80019e00, when we mr r3,r5 we're copying the maximum (r5 = 9999) over top of the result (in your case, 0x455).

Deathwolf

#27
and r0? ???
I want to set 9999 to r0
lolz

dcx2

No, you don't need to set r0 = 9999.  r0 is a temporary register that's used to load your current star bit value.  r3 is later used to write your new star bit value.

Deathwolf

li r3,9999 would not working?
lolz