The + - = <> < <= > >= operators are all implemented using the following 23 bytes of code:
GTSub: ; Swap operands and fall through XCHG LTSub: DCX D LTESub: ; Swap operands and fall through XCHG GTESub: RST_NegateDE DAD D MOV A,H RAL DB 11h; LXi D opcode to swallow next byte EqualSub: RST_CompareHLDE ; returns Z iff HL=DE CMC DB 3eh ; MVI A opcode to swallow next byte NotEqualSub: RST_CompareHLDE; returns Z iff HL=DE LXI D,1 RNC DCX D RET AddSub: DB 3eh ; opcode for MVI A, to eat next byte SubSub: RST_NegateDE ;Add DE to HL and keep in DE DAD D XCHG RET
This uses a lot of code sharing, and saves space at the expense of speed. The order of the operator …Sub: labels corresponds to operator precedence, so if these are all in the same 256 byte page then the low order byte of the label address effectively encodes operator precedence.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.