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!

Beginners Tutorial [MIPS]

Go down

Beginners Tutorial [MIPS] Empty Beginners Tutorial [MIPS]

Post  Sniper7410 on Sun Aug 22, 2010 1:04 am

Hello, everyday I see more and more people wanting to learn MIPS to code PSP games. Well there are alot of guides out there that explain how to write the subroutine which is filling in the blanks. Well in this mini tutorial I will explain the basics of MIPS commands so those begginer tutorials are a bit easier to understand. This isnt really usefull if you already know MIPS its more of a thing to help those who are just beggining. Lets get to it!

Hex basics

First the basics of hex, you should learn this as if you know next to nothing then well it may just be a little harder.MIPS address's are counted by fours so for example it will go like so. Also hex if you did not know is made up of numbers 0-9 And the letters A-F.


00000010;Once you count 0..4..8..c..then you add one to that byte etc so it goes up to 10 then 14...

That above example should easy enough to follow and I shouldnt really need to explain much more on that subject matter.

Data Types

Data types are the types of data you have so as bytes, words, hlafwords etc.

All Instructions are 32 bits (searchers should know this!)
A byte is 8 bits
A Halfword is 2bytes(18 bits)
A word is 4 bytes(32 bit instruction)

basics of registers

Registers are extremely Important in any type of assembly including MIPS, so I think this is something extremely important to cover up. Registers are used to hold and contain different types of data such as packets, information, offsets etc. You can call data from one register and bring it into another. You also use them in subrotuines with the most commonly used among begginers which would be tX.

Register Name|Purpose|Example(s)

Temporary | Temporary contains data to be called and used elsewhere goes $t0-t9 | ori t0, zero, $0001

Values | Contains the function values and the result $v0-v1 | beq v1, zero, $00000158

Saved | Saves the called data and please remember that when using these registers in a subrotuine you must save the original data and restore it back before exiting $s0-s7 | andi s2, t1, $7f19

Arguments | Commonly used for packets such as a3 when using the data pointer for where the packet is recived or sent etc. Not Commonly used for begginers $a0-a3 | addiu a0, zero, $0003

Stack pointer | used to point data and allocate it onto the stack. Many begginers wont understand this so I will expplain my example! (sp) | sw t0, $0000(sp) Kinda hard to explain without the whole routine but this short mini example stores the contents of t0 onto the stack pointer which would of been defined before +0000.

Thats all I think you guys should know about registers for know as theres still more to explain such as more about the stack, frame pointers but I will explain those in a tutorial in the future.

The basic MIPS Commands

Commands tell the assembler what function to perform and what to do etc such as add this data into the value, or load this address from here etc. I will only explain the basic ones in this tutorial as I dont want people who are just starting to learn to become too confused.

nop - No operation -Disables a function or object in the memory, also where codes are written to as these address's have no value and therefor can not corrupt other memory.(unless the rotuine is wrong) the Value of this is 00(00000000)

lui - Load upper Imediate -This command will load the upper half of an address or the data of a value. Say you have the address aaaabbbb It would load the upper Immediate which is the first half of that string. So it would be. XXXX0000 Loading the X's like so.

lui t0, $aaaa ;Where as this loads the first half of the data(either an address or value into a temporary register)

lw -Load word- Loads the word just like lui, except this loads the second half of the data wheter that is an address or a value into a register for further use. The word is the second half so it is. 0000XXXX where as X is the second half. aaaabbbb

lw t2, $bbbb ;This loads the second half of the data into another temporary register. Now Im going to show you how to load a compelte string of data using these two commands!

lui t0, $aaaa ;loads the first half into t0
lw t2, $bbbb(t0) (aaaabbbb) ;loads the second half of the data into t2, and then places the word into that register and binds it with t0 to make a complete string of data.

This fully loads the data aaaabbbb into temporary registers and when it is used in the subrotuine the processor will know you mean the address aaaabbbb. nice eh? And very easy to do!

ori - or imediate -This will place data or replace the current value of a function or address. It basically loads the value onto its location or the register. Such as..

ori t0, zero, $0001 ;This loads the data of one into a temporary register. What is the 'zero' '0' there for? Well it keeps the value constent so lemme explain this. Instead of being XXXX0001 It will define the data as 00000001 Even though it is not really shown that way. This is so if you dont want to place another hlaf of data into that value it will only keep it 01.

addiu - add unsigned imediate - Can be used to incremate or add data to a value etc, also used to change the address of what your loading, also works somewhat like an ori.

addiu sp, sp, -$0020(ffe0 is the value that it comes out to be *as the data ff makes it negative*) This subtracts 20 from the stack pointer to later have added back on but heres an easier example. addiu t4, zero, $0004 That adds four to that register(s).

jr ra- jump register return address -This jumps the return to the return address to finish off the routine. most if not almost all subrotuines have to be returned back to their starting point to their hook to execute the routine. jr ra is basically all you really half to know as it can be used for hooks etc. Now this can be used in some fancy ways such as returning data to a register or location of a reciving function so that data is NEVER recived so say you have a function that recives data, jr ra that location and it should stop it from you reciving it

Again this tutorial was made for begginers and people who have very little experiance with MIPS and would like to improve. This will make it ALOT easier on teachers who are instructings MIPS to people and have to start from the basics but don't know how to do it then point that person here. Also if YOU are new to MIPS and think there is something I should definetly cover for begginers, then let me know! And I will add it if it helps the begginers.

Hopefully it will help someone out in the future. Enjoy and I will most likely update this every now and then if I need too.

Beginners Tutorial [MIPS] 108cod10
108 Coder
PSN: Sniper7410
FTB2: 5.N.I.P.E
Beginners Tutorial [MIPS] Sig

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


Back to top Go down

Back to top

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