#include #include #include "systemc.h" #include "systemc" #include #include #include "cpu_adder16bit.hpp" #define N 16 void write_signal_port_out(sc_out *port_a, uint16_t d) { int i; //printf("%x\n",d); for (i=0;i>i)&0x01; //print(bit); port_a[i]->write(bit); } //exit(0); } SC_MODULE(test_cpu_adder16bit) { sc_out a[N],b[N],carry; sc_in 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 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