PSP Coding
Would you like to react to this message? Create an account in a few clicks or log in to continue.

PSP Coding


 
HomeLatest imagesSearchRegisterLog in

 

 How to Write a two code Subroutine!

Go down 
5 posters
AuthorMessage
Architect




Posts : 11
Points : 16
Reputation : 0
Join date : 2010-09-29

How to Write a two code Subroutine! Empty
PostSubject: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeWed Oct 06, 2010 11:28 pm

This is my first tutorial, Please Give me suggestions.


How to Write a two Code Subroutine.
===================================
What you Need to know:


-Basic understanding of Mips

-UnderStanding of registers

-How to find a Hook

-How to find a hook value

-Negative rule


~~The Mips you need to know~~
__________________________


lui - load upper immediate
lw - Load Word
ori- Bitwise or immediate
addiu-Add immediate unsigned
sw- Store word
Jr ra- Jump register Return address


~~Registers~~
______________


Basically a Register Holds something. ie.

lui t0 $1234
lw t0 $5678(t0)

this would load the current value at address 0x12345678 into t0

t0-t9 Temperary Registers

~~How to find a hook~~
_____________________



To find a hook:

-- You First Search 03e00008 in exact value

-- You can either Let it Search for about 4-6 min Or when it hits 1%, just stop it.

-- Now that You've got your searches Add them to your database.

-- You can either change the hex to 03e00007 or nop it (00000000).

-- What ever ones freeze can be used as a hook.


--For the hook value, Put the first part of your routine in Real using the following command. J $first address of routine in Real.



~~Negative rule~~
__________________


The Negative Rule:

If the Last 16 bits of your address is over 7FFF then You have to add 0x0001 to the address in real. i.e- 0x1234[8000] is over 7FFF so u add 0x0001 [12358000 in fake].





Now lets get started with our Routine.



The template We will be using
Code:

-Hook
lui t0 $First half of Address
lui t1 $first half of value
addiu t1 t1 $Second half of value
sw t1 $Second half of Address(t0)
lui t2 $First half of code 2
lui t3 $First half of value
addiu t3 t3 $Second half of value
sw t3 $Last half of Address
Jr Ra

Our code Were gonna use :

#This code does Nothing
0x00023454 0x00000001
0x00023458 0x00000002

First: Put the codes in Real addressing

0x00023454 +08800000
0x00023458 +08800000
_____________________
0x08823454 0x00000001
0x08823458 0x00000002


Second:
Put the codes in the template.


-Hook
lui t0 $0882
lui t1 $0000
addiu t1 t1 $0001
sw t1 $3454(t0)
lui t2 $0882
lui t3 $0000
addiu t3 t3 $0002
sw t3 $3458(t2)
Jr Ra

Now We use ps2dis to Plugin the commands and get our Values.

Load Ps2dis from 08800000


Press control F select as hex string and hold zero for 45 seconds. Now we found our Area of Nops we will be working in.


Since we have our area of Nops its time to Start Plugging in the Commands. Im using area 08803000

hook=0x00000098 0x0a200c00

Lui t0 $0882= 0x08803000 0x3c080882

lui t1 $0000= 0x08803004 0x3c090000

addiu t1 t1 $0001= 0x08803008 0x25290001

sw t1 $3454(t0)= 0x0880300C 0xad093454

lui t2 $0882= 0x08803010 0x3c0a0882

lui t3 $0000= 0x08803014 0x3c0b0000

addiu t3 t3 $0002 = 0x08803018 0x256b0002

sw t3 $3458(t2) = 0x08800301c 0xad4b3458

jr ra = 0x08803020 0x03e00008


#Not done yet
0x00000098 0x0a200c00
0x08803000 0x3c080882
0x08803004 0x3c090000
0x08803008 0x25290001
0x0880300C 0xad093454
0x08803010 0x3c0a0882
0x08803014 0x3c0b0000
0x08803018 0x256b0002
0x0880301c 0xad4b3458
0x08803020 0x03e00008



;Now we have to Subtract 0880 from each address.


Done!


#Finished code
0x00000098 0x0a200c00
0x00003000 0x3c080882
0x00003004 0x3c090000
0x00003008 0x25290001
0x0000300C 0xad093454
0x00003010 0x3c0a0882
0x00003014 0x3c0b0000
0x00003018 0x256b0002
0x0000301c 0xad4b3458
0x00003020 0x03e00008



~~Recap~~
___________


#Fake addressing
0x00023454 0x00000001
0x00023458 0x00000002

#Real addressing
0x08823454 0x00000001
0x08823458 0x00000002

#Finished code
0x00000098 0x0a200c00 -hook
0x00003000 0x3c080882 0x0882- First half of First address
0x00003004 0x3c090000 0x0000- First half of first value
0x00003008 0x25290001 0x00000001- Second half of Value
0x0000300C 0xad093454 0x00003454-Second half of Address 1
0x00003010 0x3c0a0882 0x0882 -First half of address 2
0x00003014 0x3c0b0000 0x0000 First half of Value 2
0x00003018 0x256b0002 0x00000002 - Second half of Value 2
0x0000301c 0xad4b3458 0x000003458 - Second half of Address 2
0x00003020 0x03e00008 jr ra





~Architect









Last edited by Architect on Thu Oct 07, 2010 1:21 pm; edited 3 times in total
Back to top Go down
Mr_Waffle

Mr_Waffle


