| New Reply |
Help with converting machine language instruction into MIPS assembly instruction |
Share Thread | Thread Tools |
| Dec2-10, 08:47 PM | #1 |
|
|
Help with converting machine language instruction into MIPS assembly instruction
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.
|
| Dec2-10, 10:18 PM | #2 |
|
Mentor
|
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...al/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? |
| Dec2-10, 11:18 PM | #3 |
|
|
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 thats 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. |
| Dec4-10, 09:07 PM | #4 |
|
|
Help with converting machine language instruction into MIPS assembly instruction
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. |
| Dec5-10, 12:15 AM | #5 |
|
Mentor
|
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.
|
| Dec5-10, 04:12 PM | #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/fil...nager-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. |
| Dec6-10, 09:45 AM | #7 |
|
Mentor
|
Your question in post #4 was
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. |
| Dec6-10, 02:20 PM | #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? |
| Dec6-10, 03:40 PM | #9 |
|
Mentor
|
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? |
| Dec6-10, 10:34 PM | #10 |
|
|
Ok, got it! Thank you very much for your help!
|
| New Reply |
| Thread Tools | |
Similar Threads for: Help with converting machine language instruction into MIPS assembly instruction
|
||||
| Thread | Forum | Replies | ||
| Changes in Intro Physics Instruction | Educators & Teaching | 5 | ||
| single instruction | Engineering, Comp Sci, & Technology Homework | 2 | ||
| Instruction needed | Differential Equations | 7 | ||
| Clock cycles per instruction? | Computing & Technology | 3 | ||
| [ASM] Instruction Offset | Computing & Technology | 2 | ||