Lecture Note 9
Arithmetic for Computers : Integer arithmetics
-
addition
- start from lsb, carry out values added to next digits
- overflow: result of the operation is out of range
- positive + negative -> no overflow
- positive + positive -> overflow if res is neg
- negative + negative -> overflow if res is pos
-
subtraction
- negation of second operand + perform addition
- overflow: result of the operation is out of range
- positive - negative -> overlow if neg
- negative - positive -> overflow if pos
- positive - positive -> no overflow
- negative - negative -> no overflow
-
programming languages dealing with overflow
addu, addui, subu
ignores overflow: treating like unsigned arithmetics, which ignores sign bits- invoke exception handler
- push pc to epc (exception program counter)
- jump to predefined handler address
-
arithmetic for multimedia
- 8bit, 16bit used: small data size
-
multiplication
- long multiplication approach: multiplicand * multiplier bit by bit
-
division
-
overflow