Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. def Opcode(case):
  2. op = ""
  3. if case == "add":
  4. op = "000"
  5. elif case == "nand":
  6. op = "001"
  7. return op
  8.  
  9. def Dectobin(num):
  10. num = int(num)
  11. num = bin(num)[2:].zfill(3)
  12.  
  13. return num
  14.  
  15.  
  16. #Set Path
  17. filename = "ComArch.txt"
  18.  
  19. #All instruction
  20. instruction = list()
  21.  
  22. #split instruction
  23. with open (filename) as fin :
  24. for line in fin :
  25. instruction.append (line)
  26.  
  27.  
  28. for i in instruction :
  29.  
  30. inst = i.split(" ")
  31. few = Opcode(inst[0])
  32. if few == "":
  33. continue
  34. x = Dectobin(inst[1][1:])
  35.  
  36. y = Dectobin(inst[2][1:])
  37. z = Dectobin(inst[3][1:])
  38.  
  39.  
  40. print(i)
  41. print(few,x,y,z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement