Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: cp1254 -*-
  2.  
  3. # hacım, idle'ı açıyosun. file > new window.
  4. # bunu kopyalıyosun. sonra Run > Python Shell
  5. # sonra da run([ buraya kodları virgülle ayırarak yaz ]) diye çalıştırıyosun
  6.  
  7. # not: elif diye biri yok abi, kimse üzerine alınmasın.
  8. # "niye renkli" diye de sormayın.
  9.  
  10. def run(program):
  11.     if(type(program)!=type(list())):
  12.        print("kardeşim [1,7,4,5...] şeklinde yaz, hasta etme adamı")
  13.        return
  14.  
  15.     p=program
  16.     I=0
  17.     R1=0
  18.     R2=0
  19.  
  20.     flag=False
  21.    
  22.     while(not flag):
  23.         if(abs(R1)>129 or abs(R2)>129 or I>255 or I<0):
  24.             flag=True
  25.             print("out of range. halt.")
  26.             continue
  27.        
  28.         if(p[I]==0):
  29.             flag=True
  30.             print(" 0: program terminating.")
  31.             continue
  32.         elif(p[I]==1):
  33.             R1=p[I+1]
  34.             print(" 1:R1 <- ["+str(I+1)+"]("+str(p[I+1])+")")
  35.             I=I+2
  36.             continue
  37.         elif(p[I]==2):
  38.             R2=p[I+1]
  39.             print(" 2:R2 <- ["+str(I+1)+"]("+str(p[I+1])+")")
  40.             I=I+2
  41.             continue
  42.         elif(p[I]==3):
  43.             R1=p[p[I+1]]
  44.             print(" 3:R1 <- [["+str(I+1)+"]](["+str(p[I+1])+"] -> "+str(p[p[I+1]])+")")
  45.             I=I+2
  46.             continue
  47.         elif(p[I]==4):
  48.             R2=p[p[I+1]]
  49.             print(" 4:R2 <- [["+str(I+1)+"]](["+str(p[I+1])+"] -> "+str(p[p[I+1]])+")")
  50.             I=I+2
  51.             continue
  52.         elif(p[I]==5):
  53.             R1=R2
  54.             print(" 5:R1 <- R2("+str(R2)+")")
  55.             I=I+1
  56.             continue
  57.         elif(p[I]==6):
  58.             R1=p[R2]
  59.             print(" 6:R1 <- ["+str(R2)+"]("+str(R2)+")")
  60.             I=I+1
  61.             continue
  62.         elif(p[I]==7):
  63.             p[R1]=R2
  64.             print(" 7:["+str(R1)+"] <- R2("+str(R2)+")")
  65.             I=I+1
  66.             continue
  67.         elif(p[I]==8):
  68.             p[p[I+1]]=R1
  69.             print(" 8:["+str(p[I+1])+"] <- R1("+str(R1)+")")
  70.             I=I+1
  71.             continue
  72.         elif(p[I]==9):
  73.             print(" 9: jump from "+str(I)+" to "+str(p[I+1]))
  74.             I=p[I+1]
  75.             continue
  76.         elif(p[I]==10):
  77.             if(R1==0):
  78.                 print("10: conditional jump not taken(R1==0)")
  79.                 I=I+2
  80.             else:
  81.                 print("10: conditional jump taken(R1=="+str(R1)+"). jump from "+str(I)+" to "+str(p[I+1]))
  82.                 I=p[I+1]
  83.             continue
  84.         elif(p[I]==11):
  85.             R1=R1+R2
  86.             print("11:R1 <- R1("+str(R1)+") + R2("+str(R2)+")")
  87.             I=I+1
  88.             continue
  89.         elif(p[I]==12):
  90.             R1=R1-R2
  91.             print("12:R1 <- R1("+str(R1)+") - R2("+str(R2)+")")
  92.             I=I+1
  93.             continue
  94.         elif(p[I]==13):
  95.             R1=R1*R2
  96.             print("13:R1 <- R1("+str(R1)+") x R2("+str(R2)+")")
  97.             I=I+1
  98.             continue
  99.         elif(p[I]==14):
  100.             R1=R1/R2
  101.             print("14:R1 <- R1("+str(R1)+") / R2("+str(R2)+")")
  102.             I=I+1
  103.             continue
  104.         elif(p[I]==15):
  105.             R1=-R1
  106.             print("15:R1 <- -R1("+str(R1)+")")
  107.             I=I+1
  108.             continue
  109.         elif(p[I]==16):
  110.             if(R1==R2):
  111.                 print("16: comparison(R1==R2) R1 <- 0")
  112.                 R1=0
  113.             elif(R1>R2):
  114.                 print("16: comparison(R1>R2) R1 <- 1")
  115.                 R1=1
  116.             else:
  117.                 print("16: comparison(R1<R2) R1 <- -1")
  118.                 R1=-1
  119.             I=I+1
  120.             continue
  121.  
  122.     print("R1 = "+str(R1))
  123.     print("R2 = "+str(R2))
  124.     print("I  = "+str(I))
  125.     print(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement