ScriptzMoDz

[PowerPC] Loading a value in a register

Aug 29th, 2014
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. //Tutorial Created by BadLuckBrian
  2. //No credit taken for this
  3. //For sharing purposes only
  4.  
  5. In this tutorial i will show you how to set a register.
  6.  
  7. first, what is a register ?
  8. A register is a variable which contains a value.
  9.  
  10. there is 32 registers (for us)
  11.  
  12.  
  13. r0 - r31, we count the register 0 too so its 32 registers in total, there is also some other registers but i won't talk about them for now.
  14. In PowerPC we will notice them like this: r0, r1, r2, r3 etc
  15. Code:
  16. r0 = old link register, i won't talk about it for now
  17. r1 = stack pointer, i won't talk about it for now
  18. r2 = table of contents pointer, i won't talk about it for now
  19.  
  20. r3 = it can be used as the first argument of a function OR as the returned value from a function
  21. r4–r10 = Used as the 2nd to the 8th arguments of a function.
  22. r11 = used for the PS3 Syscalls
  23. r12 = local var
  24. r13-r31 = global var, we use them to store a value and being able to use it later on another function.
  25. Don't worry we won't use them all, we will focus on r3, r4 and r5 for now :P
  26.  
  27.  
  28.  
  29. so in C# we can load values in variables like this:
  30. Code:
  31. int a = 10;
  32. string b = "Bad Luck Brian";
  33. byte[] c = new byte[] {0x05, 0x02, 0xFF};
  34. in powerpc we use li and lis
  35.  
  36. registers are 4 bytes, 11 22 33 44
  37. try to imagine them like this: XX XX YY YY
  38.  
  39.  
  40.  
  41. li - load imediate, it sets a register in the YY YY region
  42.  
  43. example: li r3, 0x15 ::: r3 = 00 00 00 15 (0x15 is the same as 0x0015)
  44. Code:
  45. li r3, 0x1500 ::: r3 = 00 00 15 00
  46. now lis is the same but with the XX XX region
  47. Code:
  48. lis r3, 0x26 ::: r3 = 00 26 00 00
  49. lis r3, 0x2600 ::: r3 = 26 00 00 00
  50. lis r3, 0x216 ::: r3 = 02 16 00 00
  51. Now we can set 2 bytes in a register, either the XX XX or the YY YY Region. We need to include some maths to set 4 bytes, its simple.
  52.  
  53. we will use addic and addis, addic adds something to the YY YY part and addis adds something to the XX XX Part.
  54.  
  55. we use them like this:
  56. Code:
  57. addic RESULT, REGISTER, VALUE
  58. Result = register containing the result of the addition
  59. Register = register to be added to the value
  60. Value = value to be added to the register
  61.  
  62. in english it would translater to this: Result = Register + Value
  63.  
  64. lets use some examples:
  65. Code:
  66. li r3, 0x15
  67. addic r3, r3, 0x01
  68. r3 is now equal to: 0x16 (0x15 + 0x01)
  69.  
  70. now lets set r3 to: 0xFCA2801
  71.  
  72. first of all, lets put it in a XX XX YY YY format.
  73.  
  74. we start from the RIGHT separating them bytes after bytes
  75. Code:
  76. FCA2801
  77. FCA28 01
  78. FCA 28 01
  79. F CA 28 01
  80. we add a zero before the last value ('F') to reach the XX XX YY YY format
  81. Code:
  82. *************
  83. *XX XX YY YY*
  84. *0F CA 28 01*
  85. *************
  86. now i will use lis to set the XX XX part and addic to set the YY YY Part
  87. Code:
  88. lis r3, 0x0FCA //r3 = 0F CA 00 00
  89. addic r3, r3, 0x2801 //r3 = 0F CA 00 00 + 00 00 28 01 (0F CA 28 01)
  90. lets do another example:
  91.  
  92. lets set r3 to: 0x1d60c
  93.  
  94. set it to the XX XX YY YY format to make it easier
  95. Code:
  96. 1d60c
  97. 1d6 0c
  98. 1 d6 0c
  99. add the zeros before it to reach XX XX YY YY
  100. Code:
  101. 01 d6 0c
  102. 00 01 d6 0c
  103.  
  104. *************
  105. *XX XX YY YY*
  106. *00 01 d6 0c*
  107. *************
  108. now i will use lis to set the XX XX part and addic to set the YY YY Part
  109. Code:
  110. lis r3, 0x0001 //r3 = 00 01 00 00
  111. addic r3, r3, 0xD60C //r3 = 00 01 00 00 + 00 00 D6 0C (00 01 D6 0C )
  112.  
  113. r3 = 0x0001D60c or 0x1D60c
  114. its simple !
  115. in the next lesson i will teach you how to write in the memory :P
Advertisement
Add Comment
Please, Sign In to add comment