Making the Logic gates in C++ (stuck on Demultiplexer)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Making the Logic gates in C++ (stuck on Demultiplexer)

burge91
I decided to do this with as few language constructs as possible and relying on recursive calls to emulate gates being built from other gates.

However, I've encountered a problem now that I've reached the dmux, it seems the gate returns multiple outputs. I can use pointers here as arguments, but it differs so much from the logic of the other gates that I'm somewhat stuck about what to do.

I know I shouldn't be doing it in C++, I should be drawing it or something, but it's more fun for me to be able to see some kind of output to make up for the fact that I'm progressing through the book so slowly.
Reply | Threaded
Open this post in threaded view
|

Re: Making the Logic gates in C++ (stuck on Demultiplexer)

burge91
So it turns out I need two boolean functions to get two outputs from two inputs. I think this was the biggest stumbling block. I guess I'll just return an array (or pointer to an array) and write in the code somewhere the convention for access.

https://math.stackexchange.com/questions/2203490/2-output-truth-table
Reply | Threaded
Open this post in threaded view
|

Re: Making the Logic gates in C++ (stuck on Demultiplexer)

cadet1620
Administrator
In reply to this post by burge91
burge91 wrote
I know I shouldn't be doing it in C++, I should be drawing it or something, but it's more fun for me to be able to see some kind of output to make up for the fact that I'm progressing through the book so slowly.
I assume that after you have the parts written in C++ that you are also writing them in HDL and testing them in the HardwareSimulator.

You might also be interested in Logisim. It's a schematic-based logic simulator that can really help if you learn best by experimentation. Unfortunately it does not have any import/export features so you will still need to write HDL for the parts you make in Logisim.

You might want to look at Python. It has become my favorite language for writing simple programs like your logic simulations.  It does support returning multiple values. You can write things like
     a, b, c, d = DMux4Way(in, sel)

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Making the Logic gates in C++ (stuck on Demultiplexer)

burge91
Yes I got as far as I could in C++ and now I'm playing with the HDL and testing. I will go back to the C++ files hopefully and develop them further as I go through the book.