Skip to content

Commit a7b9f82

Browse files
committed
Added stage3 and input/output devices
1 parent f0255cb commit a7b9f82

File tree

14 files changed

+358
-265
lines changed

14 files changed

+358
-265
lines changed

emulator/chipset.v

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module CHIPSET(
1212
);
1313

1414
reg is_powered_on;
15-
reg execute_from_ram;
15+
reg flag_execute_from_ram;
16+
reg flag_last_zero;
1617
reg[15:0] pc, pc_next;
1718

1819
// Clock
@@ -79,7 +80,7 @@ module CHIPSET(
7980
.ram_value(ram_value),
8081
.brom_value(brom_value),
8182
.pc(pc),
82-
.execute_from_ram(execute_from_ram));
83+
.execute_from_ram(flag_execute_from_ram));
8384

8485
// STAGE1
8586
wire[31:0] instruction_binary;

emulator/com/decoder.v

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
// module DECODER_4_2(
2-
// output[3:0] out,
3-
// input[1:0] in);
4-
5-
// assign out[0] = (~in[1] & ~in[0]);
6-
// assign out[1] = (~in[1] & in[0]);
7-
// assign out[2] = ( in[1] & ~in[0]);
8-
// assign out[3] = ( in[1] & in[0]);
9-
// endmodule
10-
11-
12-
// module DECODER_8_3(
13-
// output[7:0] out,
14-
// input[2:0] in);
15-
16-
// wire [3:0] _out;
17-
// DECODER_4_2 d(_out[3:0], in[1:0]);
18-
19-
// wire not_in2 = ~in[2];
20-
// assign out[3:0] = _out[3:0] & {not_in2, not_in2, not_in2, not_in2};
21-
// assign out[7:4] = _out[3:0] & {in[2], in[2], in[2], in[2]};
22-
// endmodule
1+
module DECODER_3(
2+
output[7:0] out,
3+
input[2:0] in);
4+
assign out[0] = (in==0);
5+
assign out[1] = (in==1);
6+
assign out[2] = (in==2);
7+
assign out[3] = (in==3);
8+
assign out[4] = (in==4);
9+
assign out[5] = (in==5);
10+
assign out[6] = (in==6);
11+
assign out[7] = (in==7);
12+
endmodule

emulator/com/decoder_test.v

Lines changed: 29 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,30 @@
1-
// `include "emulator/lib/decoder.v"
2-
3-
module decoder_4_2_test;
4-
// reg [1:0] in;
5-
// wire [3:0] out;
6-
7-
// DECODER_4_2 dut(.out(out), .in(in));
8-
9-
// initial begin
10-
// in = 2'b00;
11-
// # 10
12-
// $display("DECODER_TEST: in=%b out=%b", in, out);
13-
// if (out != 4'b0001) begin
14-
// $error("decoder failed");
15-
// end
16-
// in = 2'b01;
17-
// # 10
18-
// $display("DECODER_TEST: in=%b out=%b", in, out);
19-
// if (out != 4'b0010) begin
20-
// $error("decoder failed");
21-
// end
22-
// in = 2'b10;
23-
// # 10
24-
// $display("DECODER_TEST: in=%b out=%b", in, out);
25-
// if (out != 4'b0100) begin
26-
// $error("decoder failed");
27-
// end
28-
// in = 2'b11;
29-
// # 10
30-
// $display("DECODER_TEST: in=%b out=%b", in, out);
31-
// if (out != 4'b1000) begin
32-
// $error("decoder failed");
33-
// end
34-
35-
// end
1+
`include "emulator/com/decoder.v"
2+
3+
module decoder_3_test;
4+
reg [2:0] in;
5+
wire [7:0] out;
6+
7+
DECODER_3 dut(.out(out), .in(in));
8+
9+
initial begin
10+
in = 3'b010;
11+
# 10
12+
$display("DECODER_TEST: in=%b out=%b", in, out);
13+
if (out !== 8'b00000100) begin
14+
$error("decoder failed");
15+
end
16+
in = 3'b101;
17+
# 10
18+
$display("DECODER_TEST: in=%b out=%b", in, out);
19+
if (out !== 8'b00100000) begin
20+
$error("decoder failed");
21+
end
22+
in = 3'b111;
23+
# 10
24+
$display("DECODER_TEST: in=%b out=%b", in, out);
25+
if (out !== 8'b10000000) begin
26+
$error("decoder failed");
27+
end
28+
29+
end
3630
endmodule
37-
38-
39-
// module decoder_8_3_test;
40-
// reg [2:0] in;
41-
// wire [7:0] out;
42-
43-
// DECODER_8_3 dut(.out(out), .in(in));
44-
45-
// initial begin
46-
// in = 3'b010;
47-
// # 10
48-
// $display("DECODER_TEST: in=%b out=%b", in, out);
49-
// if (out != 8'b00000100) begin
50-
// $error("decoder failed");
51-
// $fatal(1);
52-
// end
53-
// in = 3'b101;
54-
// # 10
55-
// $display("DECODER_TEST: in=%b out=%b", in, out);
56-
// if (out != 8'b00100000) begin
57-
// $error("decoder failed");
58-
// $fatal(1);
59-
// end
60-
// end
61-
// endmodule

emulator/com/flipflop.v

Lines changed: 0 additions & 30 deletions
This file was deleted.

emulator/com/flipflop_test.v

Lines changed: 0 additions & 58 deletions
This file was deleted.

emulator/com/input_devices.v

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module InputDevices(
2+
output[31:0] value,
3+
input[15:0] address,
4+
input[31:0] device0_values,
5+
input[31:0] device1_values);
6+
7+
reg[31:0] _value;
8+
always @(address) begin
9+
case (address)
10+
0: _value = device0_values;
11+
1: _value = device1_values;
12+
endcase
13+
end
14+
assign value = _value;
15+
endmodule

emulator/com/input_devices_test.v

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
`include "emulator/com/input_devices.v"
2+
3+
module InputDevices_test;
4+
localparam [31:0] INPUT1 = 32'b11100101111110000100101010110001;
5+
localparam [31:0] INPUT2 = 32'b01011100100011000110101000000001;
6+
7+
reg[31:0] device0_values = INPUT1;
8+
reg[31:0] device1_values = INPUT2;
9+
reg[15:0] address;
10+
11+
wire[31:0] value;
12+
13+
InputDevices dut(
14+
.value(value),
15+
.address(address),
16+
.device0_values(device0_values),
17+
.device1_values(device1_values));
18+
19+
initial begin
20+
address = 0;
21+
# 10
22+
$display("INPUT_DEVICES_TEST: address=%b value=%b", address, value);
23+
if (value !== INPUT1) begin
24+
$error("in failed");
25+
$fatal(1);
26+
end
27+
address = 1;
28+
# 10
29+
$display("INPUT_DEVICES_TEST: address=%b value=%b", address, value);
30+
if (value !== INPUT2) begin
31+
$error("in failed");
32+
$fatal(1);
33+
end
34+
end
35+
endmodule

emulator/com/latch.v

Lines changed: 0 additions & 13 deletions
This file was deleted.

emulator/com/latch_test.v

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)