Posts : 17
Points : 21
Reputation : 0
Join date : 2010-09-30
Age : 29

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeWed Oct 06, 2010 11:56 pm

Go go go Architect!
Back to top Go down
-LeetGamer-
Admin



Posts : 247
Points : 397
Reputation : 4
Join date : 2010-09-29
Age : 30

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeThu Oct 07, 2010 9:23 am

Nice but I have a few things to point out, Jr ra means jump register return address, not jump return return address.

Also if we do this:

Lui t0 $1234
Lw t0 $5678(t0)

That would not load the value 0x12345678 into t0 like you said, it would load the current value at address 0x12345678 into t0, you would need to use Ori or Addi to get the value 0x12345678 into t0 Wink

Other than that great tutorial for people wanting to learn more than a one lined subroutine Very Happy
Back to top Go down
Mr_Waffle

Mr_Waffle


Posts : 17
Points : 21
Reputation : 0
Join date : 2010-09-30
Age : 29

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeThu Oct 07, 2010 9:24 am

-LeetGamer- wrote:
Nice but I have a few things to point out, Jr ra means jump register return address, not jump return return address.

Also if we do this:

Lui t0 $1234
Lw t0 $5678(t0)

That would not load the value 0x12345678 into t0 like you said, it would load the current value at address 0x12345678 into t0, you would need to use Ori or Addi to get the value 0x12345678 into t0 Wink

Other than that great tutorial for people wanting to learn more than a one lined subroutine Very Happy
It's a miracle :O Leet actually read a post!



Wait for it...



jk!
Back to top Go down
-LeetGamer-
Admin



Posts : 247
Points : 397
Reputation : 4
Join date : 2010-09-29
Age : 30

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeThu Oct 07, 2010 9:54 am

Mr_Waffle wrote:
-LeetGamer- wrote:
Nice but I have a few things to point out, Jr ra means jump register return address, not jump return return address.

Also if we do this:

Lui t0 $1234
Lw t0 $5678(t0)

That would not load the value 0x12345678 into t0 like you said, it would load the current value at address 0x12345678 into t0, you would need to use Ori or Addi to get the value 0x12345678 into t0 Wink

Other than that great tutorial for people wanting to learn more than a one lined subroutine Very Happy
It's a miracle :O Leet actually read a post!



Wait for it...



jk!

lmao
Back to top Go down
Architect




Posts : 11
Points : 16
Reputation : 0
Join date : 2010-09-29

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeThu Oct 07, 2010 12:58 pm

oh typo, lol Jump return thnx for your help i fixed it
Back to top Go down
Emu




Posts : 21
Points : 29
Reputation : 0
Join date : 2010-10-04

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeThu Oct 07, 2010 4:36 pm

Good job but you should use another example if your code has a different upper address:

0x08810000
0x08820000

lui t0, $0881 // 0x0001
lui t1, $0882 // 0x0002
lui t2, $1337 // 0x1337
addiu t2, t2, $0004 // 0x13370004
sw t2, $0000(t0) // 0x00010000
lui t2, $1337 // 0x1337
addiu t2, t2, $0005 // 0x13370005
sw t2, $0000(t1) // 0x00020000
jr ra // Jump register return address
nop // Slot delay

I just reused t2 again because it was unreasonable to use another register if one that you have finished using if open.

for this routine you showed:

lui t0 $0882
lui t1 $0000
addiu t1 t1 $0001
sw t1 $3454(t0)
lui t2 $0882
lui t3 $0000
addiu t3 t3 $0002
sw t3 $3458(t2)
Jr Ra

You could have done this to make it shorter:

lui t0 $0882
addiu zero, t1, $0001
sw t1 $3454(t0)
addiu zero, t1, $0002
sw t1 $3458(t0)
jr ra
nop
Back to top Go down
Architect




Posts : 11
Points : 16
Reputation : 0
Join date : 2010-09-29

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeThu Oct 07, 2010 8:29 pm

yeah i know but i was trying to explain two different codes.. Cuz I remember when i was Learning to subroutine i wanted to do 2 codes but i didn't know how Razz.
Back to top Go down
Emu




Posts : 21
Points : 29
Reputation : 0
Join date : 2010-10-04

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeFri Oct 08, 2010 5:02 pm

Glad to see you got it. Good job again Very Happy
Back to top Go down
Architect




Posts : 11
Points : 16
Reputation : 0
Join date : 2010-09-29

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeSat Oct 09, 2010 8:47 pm

thanx
Back to top Go down
SXYxJeff

SXYxJeff


Posts : 47
Points : 55
Reputation : 0
Join date : 2010-09-29

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeSun Oct 10, 2010 12:55 am

nice good job Smile
Back to top Go down
Architect




Posts : 11
Points : 16
Reputation : 0
Join date : 2010-09-29

How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitimeSun Oct 10, 2010 11:12 am

Thank you
Back to top Go down
Sponsored content





How to Write a two code Subroutine! Empty
PostSubject: Re: How to Write a two code Subroutine!   How to Write a two code Subroutine! I_icon_minitime

Back to top Go down
 
How to Write a two code Subroutine!
Back to top 
Page 1 of 1
 Similar topics
-
» [Video Tutorial] How to Write a Subroutine
» Writing a subroutine that activates another subroutine....
» How Joker A Code [ Big Guide ]
» DML Subroutine Writer Generator
» Code help

Permissions in this forum:You cannot reply to topics in this forum
PSP Coding :: PSP Section :: PSP Coding Tutorials :: MIPS-
Jump to: