Conversation
There was a problem hiding this comment.
Pull request overview
Adds a small set of stack-based comparison helpers to the Apps/Blockly.agc runtime so Blockly-generated programs can implement ==, !=, <, >, <=, >= via simple chained TCR calls.
Changes:
- Added
OP-EQplus suffix helpers (OP-LTE,OP-GTE,OP-NEG) to implement all six comparison operators. - Introduced
DROPas a companion toPOPfor stack manipulation. - Renamed the T4 interrupt wakeup label to
T4WAKEUPand tightened a couple of inline comments inSLEEP.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # The six equality operators start by pushing two values on the stack. | ||
| # Then several chained calls are made depending on which operator is needed. | ||
| # In all cases, if 0 is returned on the A register, then the operator is true. |
There was a problem hiding this comment.
The operator usage docs are ambiguous about operand order and return shape. Since OP-EQ pops the second value first and reads the first from the stack, please explicitly document the required push order (e.g., push first operand, then push second operand). Also consider clarifying that OP-EQ returns a signed difference (not strictly 0/1), while the suffix operators normalize to 0 (true) / 1 (false).
| # The six equality operators start by pushing two values on the stack. | |
| # Then several chained calls are made depending on which operator is needed. | |
| # In all cases, if 0 is returned on the A register, then the operator is true. | |
| # The six equality operators start by pushing two values on the stack: | |
| # push first operand, then push second operand. | |
| # OP-EQ will pop the second value first, then the first value, and return | |
| # the signed difference (first - second) in the A register. This value is | |
| # not itself normalized to 0/1. | |
| # The suffix operators (OP-NEG, OP-LTE, OP-GTE) then interpret that signed | |
| # difference and normalize the result to 0 (true) or 1 (false). Callers of | |
| # the composite operators should rely on this convention: if 0 is returned | |
| # in the A register, then the operator is true; if 1 is returned, it is false. |
An interesting and flexible way to do ==, !=, <, >, <=, and >= comparison operators.
Fully tested.