Hi,
For the benefit of students (and in this case I now have to include myself as one too) I am simulating the use of binary addition to carry out a subtraction using 2's complement. I have no issue with applying 2's complement to the subtrahend, and adding it to the minuend. For example 32 = 1, where I first take the 2's complement of 2 and then add it to 3). It is my understanding (and my Logisim model plays true to this) that I then apply 2's complement to the output of this addition to produce the final answer, if no carry occurs. If a carry does occur, just drop it and ignore the final step of applying 2's complement, as you already have the answer.
All this sounds simple enough, and it works in every instance, EXCEPT where I subtract zero! If I attempt to subtract zero, the hard logic says I should apply 2's complement, when clearly I should not. I have also attempted to resolve this by monitoring for overflow (which is subtly different to a carry over) but again the logic does not stack up. I have looked everywhere online and can find no solution for how the discrete logic should look to determine whether or not to apply that final 2's complement. I understand I could apply an array of logic gates (OR gates for example) to determine whether or not the subtrahend = 0, however that seems over the top. Funnily enough nobody speaks of this complete anomaly online, that subtracting zero essentially subverts the process of applying 2's complement for the final answer.
Here are some images (sorry they are a bit small to encompass the entire project for the sake of clarity) to demonstrate. Note the carry flag LED is set appropriately for all options, except where I subtract zero, in which case (if I applied the glue logic here) it would insist on applying 2s complement which is wrong!
Correct! 32 = 1
Correct! 33 = 0
Correct! 34 = 1 (applying 2s compliment as per carry bit)
Incorrect! 30 = 13 (applying 2s compliment as per carry bit)
NOTE: I am well aware the implementation of this (2's complement subtraction using addtion) logic could be done in a smarter and more integrated manner, however for teaching purposes I am attempting to use glue logic here in as discrete a fashion as possible to better convey the underlying principles.
For the benefit of students (and in this case I now have to include myself as one too) I am simulating the use of binary addition to carry out a subtraction using 2's complement. I have no issue with applying 2's complement to the subtrahend, and adding it to the minuend. For example 32 = 1, where I first take the 2's complement of 2 and then add it to 3). It is my understanding (and my Logisim model plays true to this) that I then apply 2's complement to the output of this addition to produce the final answer, if no carry occurs. If a carry does occur, just drop it and ignore the final step of applying 2's complement, as you already have the answer.
All this sounds simple enough, and it works in every instance, EXCEPT where I subtract zero! If I attempt to subtract zero, the hard logic says I should apply 2's complement, when clearly I should not. I have also attempted to resolve this by monitoring for overflow (which is subtly different to a carry over) but again the logic does not stack up. I have looked everywhere online and can find no solution for how the discrete logic should look to determine whether or not to apply that final 2's complement. I understand I could apply an array of logic gates (OR gates for example) to determine whether or not the subtrahend = 0, however that seems over the top. Funnily enough nobody speaks of this complete anomaly online, that subtracting zero essentially subverts the process of applying 2's complement for the final answer.
Here are some images (sorry they are a bit small to encompass the entire project for the sake of clarity) to demonstrate. Note the carry flag LED is set appropriately for all options, except where I subtract zero, in which case (if I applied the glue logic here) it would insist on applying 2s complement which is wrong!
Correct! 32 = 1
Correct! 33 = 0
Correct! 34 = 1 (applying 2s compliment as per carry bit)
Incorrect! 30 = 13 (applying 2s compliment as per carry bit)
NOTE: I am well aware the implementation of this (2's complement subtraction using addtion) logic could be done in a smarter and more integrated manner, however for teaching purposes I am attempting to use glue logic here in as discrete a fashion as possible to better convey the underlying principles.
Attachments

3.6 KB Views: 13