# Need help converting machine code

I would appreciate some help with this question.

The 32 bit numbers below represent a MIPS instruction. identify the different fields and state which instruction it is. give the assembler source code that can be converted into this instruction.

001000|10001|10010|0000000000001111

I separated the bits and I know the first 6 bits are the opcode and given the opcode it means Addi. The last 16 bits are the immediate value which I have converted to 15. I do need help with the registers and converting the binary into the register number. I have looked everywhere and can not find an explanation. Any help would be appreciated. i know the structure takes this format:

Addi, t,s, 15

## 1 Answer

You've basically got the answer already: the s register is number 0b10001 = 17, the t register is number 0b10010 = 18.

The instruction is not quite the way you've said it: standard MIPS has the registers in the opposite order, so it's opcode rs rt immediate. The opcode is 0b001000 = 8 = ADDI; rs is 0b10001 = 17 = $s1; rt is 0b10010 = 18 = $s2; the immediate value is 0b0000000000001111 = 15.

(The prefix 0b indicates that the following number is in binary.)

• Thank you. i haven't been able to find an information on it. would i need to write $t17? Commented Aug 31, 2018 at 20:24 • @jessie For the registers? For e.g. register 17 you can either use $17 or $s1 (its symbolic name). Commented Aug 31, 2018 at 20:30 • is there an efficient way to convert say r17 to its symbolic name$s1? Commented Aug 31, 2018 at 20:32
• @jessie Looking it up in a table is the easiest way. This one was the first hit on Google. Commented Aug 31, 2018 at 20:34
• Thank you. this will help with my studies. can i ask if i was to convert the other way say: add r3, r5, r4. Would you know how i would go about converting those registers? would it be as simple as convert say r4 to 0100? Commented Aug 31, 2018 at 20:37