`ifndef SIGN_EXTENDER_H `define SIGN_EXTENDER_H module sign_extender #(in_width=4, out_width=5)( input logic [0:0] op, input logic [2**in_width-1:0] val, output logic [2**out_width-1:0] ext_val ); logic [0:0] msb; assign msb = (val >> (in_width-1)) & 1'b1; always_comb begin if (op) begin ext_val = { {(2**out_width-2**in_width){msb}}, val}; end if (~op) begin ext_val = ({{(2**out_width-2**in_width){1'b0}}, val}); end end endmodule `endif