Post Reply 
A LANGUAGE FOR DIGITAL DESIGN
03-05-2019, 10:22 PM
Post: #3
Python: A LANGUAGE FOR DIGITAL DESIGN
Python Code
Code:
def S(x):
    '''types the value and time of a signal (+ indicating +5V).'''
    t = x & 0x7FFF
    return "+" + str(t) if x & 0x8000 else str(t)
 
def _(a):
    '''complements a signal (without changing its time).'''
    return a ^ 0x8000
 
def AND(a, b):
    '''combines 2 signals with worst case timing.'''
    return max(a & 0x7FFF, b & 0x7FFF) + (a & b & 0x8000)
 
def OR(a, b):
    '''combines 2 signals using DeMorgan's law.'''
    return _(AND(_(a), _(b)))
 
def AND2_(a, b):
    '''is a 2-input nand gate with 9ns delay.'''
    return _(AND(a, b)) + 9
 
def OR3(a, b, c):
    '''is a 3-input or gate with 30ns delay.'''
    return OR(OR(a, b), c) + 30
 
def XOR2(a, b):
    '''is a 2-input exclusive-or gate with 35ns delay.'''
    return OR(AND(a, _(b)), AND(_(a), b)) + 35
 
A = 0 # is a signal known low at 0ns.
 
B = 10 # is a signal known low at 10ms.
 
C = _(10) # is a signal known high at 10ms.
 
def ENB_():
    '''is a signal determined low by A and B at 45ns.'''
    return XOR2(A, B)
 
def XY():
    '''is a signal determined high by A, B and C at 84ns.'''
    return OR3(AND2_(ENB_(), C), A, B)

Python REPL
Code:
>>> S(ENB_())
'45'
 
>>> S(XY())
'+84'
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Python: A LANGUAGE FOR DIGITAL DESIGN - Thomas Klemm - 03-05-2019 10:22 PM



User(s) browsing this thread: 1 Guest(s)