Conditional Statements |
---|
One of the most useful features of the NESHLA language is the ability to use conditional statements. They simplify and speed up coding, greatly enhance code readability, and eleviate the need for labels, creating structured code.
The majority of conditional branches in assembly language tend to be straight forward jumps calling for useless labels. The labels names are irrelivant, and cause the code to loose structure and become tedious. However, NESHLA supports if, else, while, do while, forever and switch/case expressions! Written in as "while(no carry) {" and such, they do not impeade the assembly language in any form, or make the code any less efficient than manual branch opcodes+labels.
The keywords near and far can be used as well. The 6502 only allows conditional branches to use 8 bit operands, so the jumps can only be within -128 and +127 of the opcode. Normally to overcome this, one would then need to create an extra label, use the opposite comparitive branch, and then write in an absolute jump. This adds to unnecessary tedious coding. NESHLA allows the use of conditional branches with 16 bit operands, and automatically writes the extra code!
Condition Statements |
---|
The Syntax |
---|
|
Conditions |
Opcodes |
---|---|
plus | BPL |
positive | BPL |
greater | BPL |
minus | BMI |
negative | BMI |
less | BMI |
overflow | BVC |
carry | BCS |
nonzero | BNE |
set | BNE |
true | BNE |
1 | BNE |
equal | BEQ |
zero | BEQ |
false | BEQ |
unset | BNE |
clear | BNE |
0 | BNE |
Examples |
---|
|
If Statements |
---|
Use an if statement to implement a conditional statement.
The Syntax |
---|
|
If conditional expression evaluates to be true, code block 1 is executed, otherwise it is skipped. If an else is appended to the if statement and conditional expression evaluates to be false, code block 2 is executed.
Example |
---|
|
While Statements |
---|
Use a while statement to implement a conditional loop.
The Syntax |
---|
|
With a while expression, code block is continually executed until conditional expression evaluates to be FALSE.
Example |
---|
|
Do While Statements |
---|
Use a do while statement to implement a conditional loop.
The Syntax |
---|
|
With a do while statement, code block is executed once. If conditional expression evaluates to be TRUE, code block 1 is executed again, and continually until conditional expression evaluates to be FALSE.
Example |
---|
|
Forever Statements |
---|
Use a forever statement to implement an infinite loop.
The Syntax |
---|
|
With a forever statement, code block is executed continually until a return keyword, jump opcode which jumps outside of the block is encountered, or the NES is reset.
It is also very useful in debugging. Upon an invalid game state, you can execute an empty forever loop to create a break point in the emulator.
Example |
---|
|
Switch/Case Statements |
---|
Use the switch statement to pass control to a case which matches the result of register. If no case satisfies the condition, the default case is executed.
The Syntax |
---|
|
Examples |
---|
|