108 Coders
Hello, if your currently not a registered user, please take some time to sign up! If you are a registered user then go ahead and log in. Enjoy!

How To Write A Simple Subroutine

Go down

How To Write A Simple Subroutine

Post  Sniper7410 on Thu Aug 05, 2010 4:42 pm

THINGS YOU NEED TO KNOW:
Well Understanding Of MIPS
How to use registers and commands
The Negative Rule
Hooks And Areas

Ok before we get started you need to know a couple things.

The Negative Rule
First off is the 7FFF rule. The 7FFF rule only apply's to some CMD's(Commands) but not all. The 7FFF rule means that whenever you have a code, lets say Inf Ammo for FTB3, which is 0x0897F5DC in REAL addressing. Now as you can see the last 16 bytes of the address is F5DC, that is bigger than 7FFF. So now you have to add 0x0001 since the last 16 bytes are bigger than 7FFF. So the new code would be 0x0898F5DC.

Knowing How To Use Registers
Now, using registers is pretty simple if you know how to read. Ok the basic Sub-Rountine Temp looks like this:
lui t0 $[First Half Of Address + 1 If Second Half Is 8000 Or More]
lui t1 $[First half Of Value]
ori t1 t1 $[Second Half Of Value]
sw t1 $[Second Half Of Address](t0)
JR RA

Now look at the first command. It's a lui t0. This is loading the first half of your code in REAL addressing into a temporary register. Now look where it command that loads the last half of the code. It's a sw t1 (t0) Now the t0 in brackets links back to the t0 which is the register thats holding the first half of the code. As you can see its linking them together. Don't get it? Lets try another. Ok look at the command loading the first half of the hex, it's a lui t1. Ok now look at the command loading the last half of the hex it's a ori t1, t1. As you can seen the last t1 in the Ori CMD links it to the first half of the hex completing it. (This is how i see it, you might see it differently)

Hooks And Areas
Ok Hooks are pretty simple here are some safe hooks:
0x00000024
0x0000004C
0x00000098

Ok you can chose anyone of these for you routine.
To find the hex of your hook you must chose what area you want to use. To do this find a large field of nops (No Operation) in the game's RAM. Now lets say you chose 0x00003000 as a area. The hex of your hook has to equal the area of your sub in REAL addressing. The REAL address of our area is 0x08803000. Now a hex to to equal this area is 0x0A200C00 ($08803000)
So your hook will look like this:

0x00000098 0x0A200C00 (I chose 98 for a hook you can use anything you like)

Ok so now you have a understanding of this lets write the routine.

Ok, first find the code you would like to sub. I'm going to use:

#Inf Ammo
;Sniper7410
0x0017F5DC 0x10000000

Ok, now we have the code we are gonna put this into REAL address so break out the hex calc or just use your head.

0x08800000 + 0x0017F5DC = 0x00897F5DC

Now notice the last 16bytes are bigger than 7FFF so lets add 0x0001 making our code 0x0898F5DC.

Ok, now we are ready!

#Inf Ammo SUB
0x00000098 0x0A200C00
0x00003000 0x3C080898

Ok as you see i loaded the first half of the code into a lui t0 which is 0x3C08.

Now time for the next line.

#Inf Ammo SUB
0x00000098 0x0A200C00
0x00003000 0x3C080898
0x00003004 0x3C090000

Now i loaded the first half of the hex into the CMD lui t1 which is 0x3C09.

Next Line:

#Inf Ammo SUB
0x00000098 0x0A200C00
0x00003000 0x3C080898
0x00003004 0x3C090000
0x00003008 0x35290001

Now i loaded the last half of the hex into a ori t1, t1 which is 0x3529

Next Line:

#Inf Ammo SUB
0x00000098 0x0A200C00
0x00003000 0x3C080898
0x00003004 0x3C090000
0x00003008 0x35290001
0x0000300C 0xAD09F5DC

Now i loaded the last half of the address into a sw t1 (t0) Which is 0xAD09

Last Line:

This is the last line and its simple all you have to do for the hex of a JR RA is 0x03E00008

#Inf Ammo SUB
0x00000098 0x0A200C00
0x00003000 0x3C080898
0x00003004 0x3C090000
0x00003008 0x35290001
0x0000300C 0xAD09F5DC
0x00003010 0x03E00008

Congrats this is our completed code.

Quick Re-Run:

#Inf Ammo SUB
0x00000098 0x0A200C00 =Hook ($08803000)
0x00003000 0x3C080898 lui t0 + 0x0001 ($0898)
0x00003004 0x3C090000 lui t1 ($0000)
0x00003008 0x35290001 ori t1, t1 ($0001)
0x0000300C 0xAD09F5CD sw t1 (t0) ($F5DC)
0x00003010 0x03E00008 = JR RA

---------------------------------------------------------------------------------------
Notes:

This is just a simple Sub-Routine Tutorial Writen By Sniper7410.

Any questions comments or problems please reply.
If i left anything out please tell me.

-Sniper7410
108 Coder
avatar
Sniper7410
Admin
Admin

Posts : 72
Join date : 2010-07-26
Location : NY

View user profile http://108coders.darkbb.com

Back to top Go down

Re: How To Write A Simple Subroutine

Post  PiStoL-KiLL- on Thu Aug 05, 2010 8:35 pm

Very useful and helpful tutorial. Thank you.
avatar
PiStoL-KiLL-
Moderator
Moderator

Posts : 21
Join date : 2010-08-04
Age : 24
Location : Chatham

View user profile http://armycommand.tk

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum