Mum, I’m building a CPU – Performing Subtraction via Negation

This week, we published the latest episode in our video blog covering our journey constructing a CPU.  In this episode (embedded below), Charlie explains how we perform subtraction using our 8-bit full adder board.  If you just want to see the video, keep scrolling down, however if you’re looking for a quick simple explanation of some of the concepts (2’s complement and signed binary), take a look at this:

Let’s say we want to perform 7 – 5.  This is the same as 7 + (-5).  If we can represent the -5 in binary, we can simply put both through our added.  Luckily, we can because our CPU uses Signed Binary Values.

What does this mean?  Basically, we use the first (most significant bit) as an indicator as to whether the number is positive (msf = 0) or negative (msf = 1).

00000000 = 0
11111111 = -1
11111110 = -2

Let’s say we have a binary representation for positive number x.  To convert this to a negative number, we will flip every bit (1 <= 0, 0 <= 1), and then add one.  For example:

00000101 = 5
11111011 = -5

Initially, we performed this operation using not gates, however as Charlie explains in the video it’s much more efficient to use XOR’s!

Note, I did write a similar (and still relevant) post about this earlier, but the information in that is no longer completely correct, hence this post.

If you’re new to the series, you can catch up here!

Leave a Reply

Your email address will not be published. Required fields are marked *