Help with converting machine language instruction into MIPS assembly instruction

In summary, to convert the MIPS instructions add $t0, $t0, $zero and lw $t1, 4, ($s3) to machine code binary form and MIPS instructions in hex, first look up the instructions in the MIPS instruction reference sheet to determine the binary code. Then, convert the binary code to hex. Use the instruction reference sheet to determine the correct arrangement of bits for each instruction.
  • #1
XodoX
203
0
I think it's easy, but I don't get it.

Given the machine language instruction 0x00221820. What MIPS assembly instruction does it represent?

I know the solution. It's add $3, $1, $2 I just don't know how to get there.

I know I have to convert the numbers into binary first. So you have 0000 0000 0010 0010 0001 etc..

Then you take the first 6 0's, and that's how you determine what type it is ( R-type) ? How do I do this? And then how do I know it's add $3, $1, $2 using the numbers that are left after the first 6 0's ? I know that there's a lsit where you can look it up, but you have 00221820, which is 8 segments in total. But it's just 4 commands ( add $3, $1, $2 ).
Dosen't make any sense.:frown:
 
Technology news on Phys.org
  • #2
XodoX said:
I think it's easy, but I don't get it.

Given the machine language instruction 0x00221820. What MIPS assembly instruction does it represent?

I know the solution. It's add $3, $1, $2 I just don't know how to get there.

I know I have to convert the numbers into binary first. So you have 0000 0000 0010 0010 0001 etc..
If you have a number in hex already, converting to binary is pretty easy. Each hex digit is 4 binary bits.
0x00221820 = 0000 0000 0010 0010 0001 1000 0010 0000 (base 2)

From a reference I found on the MIPS instruction set (http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html), here is the encoding for add d$, s$, t$, which means add the values in s$ and t$ and store the result in d$.

0000 00|ss sss|t tttt| dddd d|000 0010 0000

0000 00|00 001|0 0010| 0001 1|000 0010 0000

Can you match things up to figure out what s$, t$, and d$ are?
XodoX said:
Then you take the first 6 0's, and that's how you determine what type it is ( R-type) ? How do I do this? And then how do I know it's add $3, $1, $2 using the numbers that are left after the first 6 0's ? I know that there's a lsit where you can look it up, but you have 00221820, which is 8 segments in total.
That would be 8 bytes in total.
XodoX said:
But it's just 4 commands ( add $3, $1, $2 ).
Dosen't make any sense.:frown:
 
Last edited:
  • #3
XodoX said:
I think it's easy, but I don't get it.

Given the machine language instruction 0x00221820. What MIPS assembly instruction does it represent?

I know the solution. It's add $3, $1, $2 I just don't know how to get there.

I know I have to convert the numbers into binary first. So you have 0000 0000 0010 0010 0001 etc..

Then you take the first 6 0's, and that's how you determine what type it is ( R-type) ? How do I do this? And then how do I know it's add $3, $1, $2 using the numbers that are left after the first 6 0's ? I know that there's a lsit where you can look it up, but you have 00221820, which is 8 segments in total. But it's just 4 commands ( add $3, $1, $2 ).
Dosen't make any sense.:frown:

Just a few comments.

I'll assume you are writing your instruction has an increasing number from right to left. In the example you are working with its probably a good idea to write the contents of memory in byte form as they appear in increasing order of memory location.

The other thing is to know how data is arranged by your architecture. There are things called the "endianess" of your data. You can have architectures that orient your words in the normal way (A,B,C,D) = 0xABCD or in the weird way (A,B,C,D) = 0xCDAB. So that's the first thing you should check.

The next is pretty easy. For a lot of architectures you usually a byte for the instruction type so fetching the first byte will sort out that. The rest is obviously dependent on what instruction it is (register,register), (register,memory) and so on.

Again find out how data is stored with the "endianess" of the architecture and you will always get the right result.
 
  • #4
Ah, got it now! Thanks guys! However, I have been trying to to the reverse now.

You have MIPS add $t0, $t0, $zero and lw $t1, 4, ($s3) and it needs to be converted to the machine code binary form and MIPS instruction in hex. I suppose you first convert it to Hex 0x00000 ( whatever number) like above and then to the binary form. How'd I do this? I thought the hex would be on the reference sheet, but I don't see anything. Once I have that, I just convert it to binary.
 
  • #5
No, you have it backwards. Figure out what the binary code is going to be for each instruction, then convert each one to hex. Use the instruction reference whose link I gave earlier to figure out where things need to go.
 
  • #6
No, I don't have it backwards. It was hex to binary to mips. I also need mips to hex/binary. I have to use the reference sheet given to me and that's not on there. This reference sheet has it already listed, it need to be converted by me.

