Ejemplo n.º 1
0
def decodeInstr(hexCode): 
    binary = utilFunc.hexToBin(hexCode)
    
    #Checking for branch type
    if(binary[3:6] == '101'):
        for i in range(4):
            dicts_branch.INSTRUCTION_TYPE(binary, i)
            if(const.FLAG_INST_EXECUTED=="1"):
                break
    
    #Checking for load-store
    elif(binary[4] == '1' and binary[6] == '0'):
        for i in range(8):
            dicts_loadStore.INSTRUCTION_TYPE(binary, i)
            if(const.FLAG_INST_EXECUTED=="1"):
                break
    
    if(const.FLAG_INST_EXECUTED=="0"):
        for i in range(11):  
            dicts.INSTRUCTION_TYPE(binary, i)
            if(const.FLAG_INST_EXECUTED=="1"):
                break
            
    if(const.FLAG_INST_EXECUTED=="0"):
        print 'Sorry!!! :( Instruction with hexCode: ' + hexCode + ' is incorrect or not supported'
Ejemplo n.º 2
0
def decodeInstr(hexCode):
    binary = utilFunc.hexToBin(hexCode)

    #Checking for branch type
    if (binary[3:6] == '101'):
        for i in range(4):
            dicts_branch.INSTRUCTION_TYPE(binary, i)
            if (const.FLAG_INST_EXECUTED == "1"):
                break

    #Checking for load-store
    elif (binary[4] == '1' and binary[6] == '0'):
        for i in range(8):
            dicts_loadStore.INSTRUCTION_TYPE(binary, i)
            if (const.FLAG_INST_EXECUTED == "1"):
                break

    if (const.FLAG_INST_EXECUTED == "0"):
        for i in range(11):
            dicts.INSTRUCTION_TYPE(binary, i)
            if (const.FLAG_INST_EXECUTED == "1"):
                break

    if (const.FLAG_INST_EXECUTED == "0"):
        print 'Sorry!!! :( Instruction with hexCode: ' + hexCode + ' is incorrect or not supported'
Ejemplo n.º 3
0
def printMemEngine(command):

    base = command[2]  # x or d
    address = command[3]
    freq = command[1]
    listOfHex = ''

    address = int(address, 16)

    #assume to be in hex
    freqcount = int(freq[0:-1])
    freqtype = freq[-1]  # b w or d
    numOfBits = ''
    if freqtype == 'w':
        for i in range(freqcount):
            data = mem.fetchWordFromMemory(address + (4 * i))
            if data == const.TRAP:
                print 'Memory location could not be accessed'
                return
            listOfHex += data + ' '
            numOfBits = 32
    elif freqtype == 'd':
        for i in range(0, freqcount):
            data1 = mem.fetchWordFromMemory(address + (8 * i))
            data2 = mem.fetchWordFromMemory(address + (8 * i) + 4)
            if data1 == const.TRAP or data2 == const.TRAP:
                print 'Memory location could not be accessed'
                return
            listOfHex += data2 + '' + data1 + ' '
            numOfBits = 64
    elif freqtype == 'b':
        for i in range(0, freqcount):
            data = mem.fetchByteFromHelperMemory(address + i)
            if data == const.TRAP:
                print 'Memory location could not be accessed'
                return
            listOfHex += data + ' '
            numOfBits = 8

    listOfHex = listOfHex.split()

    #print ''
    #print listOfHex
    #print '<'+command[3]+'>'+' : \t\t',

    pretty = 0
    for i in listOfHex:
        if (pretty % 4 == 0):
            print ''
            print '<' + command[3] + '>' + ' + ' + str(
                (pretty * numOfBits) / 8) + ' : \t\t',
        if base == 'x':
            print '0x' + i + '\t\t',
        elif base == 'd':
            binary = utilFunc.hexToBin('0x' + i, numOfBits)
            print str(utilFunc.sInt(binary, numOfBits)) + '\t\t',
        print ' ',
        pretty = pretty + 1
    print ''
Ejemplo n.º 4
0
def printMemEngine(command):
    
    base=command[2] # x or d
    address=command[3]
    freq=command[1]
    listOfHex=''
    
    address=int(address,16)
    
    #assume to be in hex
    freqcount=int(freq[0:-1])
    freqtype=freq[-1] # b w or d
    numOfBits=''
    if freqtype=='w':
        for i in range(freqcount):
            data=mem.fetchWordFromMemory(address+(4*i))
            if data==const.TRAP:
                print 'Memory location could not be accessed'
                return
            listOfHex+=data+' '
            numOfBits=32
    elif freqtype=='d':
        for i in range(0,freqcount):
            data1=mem.fetchWordFromMemory(address+(8*i))
            data2=mem.fetchWordFromMemory(address+(8*i)+4)
            if data1==const.TRAP or data2==const.TRAP:
                print 'Memory location could not be accessed'
                return
            listOfHex+=data2+''+data1+' '
            numOfBits=64
    elif freqtype=='b':
        for i in range(0,freqcount):
            data=mem.fetchByteFromHelperMemory(address+i)
            if data==const.TRAP:
                print 'Memory location could not be accessed'
                return
            listOfHex+=data+' '
            numOfBits=8
    
    listOfHex=listOfHex.split()
    
    #print ''
    #print listOfHex
    #print '<'+command[3]+'>'+' : \t\t',
    
    pretty=0
    for i in listOfHex:
        if (pretty%4==0):
            print ''
            print '<'+command[3]+'>'+' + '+str((pretty*numOfBits)/8)+' : \t\t',
        if base=='x':
            print '0x'+i+'\t\t',
        elif base=='d':
            binary=utilFunc.hexToBin('0x'+i, numOfBits)
            print str(utilFunc.sInt(binary, numOfBits))+'\t\t',
        print ' ',
        pretty=pretty+1
    print ''
Ejemplo n.º 5
0
def main():
    print "---Started---"
    #"52800102"
    hexes = ['d2800041', '94000002', 'd2800040', '52800063', 'd65f03c0']
    for hexcode in hexes:
        print 'inst: ' + utilFunc.hexToBin(hexcode)
        resetInstrFlag()
        #utilFunc.set_Z_flag()
        decoder.decodeInstr(hexcode)
    printAllRegs()
    printAllFlags()
Ejemplo n.º 6
0
def main():
    print "---Started---"
    #"52800102"
    hexes = ['d2800041', '94000002', 'd2800040', '52800063', 'd65f03c0']
    for hexcode in hexes:
        print 'inst: '+utilFunc.hexToBin(hexcode)
        resetInstrFlag()
        #utilFunc.set_Z_flag()
        decoder.decodeInstr(hexcode)
    printAllRegs()
    printAllFlags()