## Computer Scientists? – Building logic addition circuit with MAX

Apr 17, 2006 at 8:37pm

# Computer Scientists? – Building logic addition circuit with MAX

Hello all,

I am beginning to learn the Max environment for an introductory computer science course. My teacher doesn’t use Max, so I am hoping someone here might be able to help (I am learning Max so I can use it with my artwork – teleo!!!)…
I am trying to build an addition circuit using logic gates (&&, ||, and external notX(attached)). My problems is that I do not have a great handle on the whole right-to-left thing, and can’t get the outputs correct with only one ‘bang’ – I have commented everything in the patch to explain the problem more clearly.
thanks much,
tr

ps: Thanks to opendragon.com for notX external

max v2;
#N vpatcher 43 61 1417 870;
#P window setfont “Sans Serif” 9.;
#P number 741 708 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 493 708 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 676 459 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 597 459 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 502 459 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 552 459 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 923 500 30 196617 notA , notB , C;
#P comment 846 500 35 196617 notA , B , notC;
#P comment 800 500 35 196617 A , notB , notC;
#P comment 750 500 17 196617 A , B , C;
#P window linecount 2;
#P comment 676 500 30 196617 notA , B , C;
#P window linecount 3;
#P comment 597 500 32 196617 A , notB , C;
#P comment 552 500 25 196617 A , B , notC;
#P window linecount 1;
#P comment 750 479 13 196617 4;
#P comment 800 479 13 196617 3;
#P comment 846 479 13 196617 2;
#P comment 923 479 13 196617 1;
#P comment 676 479 13 196617 5;
#P comment 597 479 13 196617 6;
#P comment 552 479 13 196617 7;
#P number 887 151 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 955 151 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 837 151 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 923 459 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 846 459 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 750 459 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 800 459 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 878 120 27 196617 int;
#P newex 821 120 27 196617 int;
#P newex 937 120 27 196617 int;
#P newex 588 639 88 196617 ||;
#P newex 493 639 59 196617 ||;
#P newex 493 678 105 196617 ||;
#P newex 493 435 26 196617 &&;
#P newex 509 401 27 196617 &&;
#P newex 588 435 27 196617 &&;
#P newex 666 435 25 196617 &&;
#P newex 558 401 27 196617 &&;
#P newex 605 401 27 196617 &&;
#P newex 542 435 26 196617 &&;
#P newex 681 401 27 196617 &&;
#P comment 493 741 25 196617 C(i);
#P newex 836 639 88 196617 ||;
#P newex 741 639 59 196617 ||;
#P newex 741 678 105 196617 ||;
#P newex 741 434 26 196617 &&;
#P newex 757 400 27 196617 &&;
#P newex 836 434 27 196617 &&;
#P newex 914 434 25 196617 &&;
#P newex 806 400 27 196617 &&;
#P newex 853 400 27 196617 &&;
#P newex 790 434 26 196617 &&;
#P button 838 34 15 0;
#P newex 929 400 27 196617 &&;
#P newex 946 213 30 196617 notX;
#P newex 897 213 30 196617 notX;
#P newex 842 213 30 196617 notX;
#P number 838 97 35 9 0 1 2115 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 895 97 35 9 0 1 2115 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 954 97 35 9 0 1 2115 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 954 83 13 196617 A;
#P comment 895 83 13 196617 B;
#P comment 838 83 13 196617 C;
#P comment 741 741 25 196617 S(i);
#P comment 502 479 13 196617 8;
#P window linecount 8;
#P comment 968 459 256 196617 The problem here is that when (C , B , A) are all True , then (4) is the only one that should output True. What happens is that the first bang sets (4 , 3 , 2) all to True , and then the second bang sets (3 , 2) to False and keeps (4) True. Interestingly , the fist time I set (C , B , A) to True , the outputs are correct. After that , the problem starts. Is there a good way to clear what is stored in all of the objects?;
#P window linecount 3;
#P comment 502 500 19 196617 A , B , C;
#P window linecount 1;
#P comment 644 28 182 196617 1 Bit Addition Circuit (with carry);
#P window linecount 10;
#P comment 644 41 63 196617 Truth Table: C B A – S C 0 0 0 – 0 0 1 0 0 – 1 0 0 1 0 – 1 0 1 1 0 – 0 1 0 0 1 – 1 0 1 0 1 – 0 1 0 1 1 – 0 1 1 1 1 – 1 1;
#P window linecount 3;
#P comment 232 457 256 196617 Over here , both (5) and (6) require two bangs to get output True when they are supposed to , but (7) and (8) work ok.;
#P fasten 41 0 36 0 826 166 498 166;
#P connect 36 0 38 0;
#P connect 38 0 37 0;
#P connect 37 0 68 0;
#P connect 36 0 65 0;
#P fasten 42 0 35 0 883 179 514 179;
#P connect 35 0 36 1;
#P fasten 40 0 35 1 942 192 531 192;
#P fasten 13 0 30 0 847 238 547 238;
#P connect 30 0 38 1;
#P connect 30 0 64 0;
#P fasten 42 0 32 0 883 179 563 179;
#P connect 32 0 30 1;
#P fasten 40 0 32 1 942 192 580 192;
#P fasten 14 0 34 0 902 252 593 252;
#P connect 34 0 39 0;
#P connect 39 0 37 1;
#P connect 34 0 66 0;
#P fasten 41 0 31 0 826 166 610 166;
#P connect 31 0 34 1;
#P fasten 40 0 31 1 942 192 627 192;
#P fasten 15 0 33 0 951 265 671 265;
#P connect 33 0 39 1;
#P connect 33 0 67 0;
#P fasten 41 0 29 0 826 166 686 166;
#P connect 29 0 33 1;
#P fasten 42 0 29 1 883 179 703 179;
#P fasten 41 0 24 0 826 281 746 281;
#P connect 24 0 26 0;
#P connect 26 0 25 0;
#P connect 25 0 69 0;
#P connect 24 0 44 0;
#P fasten 42 0 23 0 883 325 762 325;
#P connect 23 0 24 1;
#P fasten 40 0 23 1 942 333 779 333;
#P fasten 40 0 18 0 942 298 795 298;
#P connect 18 0 26 1;
#P connect 18 0 43 0;
#P fasten 13 0 20 0 847 388 811 388;
#P connect 20 0 18 1;
#P fasten 17 0 41 0 843 76 826 76;
#P fasten 14 0 20 1 902 377 828 377;
#P fasten 42 0 22 0 883 289 841 289;
#P connect 22 0 27 0;
#P connect 27 0 25 1;
#P connect 41 0 47 0;
#P connect 12 0 41 1;
#P fasten 41 0 13 0 826 204 847 204;
#P connect 22 0 45 0;
#P fasten 13 0 19 0 847 388 858 388;
#P connect 19 0 22 1;
#P fasten 15 0 19 1 951 387 875 387;
#P fasten 17 0 42 0 843 76 883 76;
#P connect 42 0 49 0;
#P connect 11 0 42 1;
#P fasten 42 0 14 0 883 204 902 204;
#P fasten 41 0 21 0 826 281 894 281 894 427 919 427;
#P connect 21 0 27 1;
#P connect 21 0 46 0;
#P fasten 14 0 16 0 902 377 934 377;
#P connect 16 0 21 1;
#P fasten 17 0 40 0 843 76 942 76;
#P fasten 40 0 15 0 942 203 951 203;
#P connect 15 0 16 1;
#P connect 10 0 40 1;
#P connect 40 0 48 0;
#P pop;

#25475
Apr 18, 2006 at 5:46am

It’s a right-to-left precedence problem. For instance the last && of
(5) gets its left input from the rightmost notX, so it makes the
calculation before getting its second operator (which is obviously
not good).
I suggest you to collect A B and C in a list (using [pack 0 0 0]),
and recreate the boolean calculations for (1, 2, 3, etc.) in eight
expr objects (see the help file) and give the A B C list to each expr
object.
For instance the expr for (8) would be [expr \$i1 && \$i2 && \$i3], the
expr for (7) woud be [expr \$i1 && \$i2 && ! \$i3] (provided you have
packed A B and C in alphabetic order, not C B and A).

m

HomePage: http://www.giri.it
Computer Music Italian Forum http://www.virtual-sound.com

#75053
Apr 19, 2006 at 1:08am

Thanks for the advice! I will try this out.
tr

#75054

You must be logged in to reply to this topic.