MIPS instruction encoding j 0x400090 “jump” instruction: 000010 Address 0x400090: 100 0000 0000 0000 1001 0000 Because this address has only 23 bits, we’ll pad the leading bits by three 0’s, making a total of 26 bits 00 0100 0000 0000 0000 1001 0000 4. The entire bit pattern is 000010 00 0100 0000 0000 0000 1001 0000 5. Reorganize in group of 4-bits 0000 1000 0100 0000 0000 0000 1001 0000 6. Hex pattern: 0x08400090
CSCI206 - Computer Organization & Programming Signed Integers zyBook: 5.5
How to actually do add or sub? If the registers r1, r2, hold values 3, -2, how does the operation add $r3, $r1, $r2 work? In general, how does compute do x = 4 + (-3)
How are numbers represented? A 3-bit system would have 8 different values, -4 through 3, how do we operate such that 3 + (-2) == 1? 011 + (???) = 001 -4 -3 -2 -1 1 2 3 ? 000 001 010 011
How to represent signed integers 1. Sign Magnitude The leading bit represents the sign, 0 for positive, 1 for negative, followed by the value (magnitude). 00000000 11111111 -127 00000001 1 11111110 -126 10001001
How to represent signed integers 2. 1’s Complement The leading bit represents the sign, invert the rest of the bits if a negative value. 00000000 11111111 -0 00000001 1 11111110 -1 00001001
How to represent signed integers 3. 2’s Complement The leading bit represents the sign, invert the rest of the bits if a negative value, and add 1 to the last bit. 00000000 11111111 -1 00000001 1 11111110 -2 -9
How to represent signed integers 4. Biased (excess) B = 3 p x 000 -3 001 -2 010 -1 011 100 1 101 2 110 3 111 4 B = 127 p x 00000000 -127 11111111 128 00000001 -126 11111110 127 9 A bias value, B, is usually chosen to be roughly in the middle of the range. The actual value x of a bit pattern p is x = p - B. Given x, the bit pattern should be p = x + B.
Number Encoding Summary Sign Magnitude first digit is sign (0=positive), remaining digits are magnitude 1’s Complement first digit is sign, remaining bits are magnitude. Negative numbers are stored inverted. 2’s Complement Same as 1’st complement, but negative numbers are inverted + 1. Biased redefine zero to be in the middle of the range. The distance from the virtual zero is the magnitude. Stop, do activity