C0 codetype....

Started by Deathwolf, August 02, 2010, 03:05:10 PM

Previous topic - Next topic

dcx2

If the value is different, li r0 with the different value.

If the address is different, you can either re-load r12 with the new address, or you can figure out how far away the second address is from the first and use the displacement - displacement is the 112 in 112(r12).

Deathwolf

hmm....
does it works again with li or something like that?
btw if I want to write 32 bit, does lis and ori work on this?

lis r12,0x8023
ori r12,r12,0xED64
lis r0,0x0000
ori r0,r0,0x0000
stw r0,0(r12)
stw r0,112(r12)
lolz

dcx2

Yes, you still use lis/ori to load the upper/lower 16 bits.

Deathwolf

#18
okay thanks.

example:

0423EDD4 00000038
0423ED64 0000002C

lis r12,0x8023
ori r12,r12,0xED64
lis r0,0x0000
ori r0,r0,0x0038
stw r0,0(r12)
lis r0,0x0000
ori r0,r0,0x002C
stw r0,112(r12)

C0000000 00000005
3D808023 618CED64
3C000000 60000038
900C0000 3C000000
6000002C 900C0070
4E800020 00000000

store 00000038 to 8023ED64 and 2C to 8023EDD4.
right?
lolz

dcx2

Almost...

What do you think is going to happen on the bolded line?

lis r12,0x8023
ori r12,r12,0xED64
lis r0,0x0000
ori r0,r0,0x0038
stw r0,0(r12)
lis r0,0x0000
ori r0,r0,0x002C
stw r0,0(r12)
stw r0,112(r12)

btw, lis r0,0x0000 is unnecessary.

Deathwolf

#20
yep I have edit it.

lis r12,0x8023
ori r12,r12,0xED64 <-- 8 bit
li r0,0x38
stw r0,0(r12)
li r0,0x2C
stw r0,112(r12)

C0000000 00000004
3D808023 618CED64
38000038 900C0000
3800002C 900C0070
4E800020 00000000

my fail lol

if I write stw r0,0(r12) again, it will be overwritten with 2C
lolz

dcx2

 ;D  Learning by doing!

Do you understand that since 112 = 0x70, then 112(r12) = 0x70 + 0x8023ED64 = 0x8023EDD4?

I'm making this up, so don't apply this code.  But pretend with me for a second that we wanted to write 0x1F to 8023EE44.

address = d + rX

8023EE44 = d + 8023ED64

homework...what is d?  (both in hex and decimal)

Deathwolf

8023EE44 - 8023ED64  = d

d=E0/224
lolz

dcx2

 ;D

Last two things...

1) it's okay for offsets displacements to be negative
2) offsets displacements have limits.  the assembler will fail at you if it is too much.

Deathwolf

oh okay thank you dcx2  :)
lolz

wiiztec

dcx2 why do you prefer the term displacement to offset?
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

dcx2

#26
In particular, in the post back here, I had used the term displacement to describe it.

In general, offset is a very generic term.  It can be applied to many places, so I wanted to avoid it.

In the references for the ASM, you will see that it's described as stw rS,d(rA).  I'm pretty sure the d is for displacement, although it could stand for something similar.  I do know that I've seen "base displacement operand" used to describe d(rA) before.  I also know that it's quite common to refer to a branch's immediate field as the branch displacement.