-3

I need to do a circuit in which I subtract 2 numbers. I believe I need to use the SUM and a sign bit, and some masks, but I cannot figure out how to put it together.

[LATER EDIT]

i tried to do "15-3".

15 in binary is 1111 3 in binary is 0011

I have added a bit for the sign 0 for + and 1 for -

So now i have: 0 1111 + 1 0011 = 100010 and to this I make a XOR with the sign mask 1 0000. This is where I get stuck.

[Even later edit]

I think I found another way to look at the problem. I'll be using 2 shift registers to load the 2 numbers. The output of each shift register will be the input of a NOR gate performing a NOR with 0. (This is to transform 0101 into 1010) Then the 2 outputs of these gates will be connected to the input of the SUM. My question is how can I transform back from 1 bit to a 8 bit data before entering the SUM ?

user2252231
  • 1
  • 1
  • 2
  • you should add more details to what you have tried – Alp Apr 06 '13 at 13:22
  • 1
    You tagged this verilog, so what's wrong with `assign result = 15 - 3`? Or are you trying to build this by hand at the gate level? – Tim Apr 06 '13 at 20:39
  • I have this assignment, and I have to do all these steps: draw sequential circuit, draw logic diagram and then the verilog simulation. – user2252231 Apr 06 '13 at 23:02

2 Answers2

2

If you learn about Two's Complement as a way of inverting (negating) a number, the problem will become much simpler.

There are a few ways to represent negative numbers.

1) Sign Magnitude (Add sign bit)

0 0011 =>  3
1 0011 => -3

2) Ones Complement (bitwise invert)

0011 =>  3
1100 => -3

3) Two's Complement (one's complement + 1)

0011             =>  3
1100 + 1 => 1101 => -3

Two's Complement adds an efficiency as it removes duplicate 0 codes (0000=>0 and 1111=>-0) that One's complement has.

Two's Complement also has the property that the numbers can be added together as normal.
For 15 - 3 actually perform 15 + (-3).

To find out how to add binary number take a quick look at ripple adders.

First create a Half adder, adding 2 bits generating a sum and a carry. Use your half adders + XOR gate to build a full adder, A+B+Carry in, generating SUM and Carry Out (all 1 bit). You can then chain these together making an X width full adder.

Morgan
  • 19,934
  • 8
  • 58
  • 84
0

The half adder is an example of a simple, functional digital circuit built from two logic gates. The half adder adds to one-bit binary numbers (AB). The output is the sum of the two bits (S) and the carry (C). Note how the same two inputs are directed to two different gates. enter image description here