user3764371
user3764371

Reputation: 25

NAND2Tetris Hack

How do I skip 2 commands in hack if I don't know the exact line no. of which the code I want to jump to.

eg.

30.@33
31.D;JGT
32.M=M-1
33.M=M+1

But I don't know the line no. I am currently at(30), I just want to skip the next line of code(Go 2 steps forward instead of 1) if D;JGT is fulfilled.

Upvotes: 2

Views: 1519

Answers (1)

Trebor the MadOverlord
Trebor the MadOverlord

Reputation: 1289

Use a symbolic label:

    @your_label
    D;JGT
    M=M+1
    M=M+1

(your_label)

The assembler will figure out the address of your_label and insert it into the @-op. You don't need to keep track of what instruction address you are at.

Upvotes: 1

Related Questions