Mercurial > hg > Applications > Tokio
comparison Examples/multiply/multi @ 0:cfb7c6b24319
Initial revision
author | kono |
---|---|
date | Thu, 30 Aug 2007 14:57:44 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cfb7c6b24319 |
---|---|
1 | |
2 /* multipiler by Ben Moszkowski */ | |
3 | |
4 mux(Switch,In1,In2,Out) :- | |
5 if Switch = 0 | |
6 then Out = In2 | |
7 else Out = In1. | |
8 | |
9 reg(In,Out) :- @Out = In. | |
10 flipflop(In,Out) :- @Out = In. | |
11 | |
12 dec(In,Out) :- | |
13 if In = 0 | |
14 then Out = 0 | |
15 else Out = In-1. | |
16 | |
17 adder(In1,In2,Out) :- Out = In1+In2. | |
18 | |
19 zero_test(In,Out) :- | |
20 if In = 0 | |
21 then Out = 1 | |
22 else Out = 0. | |
23 | |
24 or_gate(In1,In2,Out) :- | |
25 Out1 is In1 \/ In2, | |
26 Out = Out1. | |
27 | |
28 mult_imp(In1,In2,M,N,Done) :- | |
29 % exists,(B1,B2,B3,B4,L1,L2,L3,L4,L5,L6,L7,L8,L9,L10) | |
30 #zero_test(In1,B4), | |
31 #(L10 = 0), | |
32 #mux(B4,L10,In2,L9), | |
33 #zero_test(In2,B2), | |
34 #dec(In1,L6), | |
35 #adder(L9,M,L8), | |
36 #dec(N,L3), | |
37 #mux(Done,L9,L8,L7), | |
38 #reg(L7,M), | |
39 #mux(Done,In1,L3,L1), | |
40 #reg(L1,N), | |
41 #dec(L3,L4), | |
42 #mux(Done,L6,L4,L5), | |
43 #zero_test(L5,B1), | |
44 #or_gate(B1,B2,B3), | |
45 #flipflop(B3,Done). | |
46 | |
47 main :- | |
48 read((In1,In2)), | |
49 Done = 1, | |
50 M = 39, | |
51 N = 83, | |
52 In1 <-- In1,In2 <-- In2, | |
53 mult_imp(In1,In2,M,N,Done), | |
54 @(halt(Done=1)), | |
55 #write((Done,M,N)). |