2
\$\begingroup\$

Recently I was reading the "Computer Organization and Design" Book By Patterson and Hennessy, and I came across the question that in order to make the immediate data 32 bit in Immediate type instructions(generally load/store), we sign extend it, but why we do not zero extend it instead?

thanks in advanced

\$\endgroup\$
4
  • \$\begingroup\$ which architechure are you reffering x86, IA-32,please write a brief question,which instruction's you talking about ? \$\endgroup\$
    – MaMba
    Aug 27, 2015 at 14:21
  • \$\begingroup\$ I am talking about MIPS instructions, in that the load, store instructions have the immediate data as sign extended, while the ori instruction has immediate as zero extended \$\endgroup\$
    – DCP
    Aug 27, 2015 at 14:24
  • \$\begingroup\$ cs.umd.edu/class/sum2003/cmsc311/Notes/Mips/load32.html \$\endgroup\$
    – MaMba
    Aug 27, 2015 at 14:54
  • \$\begingroup\$ thank you very much for you effort, this really helped me \$\endgroup\$
    – DCP
    Aug 27, 2015 at 15:02

2 Answers 2

4
\$\begingroup\$

You have a limited number of bits in a 32-bit instruction word to create a 32-bit immediate value. If you can't create it this was, you will have to use multiple instructions or other tricks (slower, take more memory). So let's say you have 10 bits. What would be more usefull, being able to create

  • 0 .. 1023, or
  • -512 .. 511 ?

You can decide from intuition, or from data gathered from compiler back-ends, but in most cases people have concluded that including at least -1 is more usefull than doubling the range on the positive side.

IIRC ARM decided to use a slightly more complex scheme, using a few of the available bits to specify how much places the value must be shifted to the left. This sacrfices the number of small values that can be made, but gains a few (widely separate) larger values, which is nice for instance for bit fields within a word. But it requires barrel shifter hardware. The MIPS designers thought the transistors needed for a barrel shifter would be better used for other purposes.

The very good aspect of the H & P books is that they quantify the effects of such design decisions. Do read all their books, not just this one.

\$\endgroup\$
7
  • \$\begingroup\$ I understand that thing, but in load instruction in MIPS, we pass offset as immediate data(16 bit)in that and, we extend it to 32 bit using sign extender, my question is that , why don't we extend it using bit extender(zero extender). thanks \$\endgroup\$
    – DCP
    Aug 27, 2015 at 14:38
  • \$\begingroup\$ I will surely read all their books, thanks for you kind suggestion \$\endgroup\$
    – DCP
    Aug 27, 2015 at 14:39
  • \$\begingroup\$ If you 0-extend you can not create a negative value. \$\endgroup\$ Aug 27, 2015 at 14:42
  • \$\begingroup\$ but why do we need the negative values for offsets... \$\endgroup\$
    – DCP
    Aug 27, 2015 at 14:44
  • \$\begingroup\$ To address data that is at a lower address than the memory pointer you have in a register. \$\endgroup\$ Aug 27, 2015 at 14:46
0
\$\begingroup\$

This link gives the very basic idea. here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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