From 4c7e2ff085423ce3f36914fe76ce233a49db9d7e Mon Sep 17 00:00:00 2001 From: Riley King-Saunders Date: Fri, 16 Oct 2026 11:29:04 +1100 Subject: [PATCH] Fixed instruction width issue in ROM. Stripped all comments to form minimal HEX file to rule out possible parser issues. --- asm/bin/ELEC4720-2026s2-Ass-02-Demo.hex | 18 ++++++++++++++++++ modules/rom.sv | 10 +++++----- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 asm/bin/ELEC4720-2026s2-Ass-02-Demo.hex diff --git a/asm/bin/ELEC4720-2026s2-Ass-02-Demo.hex b/asm/bin/ELEC4720-2026s2-Ass-02-Demo.hex new file mode 100644 index 0000000..25006fa --- /dev/null +++ b/asm/bin/ELEC4720-2026s2-Ass-02-Demo.hex @@ -0,0 +1,18 @@ +01084023 +25090007 +ad090000 +8d0a0000 +012a5821 +012b6022 +212d0003 +018d7020 +012d8024 +012d8825 +012d9026 +012d9827 +018ea02a +018ea82b +25080001 +010db02b +12d4fffd +12d6ffff \ No newline at end of file diff --git a/modules/rom.sv b/modules/rom.sv index e18e3c7..9f9a666 100644 --- a/modules/rom.sv +++ b/modules/rom.sv @@ -3,19 +3,19 @@ module rom #(parameter m=7,p=4) ( input logic [m-1:0] Ad, - output logic [p-1:0] Dout + output logic [2**p-1:0] Dout ); - logic [p-1:0] mem[2**m-1:0]; - assign Dout = mem[Ad]; + logic [2**p-1:0] mem[2**m]; + assign Dout = mem[Ad>>2]; // Because word-size versus byte size hack //Load the program in memory // The machine code stored in text file program.dat written in Hex format initial begin `ifdef QUARTUS_SYNTH - $readmemh("../../asm/bin/ELEC4720-2026s2-Ass-02-Demo.txt",mem); //$readmemb for binary + $readmemh("../../asm/bin/ELEC4720-2026s2-Ass-02-Demo.hex", mem, 0, 2**m-1); //$readmemb for binary `else - $readmemh("./asm/bin/ELEC4720-2026s2-Ass-02-Demo.txt",mem); //$readmemb for binary + $readmemh("./asm/bin/ELEC4720-2026s2-Ass-02-Demo.hex", mem, 0, 2**m-1); //$readmemb for binary `endif end endmodule // end rom module