@@ -63,18 +63,28 @@ class Main() extends Module {
6363 val decoder = Module (new Decoder ())
6464 decoder.io.instruction := memory.readPorts(0 ).data;
6565
66- memory.readPorts(0 ).enable := io.execute;
66+ val loading_instruction_stage = RegInit (true .B );
67+
68+ memory.readPorts(0 ).enable := io.execute && loading_instruction_stage;
6769 memory.readPorts(0 ).address := program_pointer;
6870
6971 memory.writePorts(0 ).enable := io.debug_write;
7072 memory.writePorts(0 ).address := io.debug_write_address;
7173 memory.writePorts(0 ).data := io.debug_write_data;
7274
73- val operation = decoder.io.operation
75+ when(io.execute) {
76+ printf(" \n " )
77+ printf(" Operation: %b\n " , decoder.io.operation)
78+ printf(" Program Pointer: %d\n " , program_pointer)
79+ printf(" Loading Instruction Stage: %d\n " , loading_instruction_stage)
80+ printf(" Data: %b\n " , memory.readPorts(0 ).data)
7481
75- printf(" Operation: %b\n " , operation)
82+ when(loading_instruction_stage) {
83+ loading_instruction_stage := false .B ;
84+ }.otherwise {
85+ loading_instruction_stage := true .B ;
7686
77- switch(operation) {
87+ switch(decoder.io. operation) {
7888 // U-type instructions
7989 is(" b01101_11" .U (7 .W )) { // LUI opcode
8090 // LUI instruction https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#lui
@@ -88,10 +98,14 @@ class Main() extends Module {
8898 // Pad 20 bit immediate with 12 zeros to the right
8999 val sext_imm = Cat (immediate, Fill (12 , 0 .U ))
90100
101+ printf(" Register: %d Immediate: %b\n " , rd, sext_imm)
102+
91103 // Write to register file
92104 regFile.io.write_addr := rd
93105 regFile.io.write_enable := true .B
94106 regFile.io.in := sext_imm
107+
108+ program_pointer := program_pointer + 1 .U ;
95109 }
96110 is(" b00101_11" .U ) {
97111 // AUIPC instruction https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#auipc
@@ -514,6 +528,10 @@ class Main() extends Module {
514528 regFile.io.in := Cat (0 .U (31 .W ), alu_result) // Zero extend to 32 bits
515529 }
516530 }
531+
532+
533+ }
534+ }
517535}
518536
519537object Main extends App {
0 commit comments