Binary Logic

Cogman

Lifer
Sep 19, 2000
10,286
147
106
OK, so for our assignment we are making a VERY simple 8 bit cpu, the functions avalible to the cpu are as follows

No Operation
Move # to Reg0
Move # to Reg1
Move Register to Display
Move Accum to Reg0
Move Accum to Reg1
ADD Reg0, Reg1
AND Reg0, Reg1
OR Reg0, Reg1
XOR Reg0, Reg1

Where the Accum is the accumulation of the ALU (simple D-flip-flop looped through a mux). ANYWAYS... Part of the assignment is first to subtract 2 numbers without adding anything to the ALU and then to subtract them using some new circuitry. I know that I will always have 4 bits and If I wanted to cop out, I could just do some mathematical thing to make the output correct. But I want to really write the program the will do subtraction with the available functions.

Any suggestions? (BTW I don't have Inversion in the original circuit which makes it all the harder)
 

BrownTown

Diamond Member
Dec 1, 2005
5,314
1
0
wait, you have an addition operation (ADD)? IF so its entirely trivial. If you are trying to subtract S= A - B then what you do is S= A + NOT(B) + 1. You can do the NOT operation by doing XOR (B,1111).
 

Born2bwire

Diamond Member
Oct 28, 2005
9,840
6
71
Originally posted by: BrownTown
wait, you have an addition operation (ADD)? IF so its entirely trivial. If you are trying to subtract S= A - B then what you do is S= A + NOT(B) + 1. You can do the NOT operation by doing XOR (B,1111).

Oh sure, just give him the answer. I mean if you're going to do that, might as well make it a wrong one.
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
Im an Idiot in this post, Brown Towns answer is correct (if I would have taken the time to read it :)) Thanks again.
 

Born2bwire

Diamond Member
Oct 28, 2005
9,840
6
71
You don't need an inverter to do inversion, you already have the necessary logic operations.
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
OOOOOHHHH, Thank you so much Brown town, I skimmed over your post too fast. Makes perfect logic. Thanks a bunch everyone!
 

ColdFusion718

Diamond Member
Mar 4, 2000
3,496
9
81
Originally posted by: Cogman
OK, so for our assignment we are making a VERY simple 8 bit cpu, the functions avalible to the cpu are as follows

No Operation
Move # to Reg0
Move # to Reg1
Move Register to Display
Move Accum to Reg0
Move Accum to Reg1
ADD Reg0, Reg1
AND Reg0, Reg1
OR Reg0, Reg1
XOR Reg0, Reg1

Where the Accum is the accumulation of the ALU (simple D-flip-flop looped through a mux). ANYWAYS... Part of the assignment is first to subtract 2 numbers without adding anything to the ALU and then to subtract them using some new circuitry. I know that I will always have 4 bits and If I wanted to cop out, I could just do some mathematical thing to make the output correct. But I want to really write the program the will do subtraction with the available functions.

Any suggestions? (BTW I don't have Inversion in the original circuit which makes it all the harder)

Which types of gates are you allowed to use? If they give you NAND gates, just tie both inputs together to get a NOT gate (aka inverter).
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
Its not so much the gates we are allowed to use, but the instruction set given. Browntown's solution is perfect and gets the job done right. I don't know how I could change my current setup to use nand gates (Possible im sure, but a little too much work if you ask me)