SlideServe
Menu
Préférences
© SlideServe · v2026

Arithmetic

knox-santana avatar
15 diapositives · 269 Views · Nov 15, 2014

Arithmetic. CPSC 321 Computer Architecture Andreas Klappenecker. Signed Numbers (3bits). Two’s complement. The unsigned sum of an n-bit number with its negative yields? Example with 3 bits: 011 2 = 3 101 2 = -3 1000 2 = 2 n => negate(x) = 2 n -x 101 2 = -2 2 + 2 0.

Arithmetic - slide 1
01 / 15Arithmetic
1 / 17

Télécharger la présentation

Arithmetic
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Arithmetic CPSC 321 Computer Architecture Andreas Klappenecker

  2. Signed Numbers (3bits)

  3. Two’s complement • The unsigned sum of an n-bit number with its negative yields? • Example with 3 bits: • 0112 = 3 • 1012 = -3 • 10002 = 2n => negate(x) = 2n-x • 1012 = -22+ 20

  4. Negating Signed Integers • Suppose that you have an n-bit integer in two’s complement representation • Negate positive to negative: • 00112 = 3  11012 = -3 • invert bits and add 1 • Negate negative to positive • Trick: invert bits and add 1 • -3 = 11012 00102  00112

  5. Addition & Subtraction • Just like in grade school (carry/borrow 1s)0111 0111 0110+ 0110 - 0110 - 0101 1101 0001 0001 • Two's complement operations easy • subtraction using addition of negative numbers0111 = 7 + 1010 = -6 0001

  6. Detecting Overflow

  7. MIPS instructions • lb loads a byte and stores the sign-extended version in a word. • lbu loads a byte and stores it in a word • Which of these two is typically used to process characters?

  8. Logic Gates: AND AND a b c 0 0 0 0 1 0 1 0 0 1 1 1 a c b

  9. Logic Gates: OR OR a b c 0 0 0 0 1 1 1 0 1 1 1 1 a c b

  10. operation result An ALU (arithmetic logic unit) • Let's build an ALU to support the andi and ori instructions • Selection of operation 0 = and, 1 = or • we'll just build a 1 bit ALU, and use 32 of them • Possible Implementation (sum-of-products): a b

  11. S A C B The Multiplexor • Selects one of the inputs to be the output, based on a control input • Build (and/or) ALU using a MUX note: it is called a 2-input mux even though it has 3 inputs! 0 1

  12. Different Implementations • Not easy to decide the “best” way to build something • Don't want too many inputs to a single gate • for our purposes, ease of comprehension is important • Don’t want to have to go through too many gates • Let's look at a 1-bit ALU for addition: cout = a b + a cin + b cin sum = a xor b xor cin

  13. Different Implementations • How could we build a 1-bit ALU for add, and, and or? • How could we build a 32-bit ALU?

  14. Building a 32 bit ALU

  15. What about subtraction (a – b) ? • Two's complement approach: just negate b and add. • How do we negate? • A solution: