Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: cp1254 -*-
- # hacım, idle'ı açıyosun. file > new window.
- # bunu kopyalıyosun. sonra Run > Python Shell
- # sonra da run([ buraya kodları virgülle ayırarak yaz ]) diye çalıştırıyosun
- # not: elif diye biri yok abi, kimse üzerine alınmasın.
- # "niye renkli" diye de sormayın.
- def run(program):
- if(type(program)!=type(list())):
- print("kardeşim [1,7,4,5...] şeklinde yaz, hasta etme adamı")
- return
- p=program
- I=0
- R1=0
- R2=0
- flag=False
- while(not flag):
- if(abs(R1)>129 or abs(R2)>129 or I>255 or I<0):
- flag=True
- print("out of range. halt.")
- continue
- if(p[I]==0):
- flag=True
- print(" 0: program terminating.")
- continue
- elif(p[I]==1):
- R1=p[I+1]
- print(" 1:R1 <- ["+str(I+1)+"]("+str(p[I+1])+")")
- I=I+2
- continue
- elif(p[I]==2):
- R2=p[I+1]
- print(" 2:R2 <- ["+str(I+1)+"]("+str(p[I+1])+")")
- I=I+2
- continue
- elif(p[I]==3):
- R1=p[p[I+1]]
- print(" 3:R1 <- [["+str(I+1)+"]](["+str(p[I+1])+"] -> "+str(p[p[I+1]])+")")
- I=I+2
- continue
- elif(p[I]==4):
- R2=p[p[I+1]]
- print(" 4:R2 <- [["+str(I+1)+"]](["+str(p[I+1])+"] -> "+str(p[p[I+1]])+")")
- I=I+2
- continue
- elif(p[I]==5):
- R1=R2
- print(" 5:R1 <- R2("+str(R2)+")")
- I=I+1
- continue
- elif(p[I]==6):
- R1=p[R2]
- print(" 6:R1 <- ["+str(R2)+"]("+str(R2)+")")
- I=I+1
- continue
- elif(p[I]==7):
- p[R1]=R2
- print(" 7:["+str(R1)+"] <- R2("+str(R2)+")")
- I=I+1
- continue
- elif(p[I]==8):
- p[p[I+1]]=R1
- print(" 8:["+str(p[I+1])+"] <- R1("+str(R1)+")")
- I=I+1
- continue
- elif(p[I]==9):
- print(" 9: jump from "+str(I)+" to "+str(p[I+1]))
- I=p[I+1]
- continue
- elif(p[I]==10):
- if(R1==0):
- print("10: conditional jump not taken(R1==0)")
- I=I+2
- else:
- print("10: conditional jump taken(R1=="+str(R1)+"). jump from "+str(I)+" to "+str(p[I+1]))
- I=p[I+1]
- continue
- elif(p[I]==11):
- R1=R1+R2
- print("11:R1 <- R1("+str(R1)+") + R2("+str(R2)+")")
- I=I+1
- continue
- elif(p[I]==12):
- R1=R1-R2
- print("12:R1 <- R1("+str(R1)+") - R2("+str(R2)+")")
- I=I+1
- continue
- elif(p[I]==13):
- R1=R1*R2
- print("13:R1 <- R1("+str(R1)+") x R2("+str(R2)+")")
- I=I+1
- continue
- elif(p[I]==14):
- R1=R1/R2
- print("14:R1 <- R1("+str(R1)+") / R2("+str(R2)+")")
- I=I+1
- continue
- elif(p[I]==15):
- R1=-R1
- print("15:R1 <- -R1("+str(R1)+")")
- I=I+1
- continue
- elif(p[I]==16):
- if(R1==R2):
- print("16: comparison(R1==R2) R1 <- 0")
- R1=0
- elif(R1>R2):
- print("16: comparison(R1>R2) R1 <- 1")
- R1=1
- else:
- print("16: comparison(R1<R2) R1 <- -1")
- R1=-1
- I=I+1
- continue
- print("R1 = "+str(R1))
- print("R2 = "+str(R2))
- print("I = "+str(I))
- print(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement