Advertisement
Guest User

Untitled

a guest
Jun 14th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. module Obfuscated_3_Bit_Counter(clk,clr_,in,out);
  2. //Declare our inputs
  3. input clk,clr_;
  4. //if in == 1 then up counter
  5. //if in == 0 then down counter
  6. input in;
  7. //Declare our outputs
  8. output[3:0] out;
  9. //Internal Variables
  10. //These are used for the states
  11. reg[3:0] S,S_; //S = Present, S_ = Next
  12. reg[3:0] tmp_out;
  13. //Some Local Parameters for us
  14. //This is just for readable code
  15. localparam S0 = 4'b0000, S1 = 4'b0001, S2 = 4'b0010, S3 = 4'b0011, S4 = 4'b0100, S5 = 4'b0101, S6 = 4'b0110, S7 = 4'b0111, S8 = 4'b1000, S9 = 4'b1001, S10 = 4'b1010, S11 = 4'b1011, S12 = 4'b1100;
  16. //Obfuscation states S0-S4
  17. //Normnal mode states S5-S12
  18. //Enabling Key = 10101
  19.  
  20. //Combinational Logic that Defines the next states
  21. //Transition function δ:IxS------> S
  22. always @ (in,S) begin
  23. //Here a case statement starts to deftermine the states
  24. case(S)
  25. //////////////////////////////
  26. S0: if(in == 1)
  27. S_ = S1;
  28. else
  29. S_ = S0;
  30. //////////////////////////////
  31. S1: if(in == 0)
  32. S_ = S2;
  33. else
  34. S_ = S1;
  35. //////////////////////////////
  36. S2: if(in == 1)
  37. S_ = S3;
  38. else
  39. S_ = S2;
  40. //////////////////////////////
  41. S3: if(in == 0)
  42. S_ = S3;
  43. else
  44. S_ = S4;
  45. //////////////////////////////
  46. S4: if(in == 0)
  47. S_ = S4;
  48. else
  49. S_ = S5;
  50. //////////////////////////////
  51. S5: if(in == 1)
  52. S_ = S6;
  53. else
  54. S_ = S12;
  55. //////////////////////////////
  56. S6: if(in == 1)
  57. S_ = S7;
  58. else
  59. S_ = S5;
  60. //////////////////////////////
  61. S7: if(in == 1)
  62. S_ = S8;
  63. else
  64. S_ = S6;
  65. //////////////////////////////
  66. S8: if(in == 1)
  67. S_ = S9;
  68. else
  69. S_ = S7;
  70. //////////////////////////////
  71. S9: if(in == 1)
  72. S_ = S10;
  73. else
  74. S_ = S8;
  75. //////////////////////////////
  76. S10: if(in == 1)
  77. S_ = S11;
  78. else
  79. S_ = S9;
  80. //////////////////////////////
  81. S11: if(in == 1)
  82. S_ = S12;
  83. else
  84. S_ = S10;
  85. //////////////////////////////
  86. S12: if(in == 1)
  87. S_ = S5;
  88. else
  89. S_ = S11;
  90. //////////////////////////////
  91. default: S_ = 4'bxxxx; //this is so that verilog knows oti sto vilo m
  92. endcase
  93. end
  94.  
  95. //Define State Update
  96. always @ (negedge clr_, posedge clk) begin
  97. //An to clr en 0 tote kame reset to FSM, aka parto sto proto state aka to
  98. //obfuscation mode sto state 0
  99. if(!clr_)
  100. S <= S0;
  101. //Else an to clr en 1 tote men kamis reset to FSM je vale to current state na pai
  102. //sto calculated next state (pou ivres me to combinational logic pio pano)
  103. else
  104. S <= S_;
  105. end
  106. //Define Output combinational logic
  107. //This is the output functuion
  108. // λ: S--->O (Moore)
  109. // λ: SXI--->O (Mealy)
  110. always @ (*) begin
  111. //If obfuscation mode
  112. if(S == S0 | S == S1 | S == S2 | S == S3 | S == S4)
  113. tmp_out <= ~S; //obfuscasion mode
  114. else
  115. tmp_out <= S-5; //normal mode as a 3bit counter
  116. end
  117.  
  118. //I have no idea what this
  119. //I think this is an assign block
  120. assign out = tmp_out;
  121.  
  122. endmodule //End of module Obfuscated_3_Bit_Counter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement