SHARE
TWEET

Untitled

a guest Feb 20th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. reg [7:0] a;
  2. reg signed [7:0] b;
  3. reg [7:0] c;
  4. reg signed [7:0] d;
  5.  
  6. initial begin
  7.   a =  -8'd69 ;
  8.   b =  -8'd69 ;
  9.   c =  -8'd69 ;
  10.   d =  -8'd69 ;
  11.   #10ns;
  12.   a = a/2     ;
  13.   b = b/2     ;
  14.   #10ns;
  15.   $display("a      : %8b, %d", a, a);
  16.   $display("b      : %8b, %d", b, b);
  17.   $display("c >>>1 : %8b, %d", c>>>1, c>>>1);
  18.   $display("d >>>1 : %8b, %d", d>>>1, d>>>1);
  19. end
  20.    
  21. a      : 01011101,  93
  22. b      : 11011110,  -34
  23. c >>>1 : 01011101,  93
  24. d >>>1 : 11011101,  -35
  25.    
  26. //Declare the reg as signed and divide by a signed value
  27. reg signed [7:0] myReg;
  28. assign result = myReg/2;
  29.  
  30. //Use system functions
  31. assign result = $signed(myReg)/2;
  32.    
  33. reg signed [7:0] a;
  34. reg [7:0] b;
  35.  
  36. initial
  37. begin
  38. result = a;            //Signed
  39. result = a * a;        //Signed
  40. result = a * 10;       //Signed
  41. result = $unsigned(a); //Unsigned
  42. result = a[0];         //Unsigned
  43. result = a[7:0];       //Unsigned
  44. result = {a,a};        //Unsigned
  45. result = 10{a};        //Unsigned
  46. result = a + b;        //Unsigned
  47. result = a * b;        //Unsigned
  48. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top