home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p078 / 7.img / TUTOR.PLB / ADDER.PLD next >
Encoding:
Text File  |  1990-12-11  |  1.3 KB  |  28 lines

  1.                           FOUR-BIT RIPPLE ADDER
  2.  
  3. An adder can be defined in detail with Boolean equations, but with indexed
  4. equations and numerical operations, the task of discovering the detailed
  5. logic can be delegated to the compiler.  This is source code for a 4-bit
  6. ripple adder.  A[3..0] and B[3..0] are the input values, C[0] is the carry
  7. in from lower stages.  S[3..0] is the four-bit sum and C[4] is the carry
  8. out to higher stages.  For each of the four bits (i=3,2,1,0), S[i] is set
  9. to the low bit of the sum (bit 0) and C[i+1] is set to the high bit of the
  10. sum (bit 1).
  11.  
  12. |PAL16L8   in:  (A[3..0], B[3..0], C[0]),
  13. |          io:  (C[3..1], S[3..1]),
  14. |          out: (C[4], S[0])
  15. |
  16. | Title:  "Four-bit ripple adder"
  17. |
  18. | i=3..0:  { S[i]   = (A[i] + B[i] + C[i])[0]
  19. |            C[i+1] = (A[i] + B[i] + C[i])[1] }
  20.  
  21. | Vectors:
  22. | { Display C[0], "+", (A[3..0])d, "+", (B[3..0])d, \
  23. |           " = ", (C[4], S[3~0])d,                 \
  24. |           "  Intermediate carries:  ", C[3..1]
  25. |   Test C[0], A[3..0], B[3..0]
  26. |   End }
  27.  
  28.