轻松的编程学习
首页
题库
学习路径
在线商城
能力地图
下载应用
登录 / 注册
菜单
把一小段汇编跑起来
👁️ 1 人浏览
💬 0 人评论
❤️ 添加收藏
把三条指令交给解释器,打出三个寄存器最后的值。
提交你的答案
请登录后提交答案。
去登录
← 自己写:让解释器认识 add 和 sub
为什么要看编译器的输出 →
更多题目
让程序说出"你好"
让程序欢迎你
哪个命令能显示内容
哪里是指令,哪里是结果
让程序说出你的名字
这个程序会显示什么
代码编辑器
语言:
python3
c11
cpp17
Ctrl
+
Enter
运行
👩🏫 AI
▶ 运行代码
重置代码
打印代码
def run(src, regs=None, guard=200): R = {"eax": 0, "ebx": 0, "ecx": 0, "edx": 0} if regs: R.update(regs) labels = {} prog = [] for line in src.strip().splitlines(): line = line.strip() if not line: continue if line.endswith(":"): labels[line[:-1]] = len(prog) else: prog.append(line) pc = 0 flag = 0 stack = [] steps = 0 while pc < len(prog): steps = steps + 1 if steps > guard: break op, _, rest = prog[pc].partition(" ") args = [a.strip() for a in rest.split(",")] if rest else [] if op == "mov": R[args[0]] = R[args[1]] if args[1] in R else int(args[1]) elif op == "add": R[args[0]] = R[args[0]] + (R[args[1]] if args[1] in R else int(args[1])) elif op == "sub": R[args[0]] = R[args[0]] - (R[args[1]] if args[1] in R else int(args[1])) elif op == "cmp": flag = R[args[0]] - (R[args[1]] if args[1] in R else int(args[1])) elif op == "push": stack.append(R[args[0]]) elif op == "pop": R[args[0]] = stack.pop() elif op == "jmp": pc = labels[args[0]] continue elif op == "jne": if flag != 0: pc = labels[args[0]] continue elif op == "jle": if flag <= 0: pc = labels[args[0]] continue pc = pc + 1 return R, steps, stack SRC = """ mov eax, 9 mov ebx, 7 add eax, ebx mov ecx, eax """ # TODO: 把 SRC 交给 run,取出三个寄存器的值 # TODO: 按 eax/ebx/ecx 的顺序用 "/" 拼起来打印 print("")
本次输入:
输出:
👩🏫
AI
请登录后使用 AI 老师
×
登录后可获得解题思路、提示与错误分析。
去登录
关闭
🎉
恭喜你,回答正确!
系统判定:正确
我知道了
💬 题目评论
提交
全部评论
全部评论