# 5 - Arithmetic Operations 1 Outline overflow...

This preview shows pages 1–9. Sign up to view the full content.

1 Arithmetic Operations

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Outline Arithmetic Operations overflow Unsigned addition, multiplication Signed addition, negation, multiplication Using Shift to perform power-of-2 multiply/divide Suggested reading Chap 2.3
3 Unsigned Addition • • • • • • u v + • • • u + v • • • True Sum: w +1 bits Operands: w bits Discard Carry: w bits •UAdd w ( u , v )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Unsigned Addition Standard Addition Function Ignores carry output Implements Modular Arithmetic s  = UAddw(u , v) = (u + v)  mod 2 w
5 Signed Addition Functionality True sum requires  w+1  bits Drop off MSB Treat remaining bits as 2’s comp. integer < + + + + + + < - + = ) ( , 2 , ) ( , 2 ) , ( NegOver TMin v u v u TMax v u TMin v u PosOver v u TMax v u v u Tadd w w w w w w

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Signed Addition u v < 0 > 0 < 0 > 0 •NegOver •PosOver TAdd( u , v ) •–2 w –1 –2 w •0 •2 w –1 •2 w –1 •True Sum TAdd Result •1 000…0 •1 100…0 •0 000…0 •0 100…0 •0 111…1 •100…0 •000…0 •011…1 •PosOver •NegOver
7 Detecting Tadd Overflow Task – Given s  =  TAdd w (u , v) – Determine if s   = Add w (u , v) Claim Overflow iff either: u, v < 0, s   0 (NegOver) u, v   0, s < 0 (PosOver) ovf = (u<0 == v<0) && (u<0 != s<0); 0 2 w –1 2 w –1 •PosOver •NegOver

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document