Routines |
Prev: 13613 | Up: Map | Next: 13724 |
The address of this routine is found in the table of addresses. It is called indirectly via fp_calc_2.
This subroutine is used to perform the twelve possible comparison operations (offsets 9 to 14 and 17 to 22: '<=', '>=', '<>', '>', '<' and '=' for numbers and strings respectively). The single operation offset is present in the B register at the start of the subroutine.
|
||||||||||||
compare | 13627 | LD A,B | The single offset goes to the A register. | |||||||||
13628 | SUB 8 | The range is now 1 to 6 and 9 to 14. | ||||||||||
13630 | BIT 2,A | This range is changed to 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14. | ||||||||||
13632 | JR NZ,EX_OR_NOT | |||||||||||
13634 | DEC A | |||||||||||
EX_OR_NOT | 13635 | RRCA | Then reduced to 0 to 7 with carry set for 'greater than or equal to' and 'less than'; the operations with carry set are then treated as their complementary operation once their values have been exchanged. | |||||||||
13636 | JR NC,NU_OR_STR | |||||||||||
13638 | PUSH AF | |||||||||||
13639 | PUSH HL | |||||||||||
13640 | CALL exchange | |||||||||||
13643 | POP DE | |||||||||||
13644 | EX DE,HL | |||||||||||
13645 | POP AF | |||||||||||
NU_OR_STR | 13646 | BIT 2,A | The numerical comparisons are now separated from the string comparisons by testing bit 2. | |||||||||
13648 | JR NZ,STRINGS | |||||||||||
13650 | RRCA | The numerical operations now have the range 0 to 1 with carry set for 'equal' and 'not equal'. | ||||||||||
13651 | PUSH AF | Save the offset. | ||||||||||
13652 | CALL subtract | The numbers are subtracted for the final tests. | ||||||||||
13655 | JR END_TESTS | |||||||||||
STRINGS | 13657 | RRCA | The string comparisons now have the range 2 to 3 with carry set for 'equal' and 'not equal'. | |||||||||
13658 | PUSH AF | Save the offset. | ||||||||||
13659 | CALL STK_FETCH | The lengths and starting addresses of the strings are fetched from the calculator stack. | ||||||||||
13662 | PUSH DE | |||||||||||
13663 | PUSH BC | |||||||||||
13664 | CALL STK_FETCH | |||||||||||
13667 | POP HL | The length of the second string. | ||||||||||
BYTE_COMP | 13668 | LD A,H | ||||||||||
13669 | OR L | |||||||||||
13670 | EX (SP),HL | |||||||||||
13671 | LD A,B | |||||||||||
13672 | JR NZ,SEC_PLUS | Jump unless the second string is null. | ||||||||||
13674 | OR C | |||||||||||
SECND_LOW | 13675 | POP BC | Here the second string is either null or less than the first. | |||||||||
13676 | JR Z,BOTH_NULL | |||||||||||
13678 | POP AF | |||||||||||
13679 | CCF | The carry is complemented to give the correct test results. | ||||||||||
13680 | JR STR_TEST | |||||||||||
BOTH_NULL | 13682 | POP AF | Here the carry is used as it stands. | |||||||||
13683 | JR STR_TEST | |||||||||||
SEC_PLUS | 13685 | OR C | ||||||||||
13686 | JR Z,FRST_LESS | The first string is now null, the second not. | ||||||||||
13688 | LD A,(DE) | Neither string is null, so their next bytes are compared. | ||||||||||
13689 | SUB (HL) | |||||||||||
13690 | JR C,FRST_LESS | Jump if the first byte is less. | ||||||||||
13692 | JR NZ,SECND_LOW | Jump if the second byte is less. | ||||||||||
13694 | DEC BC | The bytes are equal; so the lengths are decremented and a jump is made to BYTE_COMP to compare the next bytes of the reduced strings. | ||||||||||
13695 | INC DE | |||||||||||
13696 | INC HL | |||||||||||
13697 | EX (SP),HL | |||||||||||
13698 | DEC HL | |||||||||||
13699 | JR BYTE_COMP | |||||||||||
FRST_LESS | 13701 | POP BC | ||||||||||
13702 | POP AF | |||||||||||
13703 | AND A | The carry is cleared here for the correct test results. | ||||||||||
STR_TEST | 13704 | PUSH AF | For the string tests, a zero is put on to the calculator stack. | |||||||||
13705 | RST 40 | |||||||||||
13706 | DEFB 160 | stk_zero | ||||||||||
13707 | DEFB 56 | end_calc | ||||||||||
END_TESTS | 13708 | POP AF | These three tests, called as needed, give the correct results for all twelve comparisons. The initial carry is set for 'not equal' and 'equal', and the final carry is set for 'greater than', 'less than' and 'equal'. | |||||||||
13709 | PUSH AF | |||||||||||
13710 | CALL C,f_not | |||||||||||
13713 | POP AF | |||||||||||
13714 | PUSH AF | |||||||||||
13715 | CALL NC,greater_0 | |||||||||||
13718 | POP AF | |||||||||||
13719 | RRCA | |||||||||||
13720 | CALL NC,f_not | |||||||||||
13723 | RET | Finished. |
Prev: 13613 | Up: Map | Next: 13724 |