home *** CD-ROM | disk | FTP | other *** search
- FOUR-BIT RIPPLE ADDER
-
- An adder can be defined in detail with Boolean equations, but with indexed
- equations and numerical operations, the task of discovering the detailed
- logic can be delegated to the compiler. This is source code for a 4-bit
- ripple adder. A[3..0] and B[3..0] are the input values, C[0] is the carry
- in from lower stages. S[3..0] is the four-bit sum and C[4] is the carry
- out to higher stages. For each of the four bits (i=3,2,1,0), S[i] is set
- to the low bit of the sum (bit 0) and C[i+1] is set to the high bit of the
- sum (bit 1).
-
- |PAL16L8 in: (A[3..0], B[3..0], C[0]),
- | io: (C[3..1], S[3..1]),
- | out: (C[4], S[0])
- |
- | Title: "Four-bit ripple adder"
- |
- | i=3..0: { S[i] = (A[i] + B[i] + C[i])[0]
- | C[i+1] = (A[i] + B[i] + C[i])[1] }
-
- | Vectors:
- | { Display C[0], "+", (A[3..0])d, "+", (B[3..0])d, \
- | " = ", (C[4], S[3~0])d, \
- | " Intermediate carries: ", C[3..1]
- | Test C[0], A[3..0], B[3..0]
- | End }
-
-