Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. module alu(input [31:0] a, b, input [2:0] f, output reg [31:0] y, output reg zero);
  2.  
  3. `define AND 3'b000
  4. `define OR 3'b001
  5. `define PLUS 3'b010
  6. `define NON 3'b011
  7. `define ANDBNOT 3'b100
  8. `define ORBNOT 3'b101
  9. `define MINUS 3'b110
  10. `define SLT 3'b111
  11.  
  12. always @(a or b) begin
  13.  
  14. if(f == `AND) begin
  15.  
  16. y <= a & b;
  17.  
  18. end
  19. else if(f == `OR) begin
  20.  
  21. y <= a | b;
  22.  
  23. end
  24. else if(f == `PLUS) begin
  25.  
  26. y <= a + b;
  27.  
  28. end
  29. else if(f == `ANDBNOT) begin
  30.  
  31. y <= a & ~b;
  32.  
  33. end
  34. else if(f == `ORBNOT) begin
  35.  
  36. y <= a | ~b;
  37.  
  38. end
  39. else if(f == `MINUS) begin
  40.  
  41. y <= a - b;
  42.  
  43. end
  44. else if(f == `SLT) begin
  45.  
  46. if(a >= b) begin
  47. y <= 32'b1;
  48. end
  49. else begin
  50. y <= 32'b0;
  51. end
  52.  
  53. end
  54.  
  55. if(y == 32'b0) zero <= 1;
  56. else zero <= 0;
  57.  
  58. end
  59.  
  60. endmodule
  61.  
  62. module test_alu;
  63.  
  64. integer data_file;
  65. integer scan_file;
  66. reg [7:0] a, b, y;
  67. reg [2:0] f;
  68. reg zero, clock;
  69. wire [7:0] ycheck;
  70. wire zcheck;
  71.  
  72. `define NULL 0
  73.  
  74. initial begin
  75. data_file = $fopen("alu.tv", "r");
  76. if (data_file == `NULL) begin
  77. $display("data_file handle was NULL");
  78. $finish;
  79. end
  80. end
  81.  
  82. always @(*) begin
  83. #10 clock <= -clock;
  84. end
  85.  
  86. always @(posedge clock) begin
  87. scan_file = $fscanf(data_file, "%h %h %h %h %h\n", f, a, b, y, zero);
  88. if (!$feof(data_file)) begin
  89.  
  90. alu a1(a, b, f, ycheck, zcheck);
  91.  
  92. if(ycheck == y) begin
  93. $display("Correct Output for %h %h %h", f, a, b);
  94. end
  95. else begin2
  96. $display("INCORRECT VALUE FOR OUTPUT for %h %h %h", f, a, b);
  97. end
  98.  
  99. if(zcheck == zero) begin
  100. $display("Correct Zero Value for %h %h %h", f, a, b);
  101. end
  102. else begin
  103. $display("INCORRECT VALUE FOR ZERO OUTPUT for %h %h %h", f, a, b);
  104. end
  105.  
  106. end
  107. end
  108.  
  109. endmodule
  110.  
  111. 2 00000000 00000000 00000000 1
  112. 2 00000000 FFFFFFFF FFFFFFFF 0
  113. 2 00000001 FFFFFFFF 00000000 1
  114. 2 000000FF 00000001
  115. 6 00000000 00000000 00000000 1
  116. 6 00000000 FFFFFFFF 00000001 0
  117. 6 00000001
  118. 6 00000100
  119. 7 00000000 00000000 00000000 1
  120. 7 00000000 00000001 0
  121. 7 00000000
  122. 7 00000001
  123. 7 FFFFFFFF
  124. 0 FFFFFFFF FFFFFFFF
  125. 0 FFFFFFFF 12345678 12345678 0
  126. 0 12345678 87654321
  127. 0 00000000 FFFFFFFF
  128. 1 FFFFFFFF FFFFFFFF
  129. 1 12345678 87654321
  130. 1 00000000 FFFFFFFF
  131. 1 00000000 00000000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement