Search for...

Friday, February 11, 2011

Learning Mips Series: Lesson 2 Basic loading and storing

In lesson 2, you will be learning how to load and store. The commands are rather simple but since I am a psp coder and not a pc motherboard mips programmer yet, I will teach you based off of my knowledge from the psp. All most all codes have a basic loading and storing in it, such as mark and recall (storing marked co-ords, then recall loading marked co-ordinates.)

Loading commands:

lui - Load upper immediate
li - Load immediate
lh - Load half word
lhu - Load Half word unsigned
lw - Load word
lwu - Load word unsigned
lb - Load byte
lbu - Load byte unsigned
lwc1 - Load word to floating point

lb & lbu will only load  2 digit numbers instead of all eight in hex so basically it is doing this 0x30.
lh & lhu will only load 4 digit numbers. 0x0030

here is an example code:

#psnabler
0x006343bc 0x32 <--- the 32 only has 2 digits which is called a byte
0x006343c0 0x1337 <----the 1337 only has 4 digits which is called a halfword or 16bit value
0x006343c4 0x13377331 <---the 13377331 has all 8digits which is called a word.
     ^                       ^
 Addresses        Hex values

now floating point is different, example:

0x3f800000 is our hex which would = 1

basically all load commands load stuff lol. Here is example in mips

lui $t0, 0x0880 //load upper half of address 0x0880
lw $t0, 0x3000($t0) //loads the value in 0x08803000
jr $ra // ends code
nop //delay slot

This is just loading the value in address 0x08803000, but in psp short addressing it is 0x00003000.

Now it is time for storing. You don't need all the explaination of storing because you know what the definition store means.

Storing command:

sw - Store Word
sh - Store Halfword
sb - Store Byte
swc1 - Store Word to floating point

example of storing:

lui $t0, 0x0880 // loads upper address 0x0880
lui $t1, 0x1337 //loads our upper value 0x1337
sw $t1, 0x3000($t0) //stores 0x1337 to address 0x08803000
jr $ra // end code
nop // delay slot

If any questions feel free to ask, the next tutorial will be about the delay slot and branching commands.

No comments:

Post a Comment