How Jump instruction is executed based on value of Out- The Alu Output

余生长醉 提交于 2019-12-02 06:48:54

问题


Figure from The Elements of Computer System (Nand2Tetris)

Have a look at the scenario where

 j1 = 1 (out < 0 )
 j2 = 0 (out = 0 )
 j3 = 1 (out > 0 )

How this scenario is possible as out < 0 is true as well as out > 0 but out = 0 is false. How out can have both positive and negative values at the same time?

In other words when JNE instruction is going to execute although it theoretically seems possible to me but practically its not?


回答1:


If out < 0, the jump is executed if j1 = 1.

If out = 0, the jump is executed if j2 = 1.

If out > 0, the jump is executed if j3 = 1.

Hopefully now you can understand the table better. In particular, JNE is executed if out is non-zero, and is skipped if out is zero.




回答2:


The mnemonic makes sense if those are match-any conditions, not match-all. i.e. jump if the difference is greater or less than zero, but not if it is zero.

Specifically, sub x, y / jne target works the usual way: it jumps if x and y were equal before the subtraction. (So the subtraction result is zero). This is what the if(out!=0) jump in the Effect column is talking about.

IDK the syntax for Nand2Tetris, but hopefully the idea is clear.


BTW, on x86 JNZ is a synonym for JNE, so you can use whichever one is semantically relevant. JNE only really makes sense after something that works as a compare, even though most operations set ZF based on whether the result is zero or not.



来源:https://stackoverflow.com/questions/38621804/how-jump-instruction-is-executed-based-on-value-of-out-the-alu-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!