-2

Since its a r type operation, opcode is 000000 and source register is 11111 what are the other 2 registers for source and another for destination? And how do we write machine code for j type operations?

  • 2
    _"For instructions that do not use all of these fields, the unused fields are coded with all 0 bits."_ [See also](https://phoenix.goucher.edu/~kelliher/f2009/cs220/mipsir.html) – Jester Apr 19 '23 at 00:25
  • 1
    You could use a known-good MIPS assembler like `clang -target mips -c foo.s` to make machine code, and `llvm-objdump -d foo.o` to see it. If you want to know *why* the fields are what they are, check the MIPS manuals, or ask that in your question with the actual field values you found from using an assembler. – Peter Cordes Apr 19 '23 at 00:35
  • 1
    A detailed instruction manual will say what value to set for unused fields, usually zeros. This allows forward compatibility, meaning that old code will still run properly on newer processors, if designers choose to use unused fields to take on new meaning (for non-zero values) for the newer processors. – Erik Eidt Apr 19 '23 at 16:34

1 Answers1

0

A handy reference for MIPS instruction opcodes. In this case there would be no destination as it is not required (unless you count the implicit use of PC).

As for how J type instructions are written, they have the function followed by an encoded target address.

Just a little comment, in future you should add a little more information to your question (such as you are asking about MIPS, as it is not entirely clear by the question title).

  • While ``J` is a J-type instruction, the opcode in question, `jr` is not. – Erik Eidt Apr 19 '23 at 16:33
  • 1
    Yes, I should have made it a little clearer the sentence starting 'J type' was for the second question. – AlexBliss24 Apr 20 '23 at 17:18
  • The question is tagged [mips]. The Stack Overflow policy is that titles should mostly *not* include things specified by tags, including language (e.g. C++, Java, or MIPS Assembly). I don't always agree with that policy (since SO's internal search is garbage vs. using google or whatever, so you can't get tag filtering and good search results), but it's standard practice to title the way they did. (And they did much better than some people, who post with useless titles like "MIPS assembly question". The question itself isn't great, an assembler could have answered it for them, though.) – Peter Cordes Apr 21 '23 at 02:27
  • Re: encoding J-type instructions, see [How to Calculate Jump Target Address and Branch Target Address?](https://stackoverflow.com/q/6950230) re: the immediate part. – Peter Cordes Apr 21 '23 at 02:29
  • @PeterCordes thanks for the feedback, I am rather new to answering the questions so I did not realise. I'll take a look through the guidelines. – AlexBliss24 Apr 22 '23 at 10:30