Computers usually implement subtraction by negating the subtrahend (making it negative) and adding it to the minuend. Instead of. A – B T do A + (-B) This eliminates the need for a separate logic circuit for subtraction, you just need to apply a simple conversion before adding. The result you’re seeing isn’t wrong per se, so your subtraction logic is working correctly. Then again, it isn’t right either. Let’s see why. A 4-bit register can contain 16 (2^4) distinct values. For unsigned numbers, then, the range is 0–15. Subtracting a larger number from a smaller one in this case will always produce a wrap-around in the number line. 2-3 = 15; 2-4 = 14; etc. This is known as modular math and can be easily seen by drawing a clock face with the numbers 0–15. In order to represent negative values, we have assign half the range to them, which then becomes -8 to +7. Now when we subtract, say, 7 from 2 we get -5. In binary these “signed” values are the exact same ones on the unsigned number line, we just consider them to be negative when the highest order bit (2^3) is 1. So -1 = 1111; -2 = 1110; -3 = 1101, etc. These are known as the twos-complement of the positive values. The twos-complement is found by inverting all the bits and adding one. The beauty of this way of representing negative numbers is that the math is exactly the same as for unsigned numbers. Now let’s examine your results. First, we need to ignore that 5th bit, since there’s no room for it in a 4-bit register; the result was actually 0101 (+5). The minuend is 0011 (3) and the subtrahend is 1110 (14). But the largest positive signed number you can put in a 4-bit register is 7 — 1110 is actually -2. Hence, 3 – (-2) = 5.
Now remember that 4 bits to the right means 4 bits are left at the bottom (22). So the subtracted 3-bit result is 23, and it is a wrap-around, not a negation. So your result is -8 — (-8) = 5. In fact, it's negative because the bit at the bottom is 1. The reason for the negative result is that a number will wrap-around the line if the numbers on the right are both negative and the numbers on the left. Since you’re subtracting a negative number from a negation, the negatives go to the bottom, and the ones go to the top. Let's see what you’re saying. You used negative numbers to make sure that the subtraction worked correctly. But then you subtracted a negative number. Why’s that’s bad? If we use numbers that make the addition work correctly—such as positive ones—we just need to represent negative.