summaryrefslogtreecommitdiff
path: root/cpu8/cpu_adder16bit/cpu_adder16bit.hpp
blob: a132665debccfea8ecabd9770591b243fc0ebd2c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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