Tuesday, 20 October 2015 Check your exams! (problem 10) --see email - - PowerPoint PPT Presentation

tuesday 20 october 2015
SMART_READER_LITE
LIVE PREVIEW

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-1
SLIDE 1

Tuesday, 20 October 2015

Check your exams! (problem 10)--see email Questions about yesterday’s 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 Gator Day lunch (next Tuesday) Today: Begin chapter 3 in P&H

slide-2
SLIDE 2

Arithmetic at the Machine Level

We’ve already talked about addition and subtraction:

■ Example: 7 + 6

Answer: … 0 0 1 1 0 1 = 13

slide-3
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
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
SLIDE 5

Arithmetic at the Machine Level

slide-6
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
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
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
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
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

repository.