Four bit adder: Difference between revisions

Content added Content deleted
Line 984: Line 984:
=={{header|PL/I}}==
=={{header|PL/I}}==
<lang PL/I>
<lang PL/I>
/* 4-BIT ADDER */ /* 14 August 2010 */
/* A 4-bit adder. */

TEST: PROCEDURE OPTIONS (MAIN);
TEST: PROCEDURE OPTIONS (MAIN);
DECLARE CARRY BIT (1) ALIGNED;
DECLARE CARRY_IN BIT (1) STATIC INITIAL ('0'B) ALIGNED;
DECLARE CARRY_IN BIT (1) STATIC INITIAL ('0'B) ALIGNED;
declare (m, n, sum)(4) bit(1) aligned;
declare (m, n, sum)(4) bit(1) aligned;
Line 992: Line 992:


get edit (m, n) (b(1));
get edit (m, n) (b(1));
put edit (m, ' + ', n, ' = ') (4 b, a, 4 b, a);
put edit (m, ' + ', n, ' = ') (4 b, a);


do i = 4 to 1 by -1;
do i = 4 to 1 by -1;
call full_adder (carry_in, m(i), n(i), sum(i), carry);
call full_adder ((carry_in), m(i), n(i), sum(i), carry_in);
carry_in = carry;
end;
end;
put edit (sum) (b);
put edit (sum) (b);
Line 1,003: Line 1,002:
DECLARE (IN1, IN2, SUM, CARRY) BIT (1) ALIGNED;
DECLARE (IN1, IN2, SUM, CARRY) BIT (1) ALIGNED;


SUM = ^( (IN1 & IN2) | ( ^IN1 & ^IN2) );
SUM = ( ^IN1 & IN2) | ( IN1 & ^IN2);
/* Exclusive OR using only AND, NOT, OR. */
CARRY = IN1 & IN2;
CARRY = IN1 & IN2;