[Edit: fix return FALSE for mixed signs with x > y.]
tungsten wrote
Also to implement, the Jack to VM compiler would translate a '>' or '<' symbol it encounters into an appropriate function call (such as the psuedocode).
The Jack Compiler does not have anything to do with this. It continues to generate only a
gt or
lt VM command for comparisons.
This is all about the ASM code that is generated by the VM Translator for the
gt and
lt commands.
I find that pseudocode that includes subroutines is not so helpful when designing ASM sequences for a language that does not (easily) support nested subroutine calling at the machine level.
The code that is generated for correct comparisons will be significantly longer than the simple subtraction compare, so it should be written as assembly language routines the same way that
call/
return VM Commands are handled.
As such, your original pseudocode can be rewritten using only if/else and comparisons against 0 that the ASM supports, and it will be much more helpful:
// x < y code
if x < 0
if y >= 0
// signs don't match, x < y
return TRUE
else
// x is >= 0
if y < 0
// signs don't match, x > y
return FALSE
// signs match; x - y won't overflow
if x - y < 0
return TRUE
else
return FALSE
--Mark