I am facing problem in my current task. I need to build a 2-port write and 2-port read register file with 4 registers. I am able to do the 2-port read part but I could not do the 2-port write part. How do I use two 2-4 decoders and two data lines to write 2 registers at the same time?

Thanks in advance.

  • 2
    \$\begingroup\$ Each register needs a 2:1 mux on its input to select data from one write port or the other. You'll also need to figure out how you want to handle the case of both write ports wanting to write to the same register at the same time. \$\endgroup\$ – Dave Tweed Nov 30 '16 at 22:04
  • \$\begingroup\$ Can you show me how to implement it? I tried many times, but I still couldn't get it done. \$\endgroup\$ – David Dec 3 '16 at 19:41

Can you show me how to implement it? I tried many times, but I still couldn't get it done.

OK, sure, why not? I've got nothing better to do for the next half hour.

Let's define the functionality. Each read port comprises an address input and a data output. Each write port comprises an address input, a data input and a "write strobe" input. We'll give write port A permanent priority over write port B for simplicity — if they both try to write to the same register, it will be A's data that prevails, and B's data will be discarded.


simulate this circuit – Schematic created using CircuitLab

I've shown the data paths as just one bit wide, but the design is the same for wider buses; the input and output muxes as well as the registers just need to be wider.

| improve this answer | |
  • \$\begingroup\$ What happens when someone is writing to a register and reading to a register at the same time? Is that allowed electrically? \$\endgroup\$ – drudru Jun 26 '19 at 23:01
  • \$\begingroup\$ @drudru: Sure. The inputs and outputs of each register are separate ports. Obviously, you need to pay attention as to exactly when the write causes the data to change, and where this falls in the read cycle -- you might get either the "old" data or the "new" data. \$\endgroup\$ – Dave Tweed Jun 26 '19 at 23:10
  • \$\begingroup\$ Yeah, I wish there was a definitive discussion of this aspect on wikipedia. There seem to be varied solutions in practice. Thanks Dave. \$\endgroup\$ – drudru Jun 28 '19 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.