My lecturer told me that when I use an arithmetic I-Type command (ADDI,SUBI etc.) , the IMM field gets sign extended, and when I use a logic I-Type command (ORI,ANDI etc.) , the IMM field is just bits.

He also said that if the IMM field contains a negative number, it is represented in 2's complement.

Let's say I have a command, and two binary numbers X Y, so that X's 2's complement representation looks exactly like Y in regular representation.

Note: X is negative and not the same as Y.

Given a question in which I should say what is the value in the IMM field in an arithmetic I-Type command, how do I know if it's X or Y?

  • $\begingroup$ No, that's not what I'm asking. I'm asking: How do if the IMM field contains X or Y? $\endgroup$ – HaloKiller Mar 17 '14 at 15:40

In an arithmetic I-type command, the IMM-field is treated as a signed number. So if the first bit is 1, the number will be treated as negative (X in your terms.) The number Y is simply too large to be used as argument of an arithmetic I-type command.

  • $\begingroup$ So if the number is sign extended, the sign bit in only the lsb? $\endgroup$ – HaloKiller Mar 17 '14 at 16:04
  • $\begingroup$ It's the MSB, not the LSB. But yes, sign extending means just setting all new bits to the value of the previous MSB. $\endgroup$ – FrankW Mar 17 '14 at 16:42
  • $\begingroup$ MSB, okay. But I still don't get it: Say the IMM in a certain command is 1111111111111000, how do I know if it's a negative number represented in 2's complement or a regular positive binary number? $\endgroup$ – HaloKiller Mar 17 '14 at 16:46
  • $\begingroup$ You know it from the type of instruction (i.e. the opcode). If it's an arithmetic instruction, the number is interpreted as negative; if it's a logic instruction, the number is interpreted as positive. $\endgroup$ – FrankW Mar 17 '14 at 17:14
  • $\begingroup$ If it's an arithmetic instruction how do you know if it's negative? And if it is, how do you know where the sign extention starts? $\endgroup$ – HaloKiller Mar 19 '14 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.