import math


def parseAddressDA(address, blocks, block_size, word_size = 4):
    """ Helper function that will parse the address, for direct Associative method. \n
        Paramenters: \n
        \t address \n
        \t blocks \n
        \t block_size \n
        \t word_size: default is 4\n
        Return dictionary with tag, address_result, index,word_offset, byte_offset
    """
    binary_address = bin(address)[2:].zfill(32)
    byte_offset_size = int(math.log2(word_size))
    word_offset_size = int(math.log2(block_size))
    index_size = int(math.log2(blocks))
    byte_offset = int(binary_address[-byte_offset_size:],2)
    if word_offset_size == 0:
        word_offset = 0
    elif word_offset_size == 1:
        word_offset = int(binary_address[len(binary_address)-byte_offset_size-1],2)
    else:
        word_offset = int(binary_address[-byte_offset_size-byte_offset_size:-byte_offset_size],2)
    index = int(binary_address[-byte_offset_size-word_offset_size-index_size:-byte_offset_size-word_offset_size],2)
    tag = int(binary_address[:-(byte_offset_size+byte_offset_size)-1],2)
    #address_result = int(binary_address[:-byte_offset_size],2)
    return {"tag" : tag, "address_result" : address - byte_offset , "index" : index , "word_offset" : word_offset, "byte_offset" : byte_offset}