Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Tutorial by Bad Luck Brian
- Pointers
- This lesson will be short but it is very important to understand what is a pointer !
- A pointer is an address containing an address as bytes.
- I know it sounds weird at first but lets make an example.
- we can't use 'strings' in registers so we need to use pointers to use strings !
- Code:
- 0x12340000 = my string
- 0x55550000 = pointer
- in the memory:
- Code:
- *ADDRESS | *BYTES* | ASCII
- 0x12340000: 55 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
- ...
- 0x55550000: 42 61 64 20 4C 75 63 6B 20 42 72 69 61 6E 00 00 Bad Luck Brian..
- here is how i would load the pointer in powerpc
- Code:
- lis r3, 0x1234
- lwz r3, 0x12340000(r3)
- the lis will set r3 to: 12 34 00 00 (0x12340000)
- and the lwz will read the memory at 0x12340000(pointer) and store it in r3
- so r3 = 0x55550000 (55 55 00 00)
- now r3 will contain the address of the string , of course in this case we could just use lis r3, 0x5500
- 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
- example of rpc:
- Code:
- //0x2100000 = pointer to call
- //read memory to get your arguments using lwz
- lis r9, 0x210 (0x2100000) //time to load the address
- mtctr r9 //this will save the address in a special register (count register), will talk about it in the next lesson
- bctrl //this will call the address in the count register, will talk about it in the next lesson
- that's why pointers are important !
Advertisement
Add Comment
Please, Sign In to add comment