summaryrefslogtreecommitdiffstats
path: root/cpu8/cpu_adder16bit/cpu_adder16bit.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpu8/cpu_adder16bit/cpu_adder16bit.hpp')
-rw-r--r--cpu8/cpu_adder16bit/cpu_adder16bit.hpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/cpu8/cpu_adder16bit/cpu_adder16bit.hpp b/cpu8/cpu_adder16bit/cpu_adder16bit.hpp
new file mode 100644
index 0000000..a132665
--- /dev/null
+++ b/cpu8/cpu_adder16bit/cpu_adder16bit.hpp
@@ -0,0 +1,73 @@
+#ifndef __SYSC_CPU_ADDER16BIT_HPP
+#define __SYSC_CPU_ADDER16BIT_HPP
+
+#include "systemc.h"
+#include "../cpu_and/cpu_and.hpp"
+#include "../cpu_or/cpu_or.hpp"
+#include "../cpu_not/cpu_not.hpp"
+#include "../cpu_full_adder/cpu_full_adder.hpp"
+
+
+SC_MODULE (cpu_adder16bit)
+{
+ const static int ADD_N=16;
+ //Inputs
+ sc_in <bool> in_a[ADD_N];
+ sc_in <bool> in_b[ADD_N];
+ sc_in <bool> in_carry;
+ sc_out <bool> out_sum[ADD_N];
+ sc_out <bool> out_carry;
+
+ cpu_full_adder *fulladder[ADD_N];
+
+ sc_signal<bool> sig_fadd[ADD_N-1];
+
+ void do_adder16bit()
+ {
+ /*
+ if (in_sel.read() == 0)
+ {
+ out_c.write(in_a.read());
+ }
+ if (in_sel.read() == 1)
+ {
+ out_c.write(in_b.read());
+ }
+ */
+ }
+
+ SC_CTOR(cpu_adder16bit)
+ {
+
+ int i;
+ for (i=0;i<16;i++)
+ {
+ const int sz=16;
+ char *s=(char *)malloc(sz); //need to free s?
+ snprintf(s,sz,"FULLADD%02d",i);
+ fulladder[i] = new cpu_full_adder(s);
+ }
+
+ for (i=0;i<16;i++)
+ {
+ fulladder[i]->in_a(in_a[i]);
+ fulladder[i]->in_b(in_b[i]);
+ fulladder[i]->out_sum(out_sum[i]);
+ }
+
+ fulladder[0]->in_c(in_carry);
+ fulladder[ADD_N-1]->out_carry(out_carry);
+ for (i=1;i<ADD_N;i++)
+ {
+
+ fulladder[i]->in_c(sig_fadd[i-1]);
+ fulladder[i-1]->out_carry(sig_fadd[i-1]);
+ }
+
+ //SC_METHOD(do_dmux);
+ //sensitive << in_a << in_b << in_sel;
+ }
+
+};
+
+#endif \ No newline at end of file