1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: How can I translate this mips code into binary/hexadecimal

  1. Dec 26, 2011 #1

    I have two doubts, In an exercise I have to convert a MIPS instruction into hexadecimal code. I understand a part of it.
    The instruction given by the professor is:
    Exercise 2 : bne $t2, $zero, previous instruction
    The solution is
    Co =0b0 00101, $rs =0b0 1010,$rt =0b0 0000, Imm16 = 0b1111 1111 1111 1110= 0xFFFE
    So the whole instruction is : 0x1540 FFFE.

    I understand that bne = 000101, and $t2 occupies the 10th position that $t2 is 01010. But I do not understand why Imm16 = 0b1111 1111 1111 1110= 0xFFFE
    Can anybody help me?
    The previous instruction (since it makes reference to the previous instruction it may be usefull) was :
    Exercice 1 addi $t3 , $t2 ,-1 and the solution :
    Co =0b0 01000,$rs =0b0 1010,$rt =0b0 1011,Imm16 =0b1111 1111 1111 1111
    And the instruction : 0x214B FFFF
    Another doubt is (more or less the same) :
    I am given this :
    Exercise 3: bne $t2, $zero, current instruction and the solution is :
    Co =0b0 00101, $rs =0b0 1010,$rt =0b0 0000, Imm16 = 0b1111 1111 1111 1110= xFFFF So the whole isntruction is 0x1540 FFFF. What I do not understand here is the same, why does Imm16 = 0b1111 1111 1111 1110 ??

    Anybody can help me?
  2. jcsd
  3. Dec 27, 2011 #2


    Staff: Mentor

    Imm16 means "immediate 16-bit address." This is in contrast to an indirect address.

    For this instruction, what I believe happens is that when this instruction is read, the program counter (PC) is at the beginning of the next instruction. If the number in $t2 isn't zero, control branches to the preceding instruction, which is 8 bytes (or 2 machine words) lower in memory. If the number in $t2 is zero, control continues from the next instruction, which is the address in the PC.

    The branch instructions use offsets in units of 32-bit machine words. So a branch to the previous instruction takes an offset of -2, which is 0xFFFE.
    Here 0xFFFF is not an address - it is -1. If I recall what this does, it adds -1 to register $t2, and then copies that to $t3.
    You have a mistake here. The number in binary should be 0b1111 1111 1111 1111.
    Again, no it's not. 0xFFFF = 0b1111 1111 1111 1111
  4. Jan 1, 2012 #3
    Thank you very much for your help!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook