Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Set Path
- filename = "ComArch.txt"
- # BackgroundOperation===============================================
- # DECIMAL TO BINARY
- def Dectobin(num):
- num = int(num)
- num = bin(num)[2:].zfill(3)
- return num
- # OPCODE
- def Opcode(case):
- op = ""
- if case == "add":
- op = "000"
- elif case == "nand":
- op = "001"
- return op
- # TYPE DEFINATION
- def checkType(instructionCode) :
- Rtype = ['add','sub','xor','nand','or','and','sll']
- Itype = ['lw','ld','lwu','addi','xori','jalr','andi']
- Stype = ['sw','sd']
- SBtype = ['beq','bne','blt','bge','bltu','bgeu']
- if instructionCode in Rtype :
- return "R"
- elif instructionCode in Itype :
- return "I"
- elif instructionCode in Stype :
- return "S"
- elif instructionCode in SBtype :
- return "SB"
- elif instructionCode==".fill" :
- return "FILL"
- else :
- return "ERROR"
- # BackgroundOperation===============================================
- # Main Program======================================================
- # All instruction
- instruction = list()
- variableOfFill = {}
- # Split instruction
- with open (filename) as fin :
- for line in fin :
- instruction.append (line)
- for i in instruction :
- label = (i[0:6])
- command = (i[8:99])
- inst = command.split(" ")
- value = inst[1]
- # Check Type of Inst
- instType = checkType(inst[0])
- if instType == "FILL" :
- # label = variable , command = Value
- variableOfFill[label] = value
- print(variableOfFill)
- # Main Program======================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement