fix flags

This commit is contained in:
Nicholas Orlowsky 2024-04-10 22:22:25 -05:00
parent 26f6dc5ce3
commit c1adfc84c0
Signed by: nickorlow
GPG key ID: 838827D8C4611687
2 changed files with 13 additions and 6 deletions

7
alu.sv
View file

@ -14,7 +14,7 @@ module alu(
int cnt; int cnt;
initial begin initial begin
overflow = 1'bx; overflow = 0;
result = 8'hxx; result = 8'hxx;
result_int = 9'bxxxxxxxxx; result_int = 9'bxxxxxxxxx;
done = 0; done = 0;
@ -24,7 +24,7 @@ module alu(
always_ff @(posedge clk_in) begin always_ff @(posedge clk_in) begin
if (rst_in) begin if (rst_in) begin
done <= 0; done <= 0;
overflow <= 1'bx; overflow <= 0;
result <= 8'hxx; result <= 8'hxx;
result_int <= 9'bxxxxxxxxx; result_int <= 9'bxxxxxxxxx;
cnt <= 0; cnt <= 0;
@ -65,14 +65,17 @@ module alu(
end end
structs::OR: begin structs::OR: begin
result <= in.operand_a | in.operand_b; result <= in.operand_a | in.operand_b;
overflow <= 0;
done <= 1; done <= 1;
end end
structs::AND: begin structs::AND: begin
result <= in.operand_a & in.operand_b; result <= in.operand_a & in.operand_b;
overflow <= 0;
done <= 1; done <= 1;
end end
structs::XOR: begin structs::XOR: begin
result <= in.operand_a ^ in.operand_b; result <= in.operand_a ^ in.operand_b;
overflow <= 0;
done <= 1; done <= 1;
end end
structs::SHR: begin structs::SHR: begin

12
cpu.sv
View file

@ -264,7 +264,7 @@ logic [5:0] lcd_led;
instr.alu_i.op <= structs::OR; instr.alu_i.op <= structs::OR;
instr.alu_i.operand_a <= registers[opcode[7:4]]; instr.alu_i.operand_a <= registers[opcode[7:4]];
instr.alu_i.operand_b <= registers[opcode[11:8]]; instr.alu_i.operand_b <= registers[opcode[11:8]];
compute_of <= 0; compute_of <= 1;
state <= ST_EXEC; state <= ST_EXEC;
end end
@ -279,7 +279,7 @@ logic [5:0] lcd_led;
instr.alu_i.op <= structs::AND; instr.alu_i.op <= structs::AND;
instr.alu_i.operand_a <= registers[opcode[7:4]]; instr.alu_i.operand_a <= registers[opcode[7:4]];
instr.alu_i.operand_b <= registers[opcode[11:8]]; instr.alu_i.operand_b <= registers[opcode[11:8]];
compute_of <= 0; compute_of <= 1;
state <= ST_EXEC; state <= ST_EXEC;
end end
@ -294,7 +294,7 @@ logic [5:0] lcd_led;
instr.alu_i.op <= structs::XOR; instr.alu_i.op <= structs::XOR;
instr.alu_i.operand_a <= registers[opcode[7:4]]; instr.alu_i.operand_a <= registers[opcode[7:4]];
instr.alu_i.operand_b <= registers[opcode[11:8]]; instr.alu_i.operand_b <= registers[opcode[11:8]];
compute_of <= 0; compute_of <= 1;
state <= ST_EXEC; state <= ST_EXEC;
end end
@ -620,8 +620,12 @@ logic [5:0] lcd_led;
instr.src <= BYTE; instr.src <= BYTE;
if (instr.dst == IDX_REG) if (instr.dst == IDX_REG)
instr.src_byte <= alu_result_long[11:0]; instr.src_byte <= alu_result_long[11:0];
else else if (instr.dst_reg != 15 || !compute_of) begin
instr.src_byte <= alu_result; instr.src_byte <= alu_result;
end else begin
instr.src_byte <= alu_overflow;
end
registers[15] <= compute_of ? alu_overflow : registers[15]; registers[15] <= compute_of ? alu_overflow : registers[15];
if (instr.op == ALU) begin if (instr.op == ALU) begin
state <= ST_WB; state <= ST_WB;