BrunoLevy / learn-fpga

Learning FPGA, yosys, nextpnr, and RISC-V
BSD 3-Clause "New" or "Revised" License
2.58k stars 245 forks source link

FROM_BLINKER_TO_RISCV step 14 multiply simulates but doesn't run on IceStick #84

Open dbenn opened 1 year ago

dbenn commented 1 year ago

I'm enjoying your FemtoRV/TUTORIALS/FROM_BLINKER_TO_RISCV tutorial!

I came up with a few multiplication subroutine variants. This one, for example, simulates fine with run.sh but does not yield the expected LED outputs on the IceStick. I have had no problems with previous exercises and examples.

`include "riscv_assembly.v"
   integer START_    = 0;
   integer MUL_      = 20;
   integer MUL_LOOP_ = 28;
   integer MUL_DONE_ = 44;

   initial begin
   Label(START_);
      // 3 x 4 = 12 = 0b1100
      LI(a0,3);
      LI(a1,4);
      CALL(LabelRef(MUL_));

      EBREAK();

   // multiply function
   Label(MUL_);
      LI(a2,0); // result
      LI(a3,0); // 1..a1
   Label(MUL_LOOP_);
      BEQ(a3,a1,LabelRef(MUL_DONE_));
      ADD(a2,a2,a0); // result += a0
      ADDI(a3,a3,1);
      J(LabelRef(MUL_LOOP_));
   Label(MUL_DONE_);
      MV(a0,a2);
      RET();

      endASM();
   end

The output of:

./run.sh step14_mul_func.v 

is:

Label:          0
Label:         20
Label:         28
Label:         44
LEDS = 01100

which is the expected result.

However, running this on the IceStick does not yield the expected LED pattern. Actually, no LEDs are lit at all.

I can provide the complete step14_mul_func.v if necessary, but it's literally just the assembly code section that has changed from step14.v, changed to the listing above.