diff options
Diffstat (limited to 'cpu8/cpu_adder16bit/cpu_adder16bit.cpp')
-rw-r--r-- | cpu8/cpu_adder16bit/cpu_adder16bit.cpp | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/cpu8/cpu_adder16bit/cpu_adder16bit.cpp b/cpu8/cpu_adder16bit/cpu_adder16bit.cpp new file mode 100644 index 0000000..723fb47 --- /dev/null +++ b/cpu8/cpu_adder16bit/cpu_adder16bit.cpp @@ -0,0 +1,205 @@ +#include <iostream> +#include <iomanip> + +#include "systemc.h" +#include "systemc" +#include <sysc/tracing/sc_trace.h> +#include <sysc/tracing/sc_vcd_trace.h> + +#include "cpu_adder16bit.hpp" + +#define N 16 + +void write_signal_port_out(sc_out<bool> *port_a, uint16_t d) +{ + int i; + //printf("%x\n",d); + for (i=0;i<N;i++) + { + int bit = (d>>i)&0x01; + //print(bit); + port_a[i]->write(bit); + } + //exit(0); +} + +SC_MODULE(test_cpu_adder16bit) +{ + sc_out<bool> a[N],b[N],carry; + sc_in<bool> clk; + + void test_cpu_adder16bit_stim() + { + wait(); + a[0].write(0); + a[1].write(0); + b[0].write(0); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(0); + b[0].write(0); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(0); + a[1].write(1); + b[0].write(0); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(1); + b[0].write(0); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(0); + a[1].write(0); + b[0].write(1); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(0); + a[1].write(0); + b[0].write(1); + b[1].write(1); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(0); + b[0].write(1); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(1); + b[0].write(1); + b[1].write(0); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(1); + b[0].write(1); + b[1].write(1); + carry.write(0); + + wait(); + a[0].write(1); + a[1].write(1); + b[0].write(0); + b[1].write(1); + carry.write(0); + + wait(); + write_signal_port_out(a,0x0001); + write_signal_port_out(b,0x0000); + + wait(); + write_signal_port_out(a,0x0001); + write_signal_port_out(b,0x0001); + + wait(); + write_signal_port_out(a,0xFFFF); + write_signal_port_out(b,0x0000); + + wait(); + write_signal_port_out(a,0x0000); + write_signal_port_out(b,0xFFFF); + + wait(); + write_signal_port_out(a,0x0F0F); + write_signal_port_out(b,0x0F0F); + + wait(); + write_signal_port_out(a,0xF0F0); + write_signal_port_out(b,0xF0F0); + + wait(); + write_signal_port_out(a,0xFFFF); + write_signal_port_out(b,0x0001); + + wait(); + write_signal_port_out(a,0xFFFF); + write_signal_port_out(b,0x0000); + carry.write(1); + + wait(); + write_signal_port_out(a,0xFFFE); + write_signal_port_out(b,0x0001); + carry.write(0); + + wait(); + + sc_stop(); + } + + SC_CTOR(test_cpu_adder16bit) + { + SC_THREAD(test_cpu_adder16bit_stim); + sensitive << clk.pos(); + + } +}; + + +int sc_main(int argc, char **argv) { + int i; + sc_signal<bool> sig_in_a[N], sig_in_b[N],sig_out_c[N],sig_out_sum[N],sig_in_carry,sig_out_carry; + sc_clock TestClk("TestClk", 10, SC_NS, 0.5, 1, SC_NS); + + test_cpu_adder16bit Stim1("Stimulus"); + Stim1.carry(sig_in_carry); + Stim1.clk(TestClk); + for (i=0;i<N;i++) + { + Stim1.a[i](sig_in_a[i]); + Stim1.b[i](sig_in_b[i]); + } + + + cpu_adder16bit DUT("cpu_adder16bit"); + for (i=0;i<N;i++) + { + DUT.in_a[i](sig_in_a[i]); + DUT.in_b[i](sig_in_b[i]); + DUT.out_sum[i](sig_out_sum[i]); + } + + DUT.in_carry(sig_in_carry); + DUT.out_carry(sig_out_carry); + + + sc_trace_file *Tf; + + Tf = sc_create_vcd_trace_file("trace_cpu_adder16bit.dat"); + sc_trace(Tf, sig_in_carry, "IN_CARRY"); + sc_trace(Tf, sig_out_carry, "OUT_CARRY"); + for (i=0;i<N;i++) + { + const static int sz=16; + char *str_a = (char *)malloc(sz); + snprintf(str_a,sz,"IN_A%02d",i); + sc_trace(Tf, sig_in_a[i], str_a); + char *str_b = (char *)malloc(sz); + snprintf(str_b,sz,"IN_B%02d",i); + sc_trace(Tf, sig_in_b[i], str_b); + char *str_sum = (char *)malloc(sz); + snprintf(str_sum,sz,"OUT_SUM%02d",i); + sc_trace(Tf, sig_out_sum[i], str_sum); + } + + sc_start(); + sc_close_vcd_trace_file(Tf); + + return(0); +}
\ No newline at end of file |