SLIDE 1
Tuesday, 20 October 2015 Check your exams! (problem 10) --see email - - PowerPoint PPT Presentation
Tuesday, 20 October 2015 Check your exams! (problem 10) --see email - - PowerPoint PPT Presentation
Tuesday, 20 October 2015 Check your exams! (problem 10) --see email Questions about yesterdays lab? (C pointers and arrays, shift operators, masks) Please complete the survey (see email) Department coffee/tea today at 2 p.m. Sign up for
SLIDE 2
SLIDE 3
Arithmetic at the Machine Level
Subtraction:
■ Example: 7 - 6 = 7 + (-6)
Answer: … 0 0 0 0 1 = 1
1 1 1
SLIDE 4
Arithmetic at the Machine Level
Overflow if result out of range Example: 231-1 = 0x7FFFFFFF (largest positive) (231-1) + 1 = -231 = 0x8000000 (smallest negative) Similarly, subtracting one from -231 causes wraparound to largest positive.
Never any overflow when adding two values with opposite signs!
SLIDE 5
Arithmetic at the Machine Level
SLIDE 6
Arithmetic at the Machine Level
When overflow occurs, what do we do?
- Ignore it (C, Java)?
- Terminate program with an error?
- Set some kind of internal flag that can be
checked and handled? MIPS has add and addi (throw an exception), addu and addiu (ignore overflow). (See sample program in oct20 folder of shared repo.)
SLIDE 7
Addition and Subtraction--Efficiency
How long does it take to add two 32-bit numbers? Problem: “carry propagation”. Consider: 1 1 1 1 1 1 1 1 1 1 1 1 1 ...0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 + ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 ...0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
CARRY:
SLIDE 8
Addition and Subtraction--Efficiency
There are ways to avoid long chains of carry bits using hardware: “carry lookahead”. We may touch on it in chapter 4. Basic idea: examine more than just two bits at a time (requires additional circuitry).
SLIDE 9
What About Multiplication?
Basic idea: repeated adding and shifting. Example: 7x9 (...00111 x ...01001 in binary): ...01001 +...01001 +...01001 =...0111111
Repeat 32 times (assume positive):
...00111 +...00000 +...00000 +...00111 = ...0111111 OR
SLIDE 10
Definitions: 10001 x 01101 =11011101
MULTIPLICAND MULTIPLIER MULTIPLIER0 = RIGHTMOST BIT OF MULTIPLIER
See programs “mult3-4.c” and “mverbose.c” in the
- ct20 folder of the shared