cs3330-chap3-arith-1

cs3330-chap3-arith-1 - CS/ECE 3330 Computer Architecture...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS/ECE 3330 Computer Architecture Chapter 3 Arithmetic ± Operations on integers ± Addition and subtraction ± Multiplication and division Arithmetic for Computers ± Dealing with overflow ± Floating-point real numbers ± Representation and operations CS/ECE 3330 – Fall 2009 1
Background image of page 1

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

View Full Document Right Arrow Icon
2 ± Example: 7 + 6 Integer Addition ± Overflow if result out of range ± Adding +ve and –ve operands, no overflow CS/ECE 3330 – Fall 2009 2 ± Adding two +ve operands ± Overflow if result sign is 1 (b/c MSB is the sign bit) ± Adding two –ve operands ± Overflow if result sign is 0 Positive 15 01111 14 01110 13 01101 12 01100 5 Bit 2’s Complement Negative -1 11111 -2 11110 -3 11101 -4 11100 11 01011 10 01010 9 01001 8 01000 7 00111 6 00110 5 00101 -5 11101 -6 11010 -7 11001 -8 11000 -9 10111 -10 10110 -11 10101 CS/ECE 3330 – Fall 2009 4 00100 3 00011 2 00010 1 00001 0 00000 3 -12 10100 -13 10011 -14 10010 -15 10001 -16 10000
Background image of page 2
3 ± Add negation of second operand ± Example: 7 – 6 = 7 + (–6) +7: 0000 0000 … 0000 0111 Integer Subtraction –6: 1111 1111 … 1111 1010 +1: 0000 0000 … 0000 0001 ± Overflow if result out of range ± Subtracting two +ve or two –ve operands, no overflow ± Subtracting +ve from –ve operand CS/ECE 3330 – Fall 2009 ± Overflow if result sign is 0 ± Subtracting –ve from +ve operand ± Overflow if result sign is 1 4 ± Assume 5-bit representation [i.e., max=01111 (15d), min=11111 (-16d)] ± Positive overflow example: Overflow Examples 10d + 7d = 17d (overflow) +10d: 01010 +7d: +00111 +17d: 10001 overflow ± Negative overflow example: -4d 13d = 17d (overflow CS/ECE 3330 – Fall 2009 -4d - 13d = -17d (overflow) Subtract by adding -13d -4d: 11100 -13d: 10011 -17d: 101111 overflow 5
Background image of page 3

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

View Full Document Right Arrow Icon
4 ± Some languages (e.g., C) ignore overflow ± Use MIPS addu , addui , subu instructions ± Other languages (e.g., Ada, Fortran) require Dealing with Overflow raising an exception ± Use MIPS add , addi , sub instructions ± On overflow, invoke exception handler ± Save PC in exception program counter (EPC) register
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 12

cs3330-chap3-arith-1 - CS/ECE 3330 Computer Architecture...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online