diff --git a/alu.sv b/alu.sv index 44881e8..e8ceece 100644 --- a/alu.sv +++ b/alu.sv @@ -14,7 +14,7 @@ module alu( int cnt; initial begin - overflow = 1'bx; + overflow = 0; result = 8'hxx; result_int = 9'bxxxxxxxxx; done = 0; @@ -24,7 +24,7 @@ module alu( always_ff @(posedge clk_in) begin if (rst_in) begin done <= 0; - overflow <= 1'bx; + overflow <= 0; result <= 8'hxx; result_int <= 9'bxxxxxxxxx; cnt <= 0; @@ -65,14 +65,17 @@ module alu( end structs::OR: begin result <= in.operand_a | in.operand_b; + overflow <= 0; done <= 1; end structs::AND: begin result <= in.operand_a & in.operand_b; + overflow <= 0; done <= 1; end structs::XOR: begin result <= in.operand_a ^ in.operand_b; + overflow <= 0; done <= 1; end structs::SHR: begin diff --git a/cpu.sv b/cpu.sv index e685718..aa01b86 100644 --- a/cpu.sv +++ b/cpu.sv @@ -264,7 +264,7 @@ logic [5:0] lcd_led; instr.alu_i.op <= structs::OR; instr.alu_i.operand_a <= registers[opcode[7:4]]; instr.alu_i.operand_b <= registers[opcode[11:8]]; - compute_of <= 0; + compute_of <= 1; state <= ST_EXEC; end @@ -279,7 +279,7 @@ logic [5:0] lcd_led; instr.alu_i.op <= structs::AND; instr.alu_i.operand_a <= registers[opcode[7:4]]; instr.alu_i.operand_b <= registers[opcode[11:8]]; - compute_of <= 0; + compute_of <= 1; state <= ST_EXEC; end @@ -294,7 +294,7 @@ logic [5:0] lcd_led; instr.alu_i.op <= structs::XOR; instr.alu_i.operand_a <= registers[opcode[7:4]]; instr.alu_i.operand_b <= registers[opcode[11:8]]; - compute_of <= 0; + compute_of <= 1; state <= ST_EXEC; end @@ -620,8 +620,12 @@ logic [5:0] lcd_led; instr.src <= BYTE; if (instr.dst == IDX_REG) instr.src_byte <= alu_result_long[11:0]; - else + else if (instr.dst_reg != 15 || !compute_of) begin instr.src_byte <= alu_result; + end else begin + instr.src_byte <= alu_overflow; + end + registers[15] <= compute_of ? alu_overflow : registers[15]; if (instr.op == ALU) begin state <= ST_WB;