Advertisement
STANAANDREY

ac lab 11

Dec 6th, 2023
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1.  
  2. module rgst #(
  3. parameter w=8
  4. )(
  5. input clk, rst_b, ld, clr, input [w-1:0] d, output reg [w-1:0] q
  6. );
  7. always @ (posedge clk, negedge rst_b)
  8. if (!rst_b) q <= 0;
  9. else if (clr) q <= 0;
  10. else if (ld) q <= d;
  11. endmodule
  12.  
  13. module mlopadd(
  14. input clk, rst_b,
  15. input[6:0] x,
  16. output reg[13:0] a
  17. );
  18. wire[7:0] var;
  19. rgst #(.w(8)) inst1(.clk(clk), .rst_b(rst_b), .ld(1'd1), .clr(1'd0), .d(x), .q(var));
  20. rgst #(.w(14)) inst2(.clk(clk), .rst_b(rst_b), .ld(1'd1), .clr(1'd0), .d(a + var), .q(a));
  21. endmodule
  22.  
  23. module mlopadd_tb;
  24. reg clk, rst_b;
  25. reg[7:0] x;
  26. wire[13:0] a;
  27. mlopadd inst().clk(clk), .rst(rst_b), .x(x), .a(a));
  28. localparam CLK_PERIOD=100, RUNNING_CYCLES=101, RST_DURATION=25;
  29. initial begin
  30. $display("time\tclk\trst_b\tx\ta");
  31. $monitor("%5t\t%b\t%b\t%3d\t%5d", $time, clk, rst_b, x, a);
  32. clk=0;
  33. repeat (2*RUNNING_CYCLES) #(CLK_PERIOD/2) clk=~clk;
  34. end
  35. initial begin
  36. rst_b=0;
  37. #RST_DURATION rst_b=1;
  38. end
  39. integer k;
  40. initial begin
  41. x=1;
  42. for (k=3;k<200;k=k+2)
  43. #CLK_PERIOD x=k;
  44. end
  45. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement