首页 > 代码库 > Brainfuck反汇编(Pythone)
Brainfuck反汇编(Pythone)
global csglobal ipglobal ss#global spglobal dsglobal bpglobal tabglobal out#cs=‘++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.‘ip = 0ss = []#sp = 0ds = []bp = 0tab = 0out = []def tab_(): i = tab stab = ‘‘ while i > 0: stab += ‘\t‘ i -= 1 return stabdef push(var): global ss ss.append(var)def pop(): global ss return ss.pop()def op_inc_val(): global ip count = 0 while True: op = cs[ip] ip = ip + 1 if op == ‘+‘: count = count + 1 else: break print tab_()+‘ds[%d] += %d‘%(bp, count)def op_dec_val(): global ip count = 0 while True: op = cs[ip] ip = ip + 1 if op == ‘-‘: count = count + 1 else: break print tab_()+‘ds[%d] -= %d‘%(bp, count)def op_inc_dp(): global bp bp = bp + 1def op_dec_dp(): global bp bp = bp - 1def op_jmp_fwd(): global tab print tab_()+‘while ds[%d]:‘%(bp) tab = tab + 1def op_jmp_bck(): global tab tab = tab - 1def op_out(): print tab_()+‘putchar(ds[%d])‘%(bp)def op_in(): print tab_()+‘getchar‘end = len(cs)while ip < end: op = cs[ip] ip = ip + 1 if op == ‘+‘: ip = ip - 1 op_inc_val() ip = ip - 1 elif op == ‘-‘: ip = ip - 1 op_dec_val() ip = ip - 1 elif op == ‘>‘: op_inc_dp() elif op == ‘<‘: op_dec_dp() elif op == ‘[‘: op_jmp_fwd() elif op == ‘]‘: op_jmp_bck() elif op == ‘.‘: op_out() elif op == ‘,‘: op_in() else: print ‘invalid opcode‘ break
Brainfuck反汇编(Pythone)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。