Prev: 10646 Up: Map Next: 10929
10834: THE 'SLICING' SUBROUTINE
Used by the routines at S_LETTER and STK_VAR.
The present string can be sliced using this subroutine. The subroutine is entered with the parameters of the string being present on the top of the calculator stack and in the registers A, B, C, D and E. Initially the SYNTAX/RUN flag is tested and the parameters of the string are fetched only if a line is being executed.
Input
BC Length of the string
DE Address of the first character in the string
SLICING 10834 CALL SYNTAX_Z Check the flag.
10837 CALL NZ,STK_FETCH Take the parameters off the stack in 'run-time'.
The possibility of the 'slice' being '()' has to be considered.
10840 RST 32 Get the next character.
10841 CP ")" Is it a ')'?
10843 JR Z,SL_STORE Jump forward if it is so.
Before proceeding the registers are manipulated as follows:
10845 PUSH DE The 'start' goes on the machine stack.
10846 XOR A The A register is cleared and saved.
10847 PUSH AF
10848 PUSH BC The 'length' is saved briefly.
10849 LD DE,1 Presume that the 'slice' is to begin with the first character.
10852 RST 24 Get the first character.
10853 POP HL Pass the 'length' to HL.
The first parameter of the 'slice' is now evaluated.
10854 CP 204 Is the present character a 'TO'?
10856 JR Z,SL_SECOND The first parameter, by default, will be '1' if the jump is taken.
10858 POP AF At this stage A is zero.
10859 CALL INT_EXP2 BC is made to hold the first parameter. A will hold 255 if there has been an 'out of range' error.
10862 PUSH AF Save the value anyway.
10863 LD D,B Transfer the first parameter to DE.
10864 LD E,C
10865 PUSH HL Save the 'length' briefly.
10866 RST 24 Get the present character.
10867 POP HL Restore the 'length'.
10868 CP 204 Is the present character a 'TO'?
10870 JR Z,SL_SECOND Jump forward to consider the second parameter if it is so; otherwise show that there is a closing bracket.
10872 CP ")"
This entry point is used by the routine at STK_VAR.
SL_RPT_C 10874 JP NZ,REPORT_C
At this point a 'slice' of a single character has been identified. e.g. A$(4).
10877 LD H,D The last character of the 'slice' is also the first character.
10878 LD L,E
10879 JR SL_DEFINE Jump forward.
The second parameter of a 'slice' is now evaluated.
SL_SECOND 10881 PUSH HL Save the 'length' briefly.
10882 RST 32 Get the next character.
10883 POP HL Restore the 'length'.
10884 CP ")" Is the present character a ')'?
10886 JR Z,SL_DEFINE Jump if there is not a second parameter.
10888 POP AF If the first parameter was in range A will hold zero, otherwise 255.
10889 CALL INT_EXP2 Make BC hold the second parameter.
10892 PUSH AF Save the 'error register'.
10893 RST 24 Get the present character.
10894 LD H,B Pass the result obtained from INT_EXP2 to the HL register pair.
10895 LD L,C
10896 CP ")" Check that there is a closing bracket now.
10898 JR NZ,SL_RPT_C
The 'new' parameters are now defined.
SL_DEFINE 10900 POP AF Fetch the 'error register'.
10901 EX (SP),HL The second parameter goes on the stack and the 'start' goes to HL.
10902 ADD HL,DE The first parameter is added to the 'start'.
10903 DEC HL Go back a location to get it correct.
10904 EX (SP),HL The 'new start' goes on the stack and the second parameter goes to HL.
10905 AND A Subtract the first parameters from the second to find the length of the 'slice'.
10906 SBC HL,DE
10908 LD BC,0 Initialise the 'new length'.
10911 JR C,SL_OVER A negative 'slice' is a 'null string' rather than an error condition.
10913 INC HL Allow for the inclusive byte.
10914 AND A Only now test the 'error register'.
10915 JP M,REPORT_3 Jump if either parameter was out of range for the string.
10918 LD B,H Transfer the 'new length' to BC.
10919 LD C,L
SL_OVER 10920 POP DE Get the 'new start'.
10921 RES 6,(IY+1) Ensure that a string is still indicated (reset bit 6 of FLAGS).
SL_STORE 10925 CALL SYNTAX_Z Return at this point if checking syntax; otherwise continue into STK_ST_0.
10928 RET Z
Prev: 10646 Up: Map Next: 10929