Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. # Set Path
  2. filename = "ComArch.txt"
  3.  
  4. # BackgroundOperation===============================================
  5.  
  6. # DECIMAL TO BINARY
  7. def Dectobin(num):
  8. num = int(num)
  9. num = bin(num)[2:].zfill(3)
  10. return num
  11.  
  12. # OPCODE
  13. def Opcode(case):
  14. op = ""
  15. if case == "add":
  16. op = "000"
  17. elif case == "nand":
  18. op = "001"
  19. return op
  20.  
  21. # TYPE DEFINATION
  22. def checkType(instructionCode) :
  23. Rtype = ['add','sub','xor','nand','or','and','sll']
  24. Itype = ['lw','ld','lwu','addi','xori','jalr','andi']
  25. Stype = ['sw','sd']
  26. SBtype = ['beq','bne','blt','bge','bltu','bgeu']
  27.  
  28. if instructionCode in Rtype :
  29. return "R"
  30. elif instructionCode in Itype :
  31. return "I"
  32. elif instructionCode in Stype :
  33. return "S"
  34. elif instructionCode in SBtype :
  35. return "SB"
  36. elif instructionCode==".fill" :
  37. return "FILL"
  38. else :
  39. return "ERROR"
  40.  
  41. # BackgroundOperation===============================================
  42.  
  43.  
  44. # Main Program======================================================
  45.  
  46. # All instruction
  47. instruction = list()
  48. variableOfFill = {}
  49.  
  50. # Split instruction
  51. with open (filename) as fin :
  52. for line in fin :
  53. instruction.append (line)
  54.  
  55.  
  56. for i in instruction :
  57. label = (i[0:6])
  58. command = (i[8:99])
  59. inst = command.split(" ")
  60. value = inst[1]
  61.  
  62. # Check Type of Inst
  63. instType = checkType(inst[0])
  64.  
  65. if instType == "FILL" :
  66. # label = variable , command = Value
  67. variableOfFill[label] = value
  68. print(variableOfFill)
  69. # Main Program======================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement