Advertisement
ScriptzMoDz

[PowerPC] Calling a Function

Aug 29th, 2014
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. //Tutorial by Bad Luck Brian
  2.  
  3. Calling a function
  4.  
  5.  
  6. in C# we call our functions like this: Example(arg1, arg2, arg3);
  7. example: MessageBox.Show("Bad Luck Brian", "title here");
  8.  
  9. in powerpc its a bit more complicated but its still simple ^^
  10.  
  11. we will use 'bl'
  12.  
  13. bl is like 'b', it jumps to a location but bl will continue to the next line with the returned value
  14.  
  15. example of 'b'
  16.  
  17. :0 li r3, 0x15
  18. :1 b 6
  19. :2 //Not executed
  20. :3 //Not executed
  21. :4 //Not executed
  22. :5 //Not executed
  23. :6 //stuff goes here, its a function..executed
  24.  
  25.  
  26. :0 li r3, 0x15
  27. :1 bl :6 //goto :6 and when done with it continue at :2
  28. :2 // executed
  29. :3 // executed
  30. :4 // executed
  31. :5 // executed
  32. :6 //executed
  33.  
  34.  
  35. calling functions in powerpc is a must and we will use it really often.
  36. i will make some examples later on calling functions
  37.  
  38.  
  39. There is another way of calling functions, we will use pointers.
  40.  
  41. we use mtctr and bctrl
  42.  
  43. we use mtctr like this:
  44.  
  45. mtctr REGISTER
  46.  
  47. Register = register containing the address to call
  48.  
  49. and to call it we just use bctrl
  50.  
  51.  
  52. example:
  53.  
  54. Code:
  55. //0x2100000 contains: 00 12 34 56 (0x123456),
  56. //0x123456 = function i wanna call
  57.  
  58. lis r3, 0x210 //loads the address: 0x2100000 in r3
  59. lwz r3, r3 //read at: 0x2100000 and store the value in r3 (4 bytes)
  60. mtctr r3 //store r3 in the count register
  61. bctrl //call the value in the count register
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement