×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library

AE74 RIGHT$(

Submitted by Steve Fewell

Description:

On entry carry flag is set if the RIGHT$ function was called (&AE74); otherwise, if carry is clear then we were entered
from the LEFT$ function (&AE73).
Store the entry status (carry flag) to the 6502 processor stack.
Call routine &9D3B to evaluate the expression at BASIC text pointer B and issue a 'Type mismatch' error if a String
value was not returned.
If the next non-space character (stored in X) is not a comma then issue 'Missing ,' error; otherwise, increment BASIC text
pointer B offset to skip past the comma value.

Push the SWA value to the BASIC Stack, get the Integer result of the expression at BASIC Text pointer B ('Type mismatch'
error if value is not numeric) and check for a closing ')' character ('Missing )' error if closing parenthesis not found.

Retrieve the String value (SWA) from the BASIC Stack.
Retrieve the carry flag routine entry setting from the 6502 processor stack.

If carry is not set (LEFT$) then:
* If the Integer value (&2A) is greater than or equal to the length of the String value in the SWA (&36) then exit
   with A = 0 (as the result is a String value).
* Otherwise, Set the SWA String length (&36) to the Integer value (to reduce the SWA length to the width specified
   and exit with A = 0 (as the result is a String value).
If carry is set (RIGHT$) then:
* Subtract the Integer value (&2A) from the SWA length (&36) [Note that carry flag is automatically set before
   subtraction].
* If the subtraction underflowed (the Integer value is greater than of equal to the SWA length) then exit with A = 0
   (as the result is a String value).
* Set X to the result (the first character of the result value).
* Set the SWA length (&36) to the Integer value specified (&2A).
* If the new SWA length is 0 then exit.
* Set Y = 0 and keep copying the character at SWA location X to SWA location Y and then incrementing Y and X, and
   decrementing &2A until &2A is 0 (the required number of characters has been copied).
* Exit with A = 0 (as the result is a String value located in the SWA).


Disassembly for the RIGHT$( routine

AE74   008 08 PHP
AE75 ; 032 059 157 20 3B 9D JSR &9D3B Evaluate expression at BASIC Text pointer B
AE78 E 208 069 D0 45 BNE 69 --> &AEBF [JMP &9092 Type mismatch error]
AE7A , 224 044 E0 2C CPX#&2C
AE7C D 208 068 D0 44 BNE 68 --> &AEC2 [JMP &8EF6 'Missing ,' error]
AE7E   230 027 E6 1B INC &1B
AE80   032 164 150 20 A4 96 JSR &96A4 Push SWA to stack, get Integer result of expression & check for closing ')'
AE83   032 210 188 20 D2 BC JSR &BCD2 Pop String (SWA) from the stack
AE86 ( 040 28 PLP
AE87   176 011 B0 0B BCS 11 --> &AE94 Calculate RIGHT$
AE89 * 165 042 A5 2A LDA &2A
AE8B 6 197 054 C5 36 CMP &36
AE8D   176 002 B0 02 BCS 2 --> &AE91
AE8F 6 133 054 85 36 STA &36
AE91   169 000 A9 00 LDA#&00
AE93 ` 096 60 RTS
AE94 6 165 054 A5 36 LDA &36
AE96 * 229 042 E5 2A SBC &2A
AE98   144 247 90 F7 BCC -9 --> &AE91
AE9A   240 247 F0 F7 BEQ -9 --> &AE93
AE9C   170 AA TAX
AE9D * 165 042 A5 2A LDA &2A
AE9F 6 133 054 85 36 STA &36
AEA1   240 240 F0 F0 BEQ -16 --> &AE93
AEA3   160 000 A0 00 LDY#&00
AEA5   189 000 006 BD 00 06 LDA &0600,X
AEA8   153 000 006 99 00 06 STA &0600,Y
AEAB   232 E8 INX
AEAC   200 C8 INY
AEAD * 198 042 C6 2A DEC &2A
AEAF   208 244 D0 F4 BNE -12 --> &AEA5
AEB1   128 222 80 DE BRA -34 --> &AE91

Disassembly for the Push SWA to stack, get Integer result of expression & check for closing ')' routine

96A4 Q 032 081 188 20 51 BC JSR &BC51 Push SWA to Stack
96A7   ... Extract Integer result of expression & check for ')' ...

 


 Back to 8BS
Or