Jump to content

Four bit adder: Difference between revisions

Line 984:
=={{header|PL/I}}==
<lang PL/I>
/* 4-BIT ADDER */ /* 14 August 2010 */
/* A 4-bit adder. */
 
TEST: PROCEDURE OPTIONS (MAIN);
DECLARE CARRY BIT (1) ALIGNED;
DECLARE CARRY_IN BIT (1) STATIC INITIAL ('0'B) ALIGNED;
declare (m, n, sum)(4) bit(1) aligned;
Line 992:
 
get edit (m, n) (b(1));
put edit (m, ' + ', n, ' = ') (4 b, a, 4 b, a);
 
do i = 4 to 1 by -1;
call full_adder ((carry_in), m(i), n(i), sum(i), carrycarry_in);
carry_in = carry;
end;
put edit (sum) (b);
Line 1,003 ⟶ 1,002:
DECLARE (IN1, IN2, SUM, CARRY) BIT (1) ALIGNED;
 
SUM = ^( (^IN1 & IN2) | ( ^IN1 & ^IN2) );
/* Exclusive OR using only AND, NOT, OR. */
CARRY = IN1 & IN2;
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.