A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
35
Task/Four-bit-adder/REXX/four-bit-adder.rexx
Normal file
35
Task/Four-bit-adder/REXX/four-bit-adder.rexx
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*REXX program shows (all) the sums of a full 4-bit adder (with carry).*/
|
||||
call hdr1; call hdr2
|
||||
|
||||
do j=0 for 16
|
||||
do m=0 for 4; a.m=bit(j,m); end
|
||||
do k=0 for 16
|
||||
do m=0 for 4; b.m=bit(k,m); end
|
||||
sc=4bitAdder(a.,b.)
|
||||
z=a.3 a.2 a.1 a.0 '_+_' b.3 b.2 b.1 b.0 '_=_' sc ',' s.3 s.2 s.1 s.0
|
||||
say translate(space(z,0),,'_')
|
||||
end /*k*/
|
||||
end /*j*/
|
||||
|
||||
call hdr2; call hdr1
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
|
||||
/*──────────────────────────────────subroutines/functions───────────────*/
|
||||
hdr1: say 'aaaa + bbbb = c, sum [c=carry]'; return
|
||||
hdr2: say '════ ════ ══════' ; return
|
||||
bit: procedure; arg x,y; return substr(reverse(x2b(d2x(x))),y+1,1)
|
||||
|
||||
/*──────────────────────────────────HALFADDER subroutine-───────────────*/
|
||||
halfAdder: procedure expose c; parse arg x,y; c=x & y; return x && y
|
||||
|
||||
/*──────────────────────────────────FULLADDER subroutine-───────────────*/
|
||||
fullAdder: procedure expose c; parse arg x,y,fc
|
||||
_1=halfAdder(fc,x); c1=c
|
||||
_2=halfAdder(_1,y); c=c | c1; return _2
|
||||
|
||||
/*──────────────────────────────────3BITADDER subroutine-───────────────*/
|
||||
4bitAdder: procedure expose s. a. b.; carry.=0
|
||||
do j=0 for 4; n=j-1
|
||||
s.j=fullAdder(a.j, b.j, carry.n); carry.j=c
|
||||
end /*j*/
|
||||
return c
|
||||
Loading…
Add table
Add a link
Reference in a new issue