我正在尝试使用 Jasmin 模仿 NOT 门的行为。行为如下:
- 从堆栈中弹出一个整数
- 如果整数为 0,则将 1 推回堆栈
- 否则将 0 推回堆栈
我已经尝试了两种不同的尝试,但无济于事。
尝试1:
...(other code1)
ifeq 3 ; if the top of stack is 0, jump 3 lines down to "i_const1"
i_const0 ; top of stack was not 0, so we push 0
goto 2 ; jump 2 lines down to first line of (other code2)
i_const1
...(other code2)
当然,上面的例子不起作用,因为ifeq <offset>
它接受了一个标签而不是一个硬编码的整数作为它的偏移量。是否有与 ifeq 类似的操作接受整数作为参数?
尝试2:
...
ifeq Zero ; top of stack is 0, so jump to Zero
i_const0 ; top of stack was 1 or greater, so we push 0
...
... (some code in between)
...
ifeq Zero ; top of stack is 0, so jump to Zero
i_const0 ; top of stack was 1 or greater, so we push 0
...
Zero:
i_const1 ; top of stack was 0, so push 1 to stack
goto <???> ; How do I know which "ifeq Zero" called this label?
问题在于我的代码中不止一个地方使用了 NOT 操作。我尝试将 ifeq 与标签一起使用,但完成后我如何知道使用 goto 返回哪一行?有没有办法动态确定哪个“ifeq Zero”实现了跳跃?
任何见解将不胜感激。