Example #1
0
def RFController(address, data=0, RegWrite=0):
    if RegWrite:

        RFMemory[str(address)] = str(data)
        saveMemory()

    else:
        if not len(address)-5:
            return BitArray(str(RFMemory[str(address)]))
Example #2
0
def DMController(address, data=0, MemRead=0, MemWrite=0):

    if MemWrite:

        DMMemory[str(address)] = str(data)
        saveMemory()

    if MemRead:

        return BitArray(str(DMMemory[str(address)]))
Example #3
0
    def toBitArray(self,text):
        symbols = [];
        token = self.endBinaryShift(len(text)).getToken();
        while (token != None) :
            symbols.insert(0,token);
            token = token.getPrevious();

        bitArray = BitArray.BitArray();
        for symbol in symbols :
          
            bitArray = symbol.appendTo(bitArray, text);

        return bitArray;
Example #4
0
    def encode(self,data):
        result = BitArray.BitArray();

        while (len(data) >= 32) :
            chunkLength = min(len(data), (2048 + 32 - 1));
            result.append(CODE_UPPER_BS, 5);
            result.append(0, 5);
            result.append((chunkLength - 32), 11);
            result.appendBytes(data[ 0: chunkLength]);
            data = data[chunkLength:];

        if (len(data) > 0) :
            result.append(CODE_UPPER_BS, 5);
            result.append(len(data), 5);
            result.appendBytes(data);

        return result;
Example #5
0
    def aluoperation(self, aluop, opernd1=None, opernd2=None):
        if (aluop == BitArray('010')):
            return (opernd1 + opernd2).extend(val=0)
        if (aluop == BitArray('011')):

            return (opernd1 - opernd2).extend(val=0)
        if (aluop == BitArray('000')):
            return (opernd1 & opernd2).extend(val=0)
        if (aluop == BitArray('001')):
            return (opernd1 | opernd2).extend(val=0)
        if (aluop == BitArray('101')):
            return (opernd1 * opernd2).extend(val=0)
        if (aluop == BitArray('100')):
            if (opernd1 < opernd2):
                return BitArray('1')
            else:
                return BitArray('0')


# if __name__ == "__main__":
#     a = Alu()
#     k = a.alucontrol(0,1,100010)
#     l = a.aluoperation(k,BitArray('010'),BitArray('000'))
#     print (l)
def Decompress(buf):
    (compressed_size, decompressed_size) = struct.unpack("<II", buf[0:8])
    bits = BitArray.BitArray(buf[8:])

    outbuf = ''
    blocksize = 0
    charlen_hufftree = None
    positionset_hufftree = None
    while decompressed_size:
        if blocksize == 0:
            blocksize = bits.read(16)
            extra_hufftree = BuildHuffmanTree(LoadHuffmanSyms(bits, 5, 3))
            charlen_hufftree = BuildHuffmanTree(
                LoadCharLenHuffmanSyms(bits, extra_hufftree))

            #		positionset_hufftree = BuildHuffmanTree(LoadHuffmanSyms(bits, 4, -1))
            positionset_hufftree = BuildHuffmanTree(
                LoadHuffmanSyms(bits, 5, -1))

        c = HuffmanDecode(charlen_hufftree, bits)
        blocksize -= 1
        if c < 256:
            outbuf += chr(c)
            decompressed_size -= 1
        else:
            data_length = (c & 0xff) + 3
            pos_bitlen = HuffmanDecode(positionset_hufftree, bits)
            data_offset = pos_bitlen
            if pos_bitlen > 1:
                data_offset = (1 <<
                               (pos_bitlen - 1)) + bits.read(pos_bitlen - 1)
            data_idx = len(outbuf) - data_offset - 1

            for i in xrange(0, data_length):
                outbuf += outbuf[data_idx + i]
            decompressed_size -= data_length

    return outbuf
Example #7
0
def IMController(pcounter):

    return BitArray(str(IMMemory[pcounter]))
Example #8
0
 def alucontrol(self, aluop1, aluop0, function=BitArray('222222')):
     if (aluop1 == 0 and aluop0 == 0):
         return BitArray('010')
     elif (aluop1 == 0 and aluop0 == 1):
         return BitArray('011')
     elif (aluop1 == 1 and aluop0 == 0):
         if (function == BitArray('100000')):
             return BitArray('010')
         elif (function == BitArray('100010')):
             return BitArray('011')
         elif (function == BitArray('100100')):
             return BitArray('000')
         elif (function == BitArray('100101')):
             return BitArray('001')
         elif (function == BitArray('101010')):
             return BitArray('100')
         elif (function == BitArray('111111')):
             return BitArray('101')
Example #9
0
import time
from Alu import *
from Decode import *
from BitArray import *
from ControlUnit import *
from ControlUnit import *
from MemoryHandling import *

instructions = {}
ADD = BitArray("100000")
ADDI = BitArray("001000")
MULT = BitArray("011000")
SUB = BitArray("100010")
BEQ = BitArray("000100")
BNE = BitArray("000101")
LW = BitArray("100011")
SW = BitArray("101011")
SLL = BitArray("000000")
J = BitArray("000010")
HALT = BitArray("111111")
#ADD, ADDI, MULT, SUB, BEQ, BNE, LW, SW, SLL, J
PC = 0
CLOCK_CYCLES = 0

while (1):
    CLOCK_CYCLES = CLOCK_CYCLES + 1

    i = IMController(PC)

    ALUObject = Alu()
    instructionArray = []