I'm trying to implement multiplication in a cpu I designed. I'm trying to achieve this with some conditions. I only two general purpose registers Rx and Ry and these instructions:
- Add Rx, Ry [Add take Rx and Ry to ALU and returns result to Rx]
- LD Rx, address [Load takes the data in RAM from address and loads to Rx]
- STR Rx, address [Store takes data from Rx and stores to address in RAM]
- BZ Rx, Ry, Address [Branch compares the data in two registers. Jumps if equal]
- Jump Address [Jumps to address]
If I only have 2 registers and RAM, is there a way to implement multiplication? I know the general way to implement it is by using shifts but I don't have the implemented and would prefer not to. I was thinking of looping an addition call but I can't seem to get that work since I only have 2 registers.
EDIT: You can select which register by addressing them either 0 or 1. Also, my RAM is only 16 bytes large and the bus is only 8 bits within the CPU.
- Add Rx, Ry [Rx <= Rx + Ry]
- LD Rx, address [Rx <= RAM(address)]
- STR Rx, address [RAM(address) <= Rx]
- BZ Rx, Ry, Address [Branch to Address If Rx == Ry ]
- Jump Address [Jumps to address]
The address is a 4-bit constant stored in the instruction. Rx or Ry are 1 bit. OPCODE is 4 bit with the exception of LD and STR where 4th bit of OPCode refers to register selection.