http://www.megafileupload.com/en/file/288158/RelativeResourceManager-pdf.html

Couldn't upload it here, it was to big. I think it's on page 3, but it only says if it's add, sub etc. I suppose 1st colum "mips opcode" and second column "binary", but that dosen't include registers etc. I don't know.
 
Last edited:
  • #7
Your question in post #4 was
XodoX said:
You have MIPS add $t0, $t0, $zero and lw $t1, 4, ($s3) and it needs to be converted to the machine code binary form and MIPS instruction in hex. I suppose you first convert it to Hex 0x00000 ( whatever number) like above and then to the binary form. How'd I do this? I thought the hex would be on the reference sheet, but I don't see anything. Once I have that, I just convert it to binary.
For the instruction add $t0, $t0, $zero, look up the add instruction in the reference I gave you. This will show you the binary form of this op code, and will show you where the various operands need to go. When you have everything in place, it's an easy matter to convert to hex. Starting from the least-significant bit (LSB), divide the binary number into groups of four bits. Convert each group into its hex equivalent.

For example, if you had these three groups - 1011 0011 0100, the hex equivalent is 0xA34.

Do the same for the lw instruction.

When you said "I thought the hex would be on the reference sheet" the writer who wrote the documentation for the op codes assumed that anyone who wanted to know the format of the machine code would be able to convert back and forth between binary and hex.
 
  • #8
No, that's not what I meant. I thought the hex of the MIPS instruction was on the sheet. Again, I can only use the sheet I posted the link to. Yours seems a little bit more clear, but I can't use it. I thought you'd have to get the Hex first. Ok, I guess I was wrong. It's the binary code you'll have to get and then convert it.
Bottom line: I can't figure out how to get the bianry code for it.

And I don't know what you're looking at, but your sheet has "0000 00ss ssst tttt dddd d000 0010 0000" for add. Is that what you mean?
 
  • #9
XodoX said:
No, that's not what I meant. I thought the hex of the MIPS instruction was on the sheet. Again, I can only use the sheet I posted the link to. Yours seems a little bit more clear, but I can't use it. I thought you'd have to get the Hex first. Ok, I guess I was wrong. It's the binary code you'll have to get and then convert it.
Bottom line: I can't figure out how to get the bianry code for it.

And I don't know what you're looking at, but your sheet has "0000 00ss ssst tttt dddd d000 0010 0000" for add. Is that what you mean?

This is the binary code. The s, t, and d letters show which bits are used for the source, target (?), and destination operands. For example, if the instruction were add $t1, $t2, $t3, the registers involved are $9, $10, and $11, with $t1 being the destination register and the other two the s$ and t$ registers.

I should say again that I haven't done any MIPS programming, but this is how it seems to work.

The five bits for sssss would be the bit pattern for 9, which is 10001. The five bits for ttttt would be the bit pattern for 10, which is 10010. The five bits for ddddd would be the bit pattern for 11, which is 10011. I've split these groups up with different colors to make them easier to comprehend.
0000 0010 0011 0010 1001 1000 0010 0000

0000 00ss ssst tttt dddd d000 0010 0000

Is that clear?
 
  • #10
Ok, got it! Thank you very much for your help!
 

What is machine language and MIPS assembly language?

Machine language is a set of binary code instructions that are directly executed by a computer's central processing unit (CPU). MIPS assembly language is a low-level programming language that is used to write machine language instructions in a more human-readable format.

Why is converting machine language to MIPS assembly important?

Converting machine language to MIPS assembly allows programmers to write code in a more user-friendly format, making it easier to understand and modify. It also allows for cross-platform compatibility, as MIPS is a widely used architecture in many computer systems.

What are the steps for converting machine language to MIPS assembly?

The steps for converting machine language to MIPS assembly include identifying the instruction type, determining the opcode and function code, identifying the registers and immediate values, and writing the assembly instruction in the correct format.

Are there any tools or resources available for converting machine language to MIPS assembly?

Yes, there are various online converters and tutorials available that can assist with converting machine language to MIPS assembly. Additionally, most MIPS assembly textbooks or manuals provide tables and charts for reference.

What are some common challenges when converting machine language to MIPS assembly?

Some common challenges when converting machine language to MIPS assembly include identifying the correct opcode and function code, handling negative numbers and overflow, and understanding the specific syntax and rules of MIPS assembly language.

Similar threads

  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
4
Replies
122
Views
13K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Programming and Computer Science
Replies
4
Views
379
  • Programming and Computer Science
Replies
1
Views
9K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
927
Back
Top