Line 108... |
Line 108... |
alu_status_expected[N] = alu_result_expected[7];
|
alu_status_expected[N] = alu_result_expected[7];
|
alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
|
alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
|
check;
|
check;
|
end
|
end
|
|
|
/*
|
// BCD
|
// BCD
|
// LDA
|
// LDA
|
alu_a = 0;
|
alu_a = 0;
|
alu_opcode = LDA_IMM;
|
alu_opcode = LDA_IMM;
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
|
//$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
|
@(negedge clk);
|
@(negedge clk);
|
alu_result_expected = 8'h00;
|
alu_result_expected = 8'h00;
|
// NV1BDIZC
|
// NV1BDIZC
|
alu_status_expected[N] = 0;
|
alu_status_expected[N] = 0;
|
alu_status_expected[Z] = 1;
|
alu_status_expected[Z] = 1;
|
check;
|
check;
|
// SED
|
// SED
|
alu_opcode = SED_IMP;
|
alu_opcode = SED_IMP;
|
@(negedge clk);
|
@(negedge clk);
|
alu_status_expected[D] = 1;
|
alu_status_expected[D] = 1;
|
check;
|
check;
|
|
|
// ADC
|
// ADC
|
alu_opcode = ADC_IMM;
|
alu_opcode = ADC_IMM;
|
for (i = 0; i < 1000; i = i + 1)
|
for (i = 0; i < 1000; i = i + 1)
|
begin
|
begin
|
alu_a = $random;
|
alu_a = $random;
|
@(negedge clk);
|
@(negedge clk);
|
$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], DUT.result);
|
$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], DUT.result);
|
sign = alu_result_expected[7];
|
sign = alu_result_expected[7];
|
AL = alu_a[3:0];
|
AL = alu_a[3:0];
|
AH = alu_a[7:4];
|
AH = alu_a[7:4];
|
BL = alu_result_expected[3:0];
|
BL = alu_result_expected[3:0];
|
BH = alu_result_expected[7:4];
|
BH = alu_result_expected[7:4];
|
if ( AL > 9 ) begin
|
if ( AL > 9 ) begin
|
AL = AL - 10;
|
AL = AL - 10;
|
AH = AH + 1;
|
AH = AH + 1;
|
end
|
end
|
if (AH > 9) begin
|
if (AH > 9) begin
|
AH = AH - 10;
|
AH = AH - 10;
|
end
|
end
|
if ( BL > 9 ) begin
|
if ( BL > 9 ) begin
|
BL = BL - 10;
|
BL = BL - 10;
|
BH = BH + 1;
|
BH = BH + 1;
|
end
|
end
|
if ( BH > 9 ) begin
|
if ( BH > 9 ) begin
|
BH = BH - 10;
|
BH = BH - 10;
|
end
|
end
|
{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
|
{C_in,alu_result_expected[3:0]} = AL + BL + alu_status_expected[C];
|
{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
|
{alu_status_expected[C],alu_result_expected[7:4]} = AH + BH + C_in;
|
if ( alu_result_expected[3:0] > 9 ) begin
|
if ( alu_result_expected[3:0] > 9 ) begin
|
alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
|
alu_result_expected[3:0] = alu_result_expected[3:0] - 10;
|
alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
|
alu_result_expected[7:4] = alu_result_expected[7:4] + 1;
|
end
|
end
|
if ( alu_result_expected[7:4] > 9 ) begin
|
if ( alu_result_expected[7:4] > 9 ) begin
|
alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
|
alu_result_expected[7:4] = alu_result_expected[7:4] - 10;
|
alu_status_expected[C] = 1;
|
alu_status_expected[C] = 1;
|
end
|
end
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
alu_status_expected[N] = alu_result_expected[7];
|
alu_status_expected[N] = alu_result_expected[7];
|
alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
|
alu_status_expected[V] = ((alu_a[7] == sign) && (alu_a[7] != alu_result_expected[7]));
|
check;
|
check;
|
end
|
end
|
$stop
|
*/
|
// CLD
|
|
alu_opcode = CLD_IMP;
|
|
@(negedge clk);
|
|
alu_status_expected[D] = 0;
|
|
check;
|
|
|
// ASL
|
// ASL
|
alu_opcode = ASL_ABS;
|
alu_opcode = ASL_ABS;
|
for (i = 0; i < 1000; i = i + 1)
|
for (i = 0; i < 1000; i = i + 1)
|
begin
|
begin
|
Line 208... |
Line 212... |
alu_a = i;
|
alu_a = i;
|
@(negedge clk);
|
@(negedge clk);
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
//$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
|
//$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
|
$display("result_expected = %d",alu_result_expected);
|
//$display("result_expected = %d",alu_result_expected);
|
alu_result_expected = alu_a ^ alu_result_expected;
|
alu_result_expected = alu_a ^ alu_result_expected;
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
alu_status_expected[Z] = (alu_result_expected == 0) ? 1 : 0;
|
alu_status_expected[N] = alu_result_expected[7];
|
alu_status_expected[N] = alu_result_expected[7];
|
$display("result_expected = %d", alu_result_expected);
|
//$display("result_expected = %d", alu_result_expected);
|
check;
|
check;
|
end
|
end
|
|
|
// LDA
|
// LDA
|
alu_a = 0;
|
alu_a = 0;
|
Line 269... |
Line 273... |
for (i = 0; i < 1000; i = i + 1)
|
for (i = 0; i < 1000; i = i + 1)
|
begin
|
begin
|
alu_a = i;
|
alu_a = i;
|
@(negedge clk);
|
@(negedge clk);
|
alu_x_expected = alu_a;
|
alu_x_expected = alu_a;
|
$display("alu_x_expected = %h", alu_x_expected);
|
//$display("alu_x_expected = %h", alu_x_expected);
|
//alu_result_expected = i;
|
//alu_result_expected = i;
|
alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
|
alu_status_expected[Z] = (alu_x_expected == 0) ? 1 : 0;
|
alu_status_expected[N] = alu_x_expected[7];
|
alu_status_expected[N] = alu_x_expected[7];
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
Line 286... |
Line 290... |
for (i = 0; i < 1001; i = i + 1)
|
for (i = 0; i < 1001; i = i + 1)
|
begin
|
begin
|
alu_a = i;
|
alu_a = i;
|
@(negedge clk);
|
@(negedge clk);
|
alu_y_expected = alu_a;
|
alu_y_expected = alu_a;
|
$display("alu_y_expected = %h", alu_y_expected);
|
//$display("alu_y_expected = %h", alu_y_expected);
|
//alu_result_expected = i;
|
//alu_result_expected = i;
|
alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
|
alu_status_expected[Z] = (alu_y_expected == 0) ? 1 : 0;
|
alu_status_expected[N] = alu_y_expected[7];
|
alu_status_expected[N] = alu_y_expected[7];
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
Line 316... |
Line 320... |
alu_opcode = STX_ABS;
|
alu_opcode = STX_ABS;
|
for (i = 0; i < 1000; i = i + 1)
|
for (i = 0; i < 1000; i = i + 1)
|
begin
|
begin
|
alu_a = i;
|
alu_a = i;
|
@(negedge clk);
|
@(negedge clk);
|
$display("alu_x_expected = %h", alu_x_expected);
|
//$display("alu_x_expected = %h", alu_x_expected);
|
//alu_result_expected = i;
|
//alu_result_expected = i;
|
//alu_x_expected = alu_a;
|
//alu_x_expected = alu_a;
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
//$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
|
//$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
|
Line 331... |
Line 335... |
alu_opcode = STY_ABS;
|
alu_opcode = STY_ABS;
|
for (i = 0; i < 1000; i = i + 1)
|
for (i = 0; i < 1000; i = i + 1)
|
begin
|
begin
|
alu_a = i;
|
alu_a = i;
|
@(negedge clk);
|
@(negedge clk);
|
$display("alu_y_expected = %h", alu_y_expected);
|
//$display("alu_y_expected = %h", alu_y_expected);
|
//alu_result_expected = i;
|
//alu_result_expected = i;
|
//alu_y_expected = alu_a;
|
//alu_y_expected = alu_a;
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("i = %d alu_opcode = %h alu_enable = %d", i, alu_opcode, alu_enable);
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
//$display("DUT.A = %h DUT.X = %h DUT.Y = %h", DUT.A, DUT.X, DUT.Y);
|
//$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
|
//$display("op1 = %d op2 = %d c = %d d = %d n = %d v = %d result = %d", alu_a, DUT.A, alu_status[C], alu_status[D], alu_status[N], alu_status[V], alu_result);
|