8-Bit Software

The BBC and Master Computer Public Domain Library

Back to 8BS Or Back to Disassembly


Page Last Altered:

AB05 EVAL

Submitted by Steve Fewell

Description:

Call routine &AD36 to obtain the value of the expression after the EVAL keyword.
If the expression result is not 0 (i.e. the result is Numeric & not a String value) then issue 'Type mismatch' error.

Increment the SWA length and store a '<cr>' (carriage return) character at the end of the existing SWA value.
Push the SWA value to the BASIC stack.
Store the current BASIC Text pointer B values (&19, &1A & &1B) to the 6502 stack for temporary storage.

Set BASIC Text Pointer B (&19, &1A) and pointer (&37, &38) to the current address of the BASIC Stack pointer + 1,
the BASIC Stack pointer points to the next free location on the stack, so adding the 1 will point to the first character (length)
of the SWA value on the stack.

Set location &3B to #&FF (to set the middle of a statement mode).
Zero byte &3C (as a Line number is not expected).
Call the &8DB2 routine to tokenise the String value.

Zero byte &1B (BASIC Text pointer B offset), to reset BASIC Text Pointer B to the start of the tokenised String value.
Call routine &9D3B to evalualate the tokenised string and obtain the result of the String Expression to the SWA.
Call routine &BCE1 to restore the Stack space used by the String value.
Continue to the ASCII-Numeric routine (&AB3A) to retrieve the BASIC Text pointer B values from the 6502 stack and
convert the ASCII String result (SWA) to a numeric value (either a Floating-Point value or an Integer value) and exit.


Disassembly for the EVAL routine

AB05 6 032 054 173 20 36 AD JSR &AD36 Get Value (Keyword, variable, value, open bracket)
AB08 < 208 060 D0 3C BNE 60 --> &AB46 [JMP &9092 Type mismatch error]
AB0A 6 230 054 E6 36 INC &36
AB0C 6 164 054 A4 36 LDY &36
AB0E   169 013 A9 0D LDA#&0D
AB10   153 255 005 99 FF 05 STA &05FF,Y
AB13 Q 032 081 188 20 51 BC JSR &BC51 Push SWA to Stack
AB16   165 025 A5 19 LDA &19
AB18 H 072 48 PHA
AB19   165 026 A5 1A LDA &1A
AB1B H 072 48 PHA
AB1C   165 027 A5 1B LDA &1B
AB1E H 072 48 PHA
AB1F   164 004 A4 04 LDY &04
AB21   166 005 A6 05 LDX &05
AB23   200 C8 INY
AB24   132 025 84 19 STY &19
AB26 7 132 055 84 37 STY &37
AB28   208 001 D0 01 BNE 1 --> &AB2B
AB2A   232 E8 INX
AB2B   134 026 86 1A STX &1A
AB2D 8 134 056 86 38 STX &38
AB2F   032 031 142 20 1F 8E JSR &8E1F Set tokenise flags (&3B & &3C) and tokenise the String value
AB32 d 100 027 64 1B STZ &1B
AB34 ; 032 059 157 20 3B 9D JSR &9D3B Get the result of the expression at PTR B
AB37   032 225 188 20 E1 BC JSR &BCE1 Restore Stack Space used by String
AB3A ... ASCNUM (Convert ASCII String value to Numeric value) ...

 


 Back to 8BS
Or