From a7e6070ffab93d3fc80345604464f28d9ebbf724 Mon Sep 17 00:00:00 2001 From: lshprung Date: Fri, 16 Oct 2020 10:28:33 -0700 Subject: Post-class 10/16 --- 10.md | 4 ++ 11.1.png | Bin 0 -> 17108 bytes 11.2.png | Bin 0 -> 12498 bytes 11.3.png | Bin 0 -> 37674 bytes 11.4.png | Bin 0 -> 7976 bytes 11.md | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 149 insertions(+) create mode 100644 11.1.png create mode 100644 11.2.png create mode 100644 11.3.png create mode 100644 11.4.png create mode 100644 11.md diff --git a/10.md b/10.md index c7bad48..3151605 100644 --- a/10.md +++ b/10.md @@ -181,3 +181,7 @@ - We are learning things in the context of underlying circuit implementations - We have learned how to build an adder, not a subtractor - When you need to show subtraction, you \*must\* negate and add + +--- + +[Overflow, Comparison, ALU ->](11.md) diff --git a/11.1.png b/11.1.png new file mode 100644 index 0000000..06e8298 Binary files /dev/null and b/11.1.png differ diff --git a/11.2.png b/11.2.png new file mode 100644 index 0000000..7cf0884 Binary files /dev/null and b/11.2.png differ diff --git a/11.3.png b/11.3.png new file mode 100644 index 0000000..2e9921b Binary files /dev/null and b/11.3.png differ diff --git a/11.4.png b/11.4.png new file mode 100644 index 0000000..5c63f28 Binary files /dev/null and b/11.4.png differ diff --git a/11.md b/11.md new file mode 100644 index 0000000..c6239a8 --- /dev/null +++ b/11.md @@ -0,0 +1,145 @@ +[\<- Signed numbers and subtraction](10.md) + +# Overflow, Comparison, ALU + +## Overflow + +- Remember, signed numbers, and hardware computation units, have a fixed number of bits +- What happens if the result of the addition/subtraction needs more than the available bits? +- Need to detect this condition. What happens next depends on the "system" in which the circuit is implemented + +### Determining Overflow + +- Adding two numbers with the same "sign" should not yield a result with the opposite sign + +![diagram](11.1.png) + +### HW detection of overflow + +- As humans, we can look at the sum of two numbers and see whether there's overflow +- A HW circuit, like a 4-bit adder, needs a way to "flag" whether the result is valid + - The carry-in to the sign bit position (C3) should match the carry-out (C4) +- Overflow = C3 ^ C4 (for a 4-bit adder) + - C7 ^ C8 for an 8-bit adder + - Remember: `^` is XOR +- Note: adding a negative and positive number can never overflow + +### 8-bit signed addition example + +- Computation of 0xDA + 0xAB + - Two negative 8-bit numbers + +![diagram](11.2.png) + +- No overflow: C7 == C8 + - Even though C3 != C4 +- It's the sign bit that we care about! + +--- + +## Comparison + +### Comparators + +- Often it's usefule to detect comparisons + - `==`, `>`, `<`, `!=`, `>=`, `<=` + - "Answer" is true/false, yes/no, 1/0 +- XOR gates provide an easy means to determine if two bits are equal (`==`) + - Apply to each bit position and OR the results + - A 1 means the bits don't match => inequality +- For unsigned `>` or `<`, start at the MSB (most significatn bit) and find the first mismatch + - Really only practical for small # of bits + +### Signed Comparison + +- Subtract the numbers (A-B) and check the result + - Three mutually exclusive possibilities + - A-B > 0 => A>B + - A-B = 0 => A=B + - A-B < 0 => A