



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























Chapter 3.1 - Integers
1
32-bit binary representation of (unsigned) number:
b
31
31
+ b
30
30
+ b
2
2
+ b
1
1
+ b
0
0
One billion (1,000,000,
10
) in binary is
2
(^28)
24
20
16
12
8
4
0
29
28
27
25
24
23
20
19
17
15
14
11
+ 1x
9
docsity.com
Chapter 3.1 - Integers
2
Binary bit patterns are simply representations of numbers.
-^
Numbers really have an infinite number of digits (non-significantzeroes to the left).
If result of add (or any other arithmetic operation) cannot berepresented by these rightmost hardware bits, overflow is said tohave occurred.
-^
Up to Compiler and OS what to do.
docsity.com
Chapter 3.1 - Integers
4
If "exception" (or "interrupt") occurs
routine for that exception
Operating System decides what to do
executed
MIPS hardware support: exception program counter (EPC)contains address of overflowing instruction --- (more in Chpt. 5)
docsity.com
Chapter 3.1 - Integers
5
Two
s Complement
What is result for unsigned numbers if subtract larger numberfrom a smaller one?
so result would have a string of leading 1s
the hardware simple:
leading 0s
positive,
leading 1s
negative
xxx
xxx
This representation is called two
s complement
docsity.com
Chapter 3.1 - Integers
7
Recognizing role of sign bit, can represent positive and negativenumbers in terms of the bit value times a power of 2:
31
31
d
30
30
2
2
1
1
0
0
Example (given 32-bit two’s comp. number)1111 1111 1111 1111 1111 1111 1111 1100
2
31
30
29
2
1
0
31
30
29
2
10
10
10
docsity.com
Chapter 3.1 - Integers
8
(1) Sign and magnitude
(2) Two’s (2’s) Complement (
n
bit positions)
n
-bit pattern d
n -
d
d 2
1
d
0
means:
-1 × d
n -
n -
2
2
1
1
0
0
n
-bit number and its negation = 2
n
positive
one
negative
one
(2’s
comp)
4
(=zero
if
only
bits)
docsity.com
Chapter 3.1 - Integers
10
Bias= 8 (Subtract 8)
1111111011011100101110101001100001110110010101000011001000010000
-1-2-3 -4-5-6 -7-8^76543210
(^0) -1-2 -3-4-5 -6-7 7 6 5 4 3 2 1 0
(^76543210) -1-2 -3-4-5 -6-7 -
151413121110
9 8 7 6 5 4 3 2 1 0
b
b 3
b 2
b 1
0
Bit-Pattern,
Unsigned,
2’s Comp, 1’s Comp,
Biased
docsity.com
Chapter 3.1 - Integers
11
Note: memory addresses naturally start at 0 and continue to thelargest address – they are unsigned.
C makes distinction in declaration.
int
) can be positive or negative.
unsigned
int
) only positive.
Thus MIPS needs two styles of comparison.
slt
) and set on less than immediate (
slti
work with signed integers.
sltu
) and set on less than immediate
unsigned (
sltiu
). (Will work with addresses).
docsity.com
Chapter 3.1 - Integers
13
Invert every 0 to 1 and every 1 to 0, then add 1 to the result
be 111...
2
10
x´
mean the
inverted representation
of
x
x
x´
x
x´
x´
x
Example: -4 to +4 to -
-^
x
2
x
2
2
x
2
2
docsity.com
Chapter 3.1 - Integers
14
Convert number represented in
k
bits to more than
k
bits
e.g.
, 16-bit immediate field converted to 32 bits before adding to 32-bit
register in addi
Simply replicate the most significant bit (sign bit) of smaller quantityto fill new bits
those that fit in the integer variable
10
to 32-bit:
2
2
Using Sign extension
docsity.com
Chapter 3.1 - Integers
16
-^
Convert the two’s complement number1111 1111 1111 1111 1111 1111 1111 1010
2
into decimal (base ten):
-^
Could use conversion formula (hard)1 x -
31
30
1
0
-^
Or, first use negation shortcut (easy) 0000 0000 0000 0000 0000 0000 0000 0101
1
0000 0000 0000 0000 0000 0000 0000 0110
= 6 (therefore, answer: -6)
docsity.com
Chapter 3.1 - Integers
17
two 1-bit values gives four cases:
0
0
1
1
0
1
0
1
0
1
1
(1) 0
digital logic?: half-adder circuit
carry-out
1-bit sum
a b
sumcarry-out
docsity.com
Chapter 3.1 - Integers
19
Adding 2 31-bit positive 2’s complement numberscan yield a result that needs 32 bits
sign of result (0)
°
Op Adding operands with different signs, (subtracting withsame signs) overflow cannot occur
A
B
Result
A
+
B
>=
>=
<
A
+
B
<
<
>=
A
-
B
>=
<
<
A
-
B
<
>=
>=
docsity.com
Chapter 3.1 - Integers
20
Adding 2 32-bit unsigned integers could yield a resultthat needs 33 bits
Unsigned integers are commonly used for addressarithmetic, where overflows are ignored
-^
Hence, MIPS has unsigned arithmetic instructions,which ignore overflow:
instructions are always used (different for Fortran, Ada)
docsity.com