How can I translate this mips code into binary/hexadecimal

  • Thread starter John_Brown
  • Start date
  • #1
Hello

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?
 

Answers and Replies

  • #2
33,720
5,418
Hello

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.
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.
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
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.
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
You have a mistake here. The number in binary should be 0b1111 1111 1111 1111.
So the whole isntruction is 0x1540 FFFF. What I do not understand here is the same, why does Imm16 = 0b1111 1111 1111 1110 ??
Again, no it's not. 0xFFFF = 0b1111 1111 1111 1111
Anybody can help me?
 
  • #3
Thank you very much for your help!
 

Related Threads on How can I translate this mips code into binary/hexadecimal

Replies
2
Views
13K
  • Last Post
Replies
5
Views
8K
  • Last Post
Replies
13
Views
33K
  • Last Post
Replies
1
Views
935
Replies
1
Views
6K
Replies
2
Views
2K
  • Last Post
Replies
2
Views
57K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
0
Views
10K
  • Last Post
Replies
20
Views
1K
Top