77 lines
2.8 KiB
Verilog
77 lines
2.8 KiB
Verilog
`include "./alu_basic/alu_basic.v"
|
|
|
|
module basic_alu_tb;
|
|
reg [15:0] a, b;
|
|
reg [3:0] opcode;
|
|
|
|
wire [15:0] result;
|
|
wire zero, carry, negative;
|
|
|
|
basic_alu alu(
|
|
.opcode(opcode),
|
|
.a(a),
|
|
.b(b),
|
|
.result(result),
|
|
.zero(zero),
|
|
.carry(carry),
|
|
.negative(negative)
|
|
);
|
|
|
|
initial begin
|
|
$dumpfile("./alu_basic/alu_basic.vcd");
|
|
$dumpvars(0, basic_alu_tb);
|
|
|
|
opcode = 4'h0; a = 20; b = 5;
|
|
#1
|
|
$display("opcode=%d, a=%d, b=%d, result=%d, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
opcode = 4'h1; a = 20; b = 5;
|
|
#1
|
|
$display("opcode=%d, a=%d, b=%d, result=%d, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
|
|
// ADD con overflow: 65535 + 1 = 0, carry=1, zero=1
|
|
opcode = 4'h0; a = 16'hFFFF; b = 1;
|
|
#1
|
|
$display("opcode=%d, a=%d, b=%d, result=%d, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
|
|
// SUB con negativo: 5 - 20, negative=1
|
|
opcode = 4'h1; a = 5; b = 20;
|
|
#1
|
|
$display("opcode=%d, a=%d, b=%d, result=%d, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
|
|
// MUL: 100 * 5 = 500
|
|
opcode = 4'h2; a = 100; b = 5;
|
|
#1
|
|
$display("opcode=%d, a=%d, b=%d, result=%d, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
|
|
// DIV: 100 / 5 = 20
|
|
opcode = 4'h3; a = 100; b = 5;
|
|
#1
|
|
$display("opcode=%d, a=%d, b=%d, result=%d, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
|
|
// AND: 0xFF00 & 0x0FF0 = 0x0F00
|
|
opcode = 4'h4; a = 16'hFF00; b = 16'h0FF0;
|
|
#1
|
|
$display("opcode=%h, a=%h, b=%h, result=%h, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
|
|
// OR: 0xFF00 | 0x0FF0 = 0xFFF0
|
|
opcode = 4'h5; a = 16'hFF00; b = 16'h0FF0;
|
|
#1
|
|
$display("opcode=%h, a=%h, b=%h, result=%h, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
|
|
// NOT: ~0 = 65535
|
|
opcode = 4'h6; a = 0; b = 0;
|
|
#1
|
|
$display("opcode=%d, a=%d, b=%d, result=%d, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
|
|
// XOR: 0xFF00 ^ 0x0FF0 = 0xF0F0
|
|
opcode = 4'h9; a = 16'hFF00; b = 16'h0FF0;
|
|
#1
|
|
$display("opcode=%h, a=%h, b=%h, result=%h, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
|
|
// NEG: -1 en complemento a 2 = 65535
|
|
opcode = 4'hB; a = 1; b = 0;
|
|
#1
|
|
$display("opcode=%d, a=%d, b=%d, result=%d, zero=%b, carry=%b, negative=%b", opcode, a, b, result, zero, carry, negative);
|
|
end
|
|
|
|
endmodule |