+ Reply to Thread
Results 1 to 1 of 1
  1. #1
    Join Date
    Apr 2009
    Location
    In front of my PC
    Posts
    23
    Points
    57,939.00
    Rep Power
    188

    Default MIPS Basics TUT Nr. 1

    Ok first of all this is a very simple help for some guys to understand how MIPS works.
    It is not finished yet and if HX- or some guys think that this TUT is useless than I am sorry because this is my first TUT.

    First of all cause there are lot of information about the commands of MIPS (instructions= ADD, ADDIU, LW, LUI, NOP, ORI, and so one) but less information about the registers used in MIPs here a qiuck list:

    Name of the Register: Number: Usage:
    zero; 0; Constant 0
    at; 1; Reserved for the Assembler
    v0 - v1; 2-3; Result Registers
    a0 - a3; 4-7; Argument Registers 1...4
    t0 - t9; 8-15; 24-25, Temporary Registers 0...9
    s0 - s7; 16-23; saved Registers 0...7
    k0- k1; 26-27; Kernel Registers 0...1
    gp; 28; Global Data Pointer
    sp; 29; Stack Pointer
    fp; 30; Frame Pointer
    ra; 31; Return Address (helpfull for subroutining)



    Ok now a first lesson in how MIPS is working. I will do it in a small exercise.

    Lets say we wanna do the sum of 1 and 2 (1+2) and store the result into a register.


    So lets use a Register from above for example t0. t0 will will store the result of the sum of 1 and 2 (3).

    Ok to tell MIPS that we wanna sum two numbers we have to use an instruction.
    So if you know the most instructions of MIPS it is clear which one we should choose:
    It is the instruction ADD. So to remember what ADD is doing: ADD adds two registers and stores the result in a rgister ( in this case t0). Basicly thats the reason why we chose the instruction ADD.

    But as you can see in the desription of ADD above it only adds REGISTERS so we have to put our number 1 and our number 2 into a REGISTER.

    We will use the following REGISTERS for 1 and 2: $t1 = 1 and §t2 = 2
    OK in sum what we know untill now is:

    We need the instruction ADD to tell MIPS that it have to sum 1 an 2
    (2.) and we need the register t0 to store the result of this add operation.
    (3.) we decided to put 1 into register t1 and 2 into register t2

    Now we are going to load our numbers into the registers (t1 and t2)
    To tell MIPS that it should load the numbers into registers we have to use another instruction; in this case the LI instruction. Why??? Because LI loads immediate value so it is exatly the instruction we need. (Our values: 1 and 2)


    So it would be like this:

    LI §t1, 1 # load 1 into §t1
    LI §t2, 2 # load 2 into §t2
    ADD §t0, §t1, §t2 # §t0 = $t1 + §t2



    so in niterPR it looks like that:

    Note: I use a random address (doesnt matter what address you choose)

    0x0000006C 0x3C090001 ( i used LUIs because there arent any LIs in NitePR and
    0x00000070 0x3C0A0002 LUIs do the same like LIs)
    0x00000074 0x012A4020 add t0, t1, t2


    Ok this was my first TUT and I hope this will help some people to understand MIPS better. If you need a good Programm for learning MIPS then use SPIM( google)
    Last edited by PSP_Lord; 04-30-2009 at 02:58 PM.
    Please rep if my posts help you.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts