What is MIPS??
MIPS is an assembly language.
Assembly Language?
That means that it is a low level language. C++, for instance, is a high level language, meaning that it is very close to natural language i.e. how people communicate in their day to day lives. Machine code, by stark contrast is VERY low level, and very difficult for people to understand without the use of charts and graphs, or a lot of invested time – however it does make perfect sense to the number crunching beast that is your processor. MIPS and other assembly languages can be seen as a kind of middle ground between those two contrasts; it's fairly human friendly, and is also very close to machine code.
What is machine code used for?
All programming languages, C++, Java, even MIPS, need to be compiled into machine code to run. Your processor can't understand it otherwise. Technically, machine code is all you need to create a program, but as was said earlier, it can be very difficult to understand, and even harder to write. Want to see why? No problem;
Here is some code written in C++;
struct integer
{
int i;
integer (int j = 0) : i (j) {}
integer operator* (const integer &k) const
{
return integer (i + k.i);
}
};
What this does is not important, what is useful to note is that we can create our own variables using letters, or even words, and the maths is close to real world formulae. Here is some machine code;
8020 78
8021 A9 80
8023 8D 15 03
8026 A9 2D
8028 8D 14 03
802B 58
802C 60
802D EE 20 D0
8030 4C 31 EA
As we can see, it is not much more than numbers; in fact it is hexadecimal, a number system specific to computing. Even if you do not understand the code, it should be clear how different the two are.
OK, that is harder. But if C++ can be compiled into machine code, why do we still need assembly languages?
In short, we don't, not for many day-to-day applications anyway. However, being able to understand how our source code relates to machine code is useful; the fundamentals of binary math and memory allocation are actually easier to understand in assembly. And assembly languages are still used; Some elements of Windows OS are still done in assembly, and in fact some games have been done in assembly (more recently than you might think). The reason for this is because high level code carries a certain amount of overhead, and can be done more efficiently in assembly. You also have greater control when writing in assembly; a compiler will take certain liberties when it does it job, liberties that you would otherwise have to manage.
What was that about games??
In the lifetime of a console, games tend to get more complex, and look better with time. But how is that possible when the consoles' spec remains unchanged? Well when the game “Jax and Daxter” was released back in 2001 it pushed the boundaries for graphic beauty on the Playstation 2 console. A huge reason for this is because nearly the entire game was written in MIPS assembly, and so coders where able to (and here is the key word to answer that rhetoric; ) optimise the game flow to a staggering degree, resulting in a game that has sold over 2million copies to-date.
So games can be written in assembly language on the PS2?
Yes! More specifically, games can be written in MIPS on any of the Playstation consoles; I will in fact be writing a game designed for the PSP using MIPS in the coming weeks.
Excellent! So can you write games in MIPS for any console?
No, each console has a slightly different architecture, and assembly language is always written for a specific chipset; Sony use MIPS for their machines.
Any chance we can see some MIPS?
Finding code for the PS can be tricky unless your willing to decompile the stuff yourself. As I don't have ANY PS games with me, it makes it pretty much impossible. However I did find some MIPS code that does work on the PSX (i.e. Playstation, before the PS-One). The printgpu.zip file on this site; http://psx.rules.org/psxrul2.shtml is where I found it if you wish to view the file in it's entirety. Here is a snippet, just as an example of MIPS on the PS;
lui a0, $0800 ; initialise the GPU
jal InitGPU ; command 8
ori a0,a0,$0009 ; bit $00,$01= %01 -> screen width:320
; bit $03 = 1 -> video mode = pal
la a0,back ; draw a nice backdrop
jal SendList ;
nop ;
jal Loadfont ; upload font data.
nop ;
la a0,text1 ; a0 = pointer to string.
li a1,$00200018 ; a1 : y<<16|x (y=$20,x=$20)
li a2,$00808080 ; a2 : bgr = 808080 = white.
jal PrintGPU_dma ; print
nop ;
jal SendList ; plot text.
or a0,zero,v0 ;