[RTLLM-p006] Arithmetic/Substractor/sub_64bit 的題解
記住 只 在沒有思路時使用題解,不要從它複製貼上程式碼。請尊重題目和題解的作者。
在真正解決題目之前提交題解的程式碼是可以封禁的罪行。
在真正解決題目之前提交題解的程式碼是可以封禁的罪行。
作者:
module sub_64bit(
input [63:0] A,
input [63:0] B,
output reg [63:0] result,
output reg overflow
);
always @(*) begin
result = A - B;
// Overflow happens when the sign of A and B are different, but the sign of result matches B
if ((A[63] != B[63]) && (result[63] != A[63])) begin
overflow = 1;
end else begin
overflow = 0;
end
end
endmodule
評論