Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module alu(input [31:0] a, b, input [2:0] f, output reg [31:0] y, output reg zero);
- `define AND 3'b000
- `define OR 3'b001
- `define PLUS 3'b010
- `define NON 3'b011
- `define ANDBNOT 3'b100
- `define ORBNOT 3'b101
- `define MINUS 3'b110
- `define SLT 3'b111
- always @(a or b) begin
- if(f == `AND) begin
- y <= a & b;
- end
- else if(f == `OR) begin
- y <= a | b;
- end
- else if(f == `PLUS) begin
- y <= a + b;
- end
- else if(f == `ANDBNOT) begin
- y <= a & ~b;
- end
- else if(f == `ORBNOT) begin
- y <= a | ~b;
- end
- else if(f == `MINUS) begin
- y <= a - b;
- end
- else if(f == `SLT) begin
- if(a >= b) begin
- y <= 32'b1;
- end
- else begin
- y <= 32'b0;
- end
- end
- if(y == 32'b0) zero <= 1;
- else zero <= 0;
- end
- endmodule
- module test_alu;
- integer data_file;
- integer scan_file;
- reg [7:0] a, b, y;
- reg [2:0] f;
- reg zero, clock;
- wire [7:0] ycheck;
- wire zcheck;
- `define NULL 0
- initial begin
- data_file = $fopen("alu.tv", "r");
- if (data_file == `NULL) begin
- $display("data_file handle was NULL");
- $finish;
- end
- end
- always @(*) begin
- #10 clock <= -clock;
- end
- always @(posedge clock) begin
- scan_file = $fscanf(data_file, "%h %h %h %h %h\n", f, a, b, y, zero);
- if (!$feof(data_file)) begin
- alu a1(a, b, f, ycheck, zcheck);
- if(ycheck == y) begin
- $display("Correct Output for %h %h %h", f, a, b);
- end
- else begin2
- $display("INCORRECT VALUE FOR OUTPUT for %h %h %h", f, a, b);
- end
- if(zcheck == zero) begin
- $display("Correct Zero Value for %h %h %h", f, a, b);
- end
- else begin
- $display("INCORRECT VALUE FOR ZERO OUTPUT for %h %h %h", f, a, b);
- end
- end
- end
- endmodule
- 2 00000000 00000000 00000000 1
- 2 00000000 FFFFFFFF FFFFFFFF 0
- 2 00000001 FFFFFFFF 00000000 1
- 2 000000FF 00000001
- 6 00000000 00000000 00000000 1
- 6 00000000 FFFFFFFF 00000001 0
- 6 00000001
- 6 00000100
- 7 00000000 00000000 00000000 1
- 7 00000000 00000001 0
- 7 00000000
- 7 00000001
- 7 FFFFFFFF
- 0 FFFFFFFF FFFFFFFF
- 0 FFFFFFFF 12345678 12345678 0
- 0 12345678 87654321
- 0 00000000 FFFFFFFF
- 1 FFFFFFFF FFFFFFFF
- 1 12345678 87654321
- 1 00000000 FFFFFFFF
- 1 00000000 00000000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement