@@ -792,7 +792,7 @@ module GBA_ControlUnit (
792792 control_signals.A_bus_imm = regs_count * 4 ;
793793
794794 // If its pre offset we add/subtract the offset to the base register before the memory access
795- if (decoder_bus.word.arm.block.P == ARM_LDR_STR_PRE_OFFSET ) begin
795+ if (decoder_bus.word.arm.block.P == ARM_LDR_STR_PRE_OFFSET ) begin // PRE-OFFSET
796796 if (decoder_bus.word.arm.block.W == 1'b1 ) begin
797797 // Updating the base register with the offset is enabled so we
798798 // latch operand b for the writeback in the next cycle
@@ -802,16 +802,16 @@ module GBA_ControlUnit (
802802 " [ControlUnit] Block load/store with pre-indexing and writeback, latching offset for writeback" );
803803 end
804804
805- if (decoder_bus.word.arm.block.U == 1'b1 ) begin
806- if (regs_count == 0 ) control_signals.A_bus_imm = 7'h40 ;
805+ if (decoder_bus.word.arm.block.U == 1'b1 ) begin // Increment Before (IB)
806+ if (regs_count == 0 ) control_signals.A_bus_imm = 7'd4 ;
807807 else control_signals.A_bus_imm = 7'd4 ;
808808
809809 control_signals.ALU_op = ALU_OP_ADD ;
810810
811811 $display (
812812 " [ControlUnit] Block load/store with pre-indexing and writeback, adding offset to base register R%0d before memory access" ,
813813 decoder_bus.decoded_regs.Rn);
814- end else begin
814+ end else begin // Decrement Before (DB)
815815 if (regs_count == 0 ) control_signals.A_bus_imm = 7'h40 ;
816816 else control_signals.A_bus_imm = 6 '(regs_count) * 4 ;
817817
@@ -833,7 +833,8 @@ module GBA_ControlUnit (
833833 // Decrement After (DA)
834834
835835 control_signals.A_bus_source = A_BUS_SRC_IMM ;
836- control_signals.A_bus_imm = (regs_count * 4 ) - 4 ;
836+ if (regs_count == 0 ) control_signals.A_bus_imm = 7'h3C ; // 0x40 - 4
837+ else control_signals.A_bus_imm = (regs_count * 4 ) - 4 ;
837838
838839 control_signals.ALU_op = ALU_OP_SUB_REVERSED ;
839840 end
@@ -967,7 +968,7 @@ module GBA_ControlUnit (
967968 end
968969
969970 if (cycle == 8'd2 && regs_count == 0 ) begin
970- control_signals.addr_bus_src = ADDR_SRC_PC ;
971+ control_signals.addr_bus_src = ADDR_SRC_ALU ;
971972
972973 control_signals.ALU_writeback = ALU_WB_REG_RP ;
973974 control_signals.Rp_imm = 4'd15 ;
@@ -1000,6 +1001,16 @@ module GBA_ControlUnit (
10001001 control_signals.ALU_use_op_b_latch = 1'b1 ;
10011002 control_signals.ALU_writeback = ALU_WB_REG_RN ;
10021003
1004+ control_signals.addr_bus_src = ADDR_SRC_PC_RESTORE ;
1005+
1006+ $display (
1007+ " [ControlUnit] Cycle 1 of STM instruction, address calculation done, preparing for memory write" );
1008+ end else
1009+
1010+ // Second cycle
1011+ if (cycle == 8'd2 && regs_count == 0 ) begin
1012+ control_signals | = fetch_next_instr ();
1013+
10031014 control_signals.addr_bus_src = ADDR_SRC_PC ;
10041015
10051016 control_signals.pipeline_advance = 1'b1 ;
0 commit comments