Feb 7, 2006 #1 D davyzhu Advanced Member level 1 Joined May 23, 2004 Messages 494 Helped 5 Reputation 10 Reaction score 2 Trophy points 1,298 Location oriental Activity points 4,436 Hi all, I am new to Verilog and want to build a 2's Complement Shifter. I found %displayb(8'b0001_1000>>2); //Output 0000_0110 %displayb(8'b1001_1000>>2); //Output 0010_0110 So, ">>" is unsigned shift. How can I build a signed (2's Complement) shift based on >>? i.e. I want 8'b1001_1000>>2 //Output 1110_0110 Any suggestions will be appreciated! Best regards, Davy
Hi all, I am new to Verilog and want to build a 2's Complement Shifter. I found %displayb(8'b0001_1000>>2); //Output 0000_0110 %displayb(8'b1001_1000>>2); //Output 0010_0110 So, ">>" is unsigned shift. How can I build a signed (2's Complement) shift based on >>? i.e. I want 8'b1001_1000>>2 //Output 1110_0110 Any suggestions will be appreciated! Best regards, Davy
Feb 7, 2006 #2 N nand_gates Advanced Member level 3 Joined Jul 19, 2004 Messages 899 Helped 175 Reputation 350 Reaction score 53 Trophy points 1,308 Activity points 7,037 Its simple you have to write ur function to do that! Code: module test; function [7:0] arithmatic_shift; input [7:0] vec; input [2:0] shift; begin arithmatic_shift = (vec >> shift) | ({{8{vec[7]}},8'b0000_0000} >> shift); end endfunction // arithmatic_shift initial begin $display("%b",arithmatic_shift (8'b1001_0000, 2 )); end endmodule
Its simple you have to write ur function to do that! Code: module test; function [7:0] arithmatic_shift; input [7:0] vec; input [2:0] shift; begin arithmatic_shift = (vec >> shift) | ({{8{vec[7]}},8'b0000_0000} >> shift); end endfunction // arithmatic_shift initial begin $display("%b",arithmatic_shift (8'b1001_0000, 2 )); end endmodule
Feb 8, 2006 #3 C calm Full Member level 4 Joined Oct 17, 2005 Messages 216 Helped 9 Reputation 18 Reaction score 4 Trophy points 1,298 Activity points 2,156 the design of nand_gates is ok! i have already check it on dc.
Feb 8, 2006 #4 T tarkyss Full Member level 6 Joined Aug 1, 2005 Messages 340 Helped 26 Reputation 52 Reaction score 8 Trophy points 1,298 Location China Activity points 4,162 why not write as arithmatic_shift = {{8{vec[7]}},vec} >> shift;