Login Register
MoHH2 Legendz

Legends of Medal of honor:Heores 2.. Never forgotten RiP in piece


    You are not connected. Please login or register

    View previous topic View next topic Go down  Message [Page 1 of 1]

    Post: #1Thu Sep 15, 2011 5:58 pm

    FoodFx

    FoodFx

    Senior Member


    Section 2: Learning Basic MIPS Instructons and how to use them



    Basic MIPS Intructions:

    Loading Commands:

    lui - Load upper immidiate
    lw - Load Word
    lh - Load half word
    lb - Load Byte

    Storing Commands:

    sw - Store Word
    sh - Store Halfword
    sb - Store Byte

    Branch Commands:

    bne - Branch on not equal
    beq - Branch on equal

    Jump Commands:

    jr - Jump Register
    j - Jump
    jal - Jump and link

    Other Commands:

    addiu - add immidiate unsigned
    nop - No operation

    Registers:

    $t0-$t9 - Temporary Registers
    $ra - Return address
    $zero($0) - zero


    How to use the MIPS:
    Loading Commands:

    lui:


    Loads 32-Bits of a code and shifts it 16-Bits to the left. Meaning what it does is loads the first half of a code. it looks like this when you use it :
    Code:
    lui t0, $00000880
    It is loading the 0880 at the end.


    lw:

    Load the value in the a register to another register. Meaning it's loading the value of the address/pointer in the register you tell it to.It looks like this when you use it:
    Code:
    lui t0, $0880
    lw t1, $3FFC(t0)
    It is loading the value in 08803FFC and loading it to t1.

    lh:

    Loads 4 numbers in a register and loads it back to another register. Pretty much just loading the address. It looks like this when you use it:
    Code:
    lui t0, $0880
    lh t1, $3FFC(t0)
    Is loading halfword/16-bits 4 numbers of the value of 08803FFC in t1 and loading it back to t0.

    lb:

    Loading a byte into a register and loads it into another register. Looks like this when youuse it:
    Code:
    lui t0, $0880
    lb t1, $3FFC(t0)
    Is loading a byte/8-Bit of the value in 08803FFC into t1.

    Storing Commands:

    sw:

    Stores 32-bits of the value in a register and stores it in another register. Example:
    Code:
    lui t0, $0880
    lui t1, $1337
    addiu t1, t1, $1337
    sw t1, $3FFC(t0)
    The value in t1 is 13371337 and then it stores it back into t0 which is 08803FFC.

    sh:

    Stores 16-bit of value in a register into another . Example:
    Code:
    lui t0, $0880
    lui t1, $1337
    addiu t1, t1, $1337
    sh t1, $3FFC(t0)
    What this is doing is loading 13371337 into t1 but its only storein 1337 into t0 which is 08803FFC.

    sb:

    Stores 8-Bits of code in a register and stores it into another register. Example:
    Code:
    lui t0, $0880
    lui t1, $1337
    addiu t1, t1, $1337
    sb t1, $3FFC(t0)
    What this is doing is loading 13371337 into t1 but its only storein 37 into t0 which is 08803FFC.

    Branch Commands:
    *Important Branch Command Rule: Their must be a delay slot at all time after the usage of a branch command. The most common delay slot is the MIPS Command "nop". nop is not the only way you can put the delay slot here is an example of another way.

    Code:
    lui t0, $1337
    lui t1, $0880
    lw t2, $3FF0(t1)
    bne t2, t0, $To jr ra line
    sw t2, $3FF4(t1)//Delay Slot
    jr ra
    sw t0, $3FF0(t2) //Delay Slot
    What this is doing is checking if the values in t2 and t0 are not equal. If they are go on but if they arn't jump/branch/go to jr ra line. If it does equal it will store the value in t2 in 08803FF4 and then store the value in t0 back into 08803FF0 before repeating. But if it does not equal go to jr ra store t0 on 08803FF0 before repeating. So everything is running smoothly like it's suppose to.

    bne:

    Branchs if the value in two certain registers don't equal. Branch lines can be commonly reffered to a check point. Example:
    Code:
    lui t0, $0880
    lw t0, $3FFC(t0)
    addiu t1, zero, $0001
    bne t0, t1, $To jr ra line
    nop //Delay Slot
    jr ra
    nop //Delay Slot
    The bne line what is doing is checking if the value in 08803FFC and 00000001 are equal. If they are not jump/branch/go to the jr ra line.

    beq:

    Branchs if the value in two certain registers equal. Branch lines can be commonly reffered to a check point. Example:
    Code:
    lui t0, $0880
    lw t1, $3FFC(t0)
    lw t2, $1880(t0)
    beq t1, t2, $To jr ra line
    nop //Delay Slot
    lw t3, $3FFC(t0)
    addiu t4, t3, $0001
    sw t4 $3FFC(t0)
    jr ra
    nop //Delay Slot
    The beq line checks if the values in 08803FFC and 08801880 equal if they do jump/branch/go to the jr ra line. If they dont load 08803FFC and add 00000001 and store it back to 08803FFC.

    Jump Commands:
    *Important jump command rule: Just like the important branch rule at all time their must be a delay slot after the jump command line. For more info reffer to the Branch Command Rule Section.

    jr:

    The jr command is very simple. It jumps to the address stored in a specific register. Example:
    Code:
    lui t0, $0880
    lw t1, $1880(t0)
    lw t2, $1000(t0)
    jr t1
    nop //Delay Slot

    j:

    This jumps to a specified address. Yes very simple. Example:
    Code:
    j $To Segment 1
    lui t0, $0880 //Segment 1
    lui t1, $1337
    addiu t1, t1, $1337
    sw t1 $3FFC(t0)
    jr ra // Jumps to return address. The return address here is the j line

    jal:

    This calls a subroutine into another subroutine. An example this will involve a function and more advanced mips a vague explination will come with it:
    Code:
    addiu sp, sp, $FFF0//Subtracts from the stack
    sw ra, $0000(sp) //Segment 1
    sw s0, $0004(sp) //Segment 2
    sw s1, $0008(sp) //Segment 3
    lui t0, $0880
    lw t0, $3FFC(t0)
    jal $08801880 //Random address
    sw t0 $3FFC(t0)
    lw s1, $0008(sp) //Segment 1.1
    lw s0, $0004(sp) //Segment 2.1
    lw ra, $0000(sp) //Segment 3.1
    jr ra
    nop //Delay Slot
    The Segments are an important part for functions so it wont mess anything else up in the function you are calling with jal. This is loading 08803FFC then it jumps to another function "08801880" then it stores what the function is doing back into 08803FFC. You can do this like how much damage you take then you can store the damage into 08803FFC with the subroutine above.

    Other Commands:

    addiu:

    Adds a value to a register and stores it to another register. Here is a example:
    Code:
    lui t0, $0880
    lw t0, $3FF8(t0)
    addiu t1, t0, $0004
    What this is doing is adding 00000004 to 08803FF8 makeing it 08803FFC. Ater adding 00000004 to it it stores the result in t1 so t1 = 08803FFC.

    nop:

    No operation. Nothing empty area its value is 00000000. It is used as delay slots and to take up space. An example of both:
    Code:
    nop
    nop
    nop
    nop
    nop
    nop
    nop //All the nop above taking up space
    lui t0, $0880
    lw t1, $3FFC(t0)
    lw t2, $3FF8(t0)
    bne t1, t2, $To Jr Ra line
    nop //Delay Slot
    sw t2 $3FF4(t0)
    jr ra
    nop //Delay Slot

    Registers:

    $t0-$t9:

    Temporary Registers hold values in them. What ever you load and store them in they are holding. You can overwrite them so be careful what you are writing into them. Here are two examples of perfect and overwriting.

    Not overwriting:
    Code:
    lui t0, $0880
    lw t1 $3FFC(t0)
    lw t2, $3FF8(t0)
    This is not overwriting any registers. 08803FFC is being loaded into t1 and 08803FF8 is being loaded into t2.

    Overwriting:
    Code:
    lui t0, $0880
    lw t1, $3FFC(t0)
    lw t1, $1880(t0)
    This overwrites the register t1. first it's loading 08803FFC into t0 then it loads 08801880 which overwrote the first loading.

    $ra:

    This stores the address that calls the subroutines it's in. Meaning it's calling a jump command address. Example a common subroutine:

    Code:
    j $Segment 1 //Now becomes the $ra in the subroutine
    lui t0, $0880
    lui t1, $1337
    addiu t1, t1, $1337
    sw t1, $3FFC(t0)
    jr $ra //It's jumping to the address in the register i this case it's ra
    This is why some coders say jr $ra ends the subroutine because it starts the cycle again.

    $zero:

    Always has the value of zero. If something tries to overwrite this register it is ignored at stays zero. I am not going to bother adding an example for $zero it's really simple.
    =========================================
    Code:
    Lesson 2: Learning Basic MIPS Instructons and how to use them
    Created by: FoodFx


    Post: #2Thu Sep 15, 2011 6:20 pm

    StriickeN

    StriickeN

    Admins
    Admins


    nice guide Smile looks like it took forever to make i hope fragon learns something Rolling Eyes


    http://www.psvmods.net

    Post: #3Fri Sep 16, 2011 12:04 am

    Ralph

    Ralph

    Admins
    Admins


    mips are confusing


    http://www.*******.com

    Post: #4Fri Sep 16, 2011 1:28 am

    Anonymous

    Guest

    Guest


    i feel like i am on the brink of understanding it. Food i shall ask you many questions when i am not so tired


    Post: #5Fri Oct 28, 2011 12:04 am

    Vet

    Vet

    Elite Member


    whats t0 t1 etc?


    Post: #6Fri Oct 28, 2011 12:14 am

    avatar

    Brian-1337-

    Senior Member


    temporary registers. t0 t1 t2 t3 t4 t5 t6 t7 t8 t9


    https://www.facebook.com/Mips.Brian1337

    Post: #7Fri Oct 28, 2011 12:16 am

    StriickeN

    StriickeN

    Admins
    Admins


    thanks that kinda confused me too Smile


    http://www.psvmods.net

    Post: #8Fri Oct 28, 2011 1:11 am

    Vet

    Vet

    Elite Member


    temporary registers? still dont understand


    Post: #9Fri Oct 28, 2011 10:21 pm

    Gangsta-Piggy

    Gangsta-Piggy

    Senior Member


    this is either sooo confusing or i am soooo lazy to read this but....... ima stick with cheat searching and and other small hacks


    Post: #10

    Sponsored content





    View previous topic View next topic Back to top  Message [Page 1 of 1]

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