3.1.3 Combinational Logic - Arithmetic Circuits

Kiwoong Nam·2025년 6월 6일

HDLBits

목록 보기
7/11

Signed addition overflow

Exams/ece241 2014 q1c

module top_module (
    input [7:0] a,
    input [7:0] b,
    output [7:0] s,
    output overflow
); 
    wire [7:0] cin;
    wire [7:0] cout;
    fadd inst [7:0] (a, b, cin, cout, s);
    assign cin = {cout[6:0], 1'b0};
    assign overflow = cout[7]^cout[6];

endmodule

module fadd(input a,b,cin, output cout, sum);
    assign {cout, sum} = a+b+cin;
endmodule

A signed overflow occurs when adding two positive numbers produces a negative result, or adding two negative numbers produces a positive result. There are several methods to detect overflow: It could be computed by comparing the signs of the input and output numbers, or derived from the carry-out of bit n and n-1.

Signed overflow의 감지 방법으로 출력의 최상위 비트와 그 다음 비트가 같은지 비교하는 방법이 있다. 다르면 오버플로우가 발생한 것이다.
다른 방법으로는 입력과 출력의 부호를 비교할 수도 있다.

0개의 댓글