Writing Nibbles

Started by Bully@Wiiplaza, December 07, 2012, 04:16:34 PM

Previous topic - Next topic

Bully@Wiiplaza

I was wondering if or how we could do 4 bit writes.

The codetypes don´t seem to consist anything, but I´m pretty sure there´s some assembly...
what´s the best way to overwrite one digit from a value without touching the others?
My Wii hacking site...
http://bullywiihacks.com/

My youtube account with a lot of hacking videos...
http://www.youtube.com/user/BullyWiiPlaza

~Bully

biolizard89

Quote from: Bully@Wiiplaza on December 07, 2012, 04:16:34 PM
I was wondering if or how we could do 4 bit writes.

The codetypes don´t seem to consist anything, but I´m pretty sure there´s some assembly...
what´s the best way to overwrite one digit from a value without touching the others?
Maybe Gecko Registers with bitmasks?

Bully@Wiiplaza

#2
How?
If the value is 0xHHHXHHHH and I want to write to X any amount between 0 and F...
"and" and "or" don´t work for all values... it must be reliable at all times :S
My Wii hacking site...
http://bullywiihacks.com/

My youtube account with a lot of hacking videos...
http://www.youtube.com/user/BullyWiiPlaza

~Bully

James0x57

If your Nibble to write is on the "right side" of the byte (_Y):

first OR the byte in a register with 0F,
then AND that with your (Nibble + F0).

[address] = ([address] OR 0F) AND FY




If your Nibble to write is on the "left side" of the byte (Y_):

first OR the byte in a register with F0,
then AND that with your (Nibble + 0F).

[address] = ([address] OR F0) AND YF



Bully@Wiiplaza

#4
Awesome, that´s what I was looking for. ;D
I almost had your solution though :-[
My Wii hacking site...
http://bullywiihacks.com/

My youtube account with a lot of hacking videos...
http://www.youtube.com/user/BullyWiiPlaza

~Bully

dcx2

You could also use the rlwimi assembly instruction to replace arbitrary contiguous bits.   I think this will work (I always have trouble with rlwi* instructions).  Assuming r3 has the nibble you want in bits 28-31 (i.e. the last four bits, 0x0000000Y) and you're putting it in r4

rlwimi r4, r3, 0, 28, 31

For the other nibble, 0x000000Y0, you'd use

rlwimi r4, r3, 0, 24, 27

This instruction is very versatile.  First, it rotates rS (r3 in this case) by sh (0 in this case).  Then it generates a mask of 1 bits, stretching from mb to me (28 to 31 in the first case).  The rotated rS is then masked by the mask bits and directly inserted into rA.  So for example, let's say r3 had 0xY, but you wanted it to replace r4's 0xY0 bits.

rlwimi r4, r3, 4, 24, 27

If r3 had 0xY0 and you wanted it to replace r4's 0xY (recall that a left shift of 28 is equivalent to a right shift of 4)

rlwimi r4, r3, 28, 28, 31