{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

This preview shows pages 1–10. Sign up to view the full content.

Lecture 5 Addition, Subtraction, Logic Operations and ALU Design Computer Architecture CSC 205

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

View Full Document
Unsigned Binary Integers Unsigned binary numbers are typically used to represent computer addresses or other values that are guaranteed not to be negative. An n-bit unsigned binary integer A = a n-1 a n-2 ... a 1 a 0 has a value of What is 1011 as an unsigned integer? An n-bit unsigned binary integer has a range from 0 to 2 n - 1. What is the value of of the 8-bit unsigned integer 10000001? i i n i a 2 1 0 - =
Signed Binary Integers Signed binary numbers are typically used to represent data that is either positive or negative. The most common representation for signed binary integers is the two's complement format. An n-bit 2’s comp binary integer A = a n-1 a n-2 ... a 1 a 0 has a value of What is 1011 as a 2’s comp. integer? An n-bit 2’s comp. binary integer has a range from - 2 n-1 to 2 n-1 - 1. What is the value of the 2’s comp. Integer 10000001? i i n i n n a a 2 2 2 0 1 1 + - = - - -

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

View Full Document
2’s Comp. Negatation To negate a two's complement integer, invert all the bits and add a one to the least significant bit. What are the two’s complements of 6 = 0110 -4 = 1100 Another way to negate is: Copy all bits to the right of the right-most ‘1’ Copy the right-most ‘1’ Invert all bits to the right-most ‘1’ Which way do you think is more commonly used by hardware? Why?
Questions What is the value of the two's complement integer 1111111111111101 in decimal? What is the value of the unsigned integer 1111111111111101 in decimal? What is the negation of the two's complement integer 1010000000000000 in binary?

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

View Full Document
Two’s Comp. Addition To add two's complement numbers, add the corresponding bits of both numbers with carry between bits. For example, 3 = 0011 -3 = 1101 -3 = 1101 3 = 0011 + 2 = 0010 +-2 = 1110 + 2 = 0010 + -2 = 1110 -------- --------- --------- --------- Unsigned and two’s complement addition are performed exactly the same way, but how they detect overflow differs.
Two’s Comp. Subtraction To subtract two's complement numbers we first negate the second number and then add the corresponding bits of both numbers. For example: 3 = 0011 -3 = 1101 -3 = 1101 3 = 0011 - 2 = 0010 - -2 = 1110 - 2 = 0010 - -2 = 1110 ---------- --------- --------- ---------

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

View Full Document
Overflow When adding or subtracting numbers, the sum or difference can go beyond the range of representable numbers. This is known as overflow. For example, for two's complement numbers, 5 = 0101 -5 = 1011 5 = 0101 -5 = 1011 + 6 = 0110 + -6 = 1010 - -6 = 1010 - +6 = 0110 -------- --------- --------- --------- -5 = 1011 5 = 0101 -5 = 1011 5 = 0101 Overflow creates an incorrect result that should be detected.
2’s Comp - Detecting Overflow When adding two's complement numbers, overflow will only occur if the numbers being added have the same sign the sign of the result is different If we perform the addition a n-1 a n-2 ... a 1 a 0 + b n-1 b n-2 … b 1 b 0 ---------------------------------- = s n-1 s n-2 … s 1 s 0 Overflow can be detected as Overflow can also be detected as where c n-1 and c n

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}