Verilog questions on 2's complement and left roate -
i trying write 16 bits alu verilog. inputs 16 bits ain,bin , 16 bits output out.
i required 2's complement addition , subtraction of both inputs. such wondering if can use '+' , '-' operator. ain+bin
, ain-bin
also, required left rotate of bits in value n. came out following replicate form 32 bits , shift left n bits. problem required reduce 16 bits again how can that?
out <=({a,a}<<n);
yes, can use +-
operators if want add or subtract 2 numbers.
if want truncate result 16 bits, assign result 16 bit wire/register, , automatically drop upper bits , assign lower 16 bits out
. in cases may create lint warning, may want assign result intermediate variable first, , explicit part select.
wire [15:0] out; wire [15:0] a; wire [31:0] a_rotate; a_rotate = {a,a} << n; out = a_rotate[15:0];
Comments
Post a Comment