# Implementing ADD instruction for RiSC-16 processor

I'm trying to implement the RiSC-16 (not RISC) processor documented here using Verilog. The processor is really simple, however there is a problem when you try to perform ADD instructions consecutively on a register, for example

add r1,r1,r1


Looking at the sequential implementation here, this code won't work. Here is why: Since write enable of register file is on throughout the execution, the result of the first instruction gets overridden at the beginning of the second instruction. This is because the target address does not change immediately at the beginning of the next instruction cycle.

Is there a way to prevent this from happening?

• Does the register file write "constantly" when WE is asserted? Or does it only write on the clock signal? If it only writes on the clock signal, then you might not have a problem. – user253751 Feb 7 at 10:34
• @user253751 Register file writes on rising edge of clock when WE is asserted. So, it's both. – zeke Feb 7 at 14:14
• Then what is the problem? The target address doesn't change immediately, but it changes before the rising edge of the clock, so the register file writes the new address and not the old one. – user253751 Feb 7 at 15:27

RISC-16 is RISC. All RISC CPUs are RISC. Well, your example is one that would never happen in real machine. It is a nonsense. The problem may lie in the pipeline, the RISC tends to execute all instructions in the same amount of instruction cycles, composed by fetch, decode, execute. The pipeline was introduced to speed up the processor: first problem is that all instructions shall have the same the same instruction cycles in order to take the advantage of the pipeline, next it is strictly forbidden to execute a commands that will access and change the value of the same register within one instruction cycle, as the pipeline would messs up.

The only way to reproduce your behaviour, is to intentionally write those assembler codes, as no compiler would do that. If you do program on low level, you should be aware of pipeline and its restrictions.

• RiSC stands for "Ridiculously Simple Computer", so it's not exactly RISC. Also, there is no pipeline in this processor. I suggest you to take a look at the documentations I linked in the original post. – zeke Feb 4 at 22:46
• @zeke No, RISC stands for Reduced Instruction Set Computer. Anyone who tries to change that definition arbitrarily will cause the kind of confusion that you are now suffering. – Elliot Alderson Feb 4 at 23:12
• @ElliotAlderson It literally says that in the documentation of the processor. I know what RISC is, this processor is just named RiSC. – zeke Feb 4 at 23:15
• @zeke How many those processors actually exist? You do really think you'll get an answer for a specific CPU that nobody has and will never have? – Marko Buršič Feb 5 at 12:13

'm trying to implement...

You do not say HOW your are trying to implement the processor. Is this in software or hardware?

In case of the latter, what your are describing is a know issue.
It does not only happens in the case of

add r1,r1,r1


But also if you do:

add r1,r2,r3