diff options
author | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2024-05-01 16:08:53 +0200 |
---|---|---|
committer | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2024-05-01 16:08:53 +0200 |
commit | ca5a25cfbdbefada9dfb94a097b65e69226f3f9a (patch) | |
tree | cc9598ea41947b1e4cf008f430fc56e1c727d968 /src/arithmetic_unit.v | |
parent | 51b0a4c850fbf0ed70abe694be143b2b10e3e578 (diff) | |
download | riscv_cpu-ca5a25cfbdbefada9dfb94a097b65e69226f3f9a.tar.gz riscv_cpu-ca5a25cfbdbefada9dfb94a097b65e69226f3f9a.zip |
fixed alu bugs
Diffstat (limited to 'src/arithmetic_unit.v')
-rw-r--r-- | src/arithmetic_unit.v | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/arithmetic_unit.v b/src/arithmetic_unit.v index be087a7..64ec0f9 100644 --- a/src/arithmetic_unit.v +++ b/src/arithmetic_unit.v @@ -3,21 +3,20 @@ module arithmetic_unit #( )( input [N-1:0] A, B, input [1:0] OP, // 00: ADD, 01: SUB, 11: SLT - output [N-1:0] RESULT, - output OVERFLOW + output [N-1:0] RESULT ); wire [N-1:0] b, sum; -wire cin, altb; +wire cin, altb, overflow; assign b = OP[0] ? ~B : B; assign cin = OP[0]; assign sum = A + b + cin; -assign OVERFLOW = ~(A[N-1] ^ B[N-1] ^ OP[0]) & (A[N-1] ^ sum[N-1]); +assign overflow = ~(A[N-1] ^ B[N-1] ^ OP[0]) & (A[N-1] ^ sum[N-1]); -assign altb = OVERFLOW ^ sum[N-1]; +assign altb = overflow ^ sum[N-1]; assign RESULT = OP[1] ? {{(N-1){1'b0}}, altb} : sum; |