How to sign-extend a number in Verilog

前端 未结 3 590
礼貌的吻别
礼貌的吻别 2021-02-08 00:51

I\'m working on a simple sign-extender in Verilog for a processor I\'m creating for Computer Architecture.

Here\'s what I\'ve got so far: [EDIT: Changed the selection st

3条回答
  •  一向
    一向 (楼主)
    2021-02-08 01:35

    We can use the syntax $signed to sign extend

    module signextender(
      input [7:0] unextended,//the msb bit is the sign bit
      input clk,
      output reg [15:0] extended 
    );
    
    always@(posedge clk)
      begin 
        extended <= $signed(unextended);
      end
    endmodule
    

提交回复
热议问题