ScriptzMoDz

[PowerPC] Pointers

Aug 29th, 2014
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. //Tutorial by Bad Luck Brian
  2.  
  3. Pointers
  4.  
  5.  
  6.  
  7. This lesson will be short but it is very important to understand what is a pointer !
  8.  
  9. A pointer is an address containing an address as bytes.
  10.  
  11. I know it sounds weird at first but lets make an example.
  12.  
  13. we can't use 'strings' in registers so we need to use pointers to use strings !
  14. Code:
  15. 0x12340000 = my string
  16. 0x55550000 = pointer
  17. in the memory:
  18.  
  19. Code:
  20. *ADDRESS | *BYTES* | ASCII
  21. 0x12340000: 55 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  22. ...
  23. 0x55550000: 42 61 64 20 4C 75 63 6B 20 42 72 69 61 6E 00 00 Bad Luck Brian..
  24.  
  25. here is how i would load the pointer in powerpc
  26.  
  27. Code:
  28. lis r3, 0x1234
  29. lwz r3, 0x12340000(r3)
  30. the lis will set r3 to: 12 34 00 00 (0x12340000)
  31. and the lwz will read the memory at 0x12340000(pointer) and store it in r3
  32.  
  33. so r3 = 0x55550000 (55 55 00 00)
  34.  
  35. now r3 will contain the address of the string , of course in this case we could just use lis r3, 0x5500
  36. but sometimes we have to use pointers like in RPC where the address of the function to call will be stored as bytes at our address
  37.  
  38. example of rpc:
  39. Code:
  40. //0x2100000 = pointer to call
  41.  
  42. //read memory to get your arguments using lwz
  43. lis r9, 0x210 (0x2100000) //time to load the address
  44. mtctr r9 //this will save the address in a special register (count register), will talk about it in the next lesson
  45. bctrl //this will call the address in the count register, will talk about it in the next lesson
  46. that's why pointers are important !
Advertisement
Add Comment
Please, Sign In to add comment