46 lines
1.1 KiB
Haskell
46 lines
1.1 KiB
Haskell
module FullAdder where
|
|
|
|
-- import qualified Prelude.Bool as Bool
|
|
import Clash.Prelude
|
|
|
|
-- | A | B | S | C |
|
|
-- |---+---+---+---|
|
|
-- | 0 | 0 | 0 | 0 |
|
|
-- | 0 | 1 | 1 | 0 |
|
|
-- | 1 | 0 | 1 | 0 |
|
|
-- | 1 | 1 | 0 | 1 |
|
|
|
|
mac :: (Num a) => a -> (a, a) -> (a, a)
|
|
mac acc (x, y) = (acc + x*y, acc)
|
|
|
|
fulladder
|
|
:: Bool -- ^ cin
|
|
-> (Bool, Bool) -- ^ a and b
|
|
-> (Bool, Bool) -- ^ cout and s
|
|
fulladder False (False, False) = (False, False)
|
|
fulladder True (False, False) = (False, True)
|
|
fulladder False (False, True) = (False, True)
|
|
fulladder True (False, True) = (True, False)
|
|
fulladder False (True, False) = (False, True)
|
|
fulladder True (True, False) = (True, False)
|
|
fulladder False (True, True) = (True, False)
|
|
fulladder True (True, True) = (True, True)
|
|
|
|
fulladderS
|
|
:: (HiddenClockResetEnable dom)
|
|
=> Signal dom (Bool, Bool) -- ^
|
|
-> Signal dom Bool -- ^
|
|
fulladderS = mealy fulladder False
|
|
|
|
topEntity
|
|
:: Clock System
|
|
-> Reset System
|
|
-> Enable System
|
|
-> Signal System (Bool, Bool)
|
|
-> Signal System Bool
|
|
topEntity = exposeClockResetEnable fulladderS
|
|
|
|
-- clashi
|
|
-- λ> :l FullAdder.hs
|
|
-- λ> :vhdl
|