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

前端 未结 2 591
盖世英雄少女心
盖世英雄少女心 2021-01-23 07:25

Figure from The Elements of Computer System (Nand2Tetris)

Have a look at the scenario where

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


        
相关标签:
2条回答
  • 2021-01-23 07:53

    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.

    0 讨论(0)
  • 2021-01-23 08:09

    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.

    0 讨论(0)
提交回复
热议问题