def expand_addrmask(addrmask):
    """Expands a masked memory address to a list of all the applicable memory
    addresses it could refer to. That is, a string like "00X1010X" could stand
    for the binary numbers 00010100, 00010101, 00110100, or 00110101, which
    correspond to decimal values 20, 21, 52, or 53, respectively. So if you
    give this function the string "00X1010X", it will output the list
    [20, 21, 52, 53]. """
    out = [""]
    for d in addrmask:
        if d == "X":
            d = "01"
        # wow python list comprehensions are awesome. It took me a while to
        # futz my way to the correct syntax but this is really smooth
        out = [a + i for a in out for i in d]
    return out