-
Notifications
You must be signed in to change notification settings - Fork 1
/
Add16.jack
62 lines (42 loc) · 1.6 KB
/
Add16.jack
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
// Implementation of 16-bit Adder in jack.
class Add16 {
function Array add16(int x, int y){
var Array out,a,b;
var int c,d,e,f,g,h,i,j,k,l,m,n,o,p,q;
let a = toBinaryall.toBinall(x);
let b = toBinaryall.toBinall(y);
let out = Array.new(16);
let out[15] = HalfAdder.sum(a[15],b[15]);
let c = HalfAdder.carry(a[15],b[15]);
let out[14] = FullAdder.sum(a[14],b[14],c);
let d = FullAdder.carry(a[14],b[14],c);
let out[13] = FullAdder.sum(a[13],b[13],d);
let e = FullAdder.carry(a[13],b[13],d);
let out[12] = FullAdder.sum(a[12],b[12],e);
let f = FullAdder.carry(a[12],b[12],e);
let out[11] = FullAdder.sum(a[11],b[11],f);
let g = FullAdder.carry(a[11],b[11],f);
let out[10] =FullAdder.sum(a[10],b[10],g);
let h = FullAdder.carry(a[10],b[10],g);
let out[9] = FullAdder.sum(a[9],b[9],h);
let i = FullAdder.carry(a[9],b[9],h);
let out[8] = FullAdder.sum(a[8],b[8],i);
let j = FullAdder.carry(a[8],b[8],i);
let out[7] = FullAdder.sum(a[7],b[7],j);
let k = FullAdder.carry(a[7],b[7],j);
let out[6] = FullAdder.sum(a[6],b[6],k);
let l = FullAdder.carry(a[6],b[6],k);
let out[5] = FullAdder.sum(a[5],b[5],l);
let m = FullAdder.carry(a[5],b[5],l);
let out[4] = FullAdder.sum(a[4],b[4],m);
let n = FullAdder.carry(a[4],b[4],m);
let out[3] = FullAdder.sum(a[3],b[3],n);
let o = FullAdder.carry(a[3],b[3],n);
let out[2] = FullAdder.sum(a[2],b[2],o);
let p = FullAdder.carry(a[2],b[2],o);
let out[1] = FullAdder.sum(a[1],b[1],p);
let q = FullAdder.carry(a[1],b[1],p);
let out[0] = FullAdder.sum(a[0],b[0],q);
return out;
}
}