If Statements
if statements
Pseudocode:
if (ram[100]>50) {
ram[0]=1;
} else {
ram[0]=-1;
}
Assembler:
// D=ram[100]-50
@100
D=M
@50
D=D-A
// if ram[100]-50 <= 0 then goto ELSE
@ELSE
D;JLE
(THEN)
// begin of THEN
// ram[0] = 1
@0
M=1
@DONE
1;JMP
// end of THEN
// begin of ELSE
(ELSE)
// ram[0] = -1
@0
M=-1
// end of ELSE
// infinite loop at the end
(DONE)
@DONE
1;JMP