tuesday 20 october 2015
play

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


  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

  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

  3. Arithmetic at the Machine Level Subtraction: ■ Example: 7 - 6 = 7 + (-6) 1 1 1 0 0 0 Answer: … 0 0 0 0 1 = 1

  4. Arithmetic at the Machine Level Overflow if result out of range Example : 2 31 -1 = 0x7FFFFFFF (largest positive) (2 31 -1) + 1 = -2 31 = 0x8000000 (smallest negative) Similarly, subtracting one from -2 31 causes wraparound to largest positive. Never any overflow when adding two values with opposite signs!

  5. Arithmetic at the Machine Level

  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.)

  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 CARRY: ...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

  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).

  9. What About Multiplication? Basic idea: repeated adding and shifting. Example: 7x9 (...00111 x ...01001 in binary): ...00111 ...01001 +...00000 +...01001 OR +...00000 +...01001 +...00111 =...0111111 = ...0111111 Repeat 32 times (assume positive):

  10. Definitions: MULTIPLIER 10001 MULTIPLICAND x 01101 MULTIPLIER 0 = =11011101 RIGHTMOST BIT OF MULTIPLIER See programs “mult3-4.c” and “mverbose.c” in the oct20 folder of the shared repository.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend