×   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

ABF5 SGN

Submitted by Steve Fewell

Description:

Call routine &AD36 to obtain the value of the expression after the SGN keyword.
If the result is a String value then issue 'Type mismatch' error.

If the result is a Floating-Point value then obtain the sign (SGN) as follows:
* Call &A3F2 to obtain the sign of the FWA value.
* If &A3F2 returns 0 then exit with the IWA set to 0 (FALSE) and A = #&40 (result is Integer).
* If &A3F2 returns a positive value (1) then exit with the IWA set to 1 and A = #&40 (result is Integer).
* If &A3F2 returns a negative value (-1) then exit with the IWA set to -1 (TRUE) and A = #&40 (result is
   Integer).
Otherwise the result is an Integer so obtain the sign (SGN) as follows:
* If IWA (bytes &2D-&2A) is zero then exit with the IWA unchanged and A = #&40 (result is Integer).
* If byte &2D (the IWA MSB) is negative (>=#&80) then exit with the IWA set to -1 (TRUE) and A = #&40
   (result is Integer).
* Otherwise, the IWA is positive, so exit with the IWA set to 1 and A = #&40 (result is Integer).


Disassembly for the SGN routine

ABEC   032 242 163 20 F2 A3 JSR &A3F2 Obtain Sign of the FWA Floating-Point value
ABEF   240 247 F0 F7 BEQ -9 --> &ABE8 Set IWA to FALSE (0)
ABF1   016 023 10 17 BPL 23 --> &AC0A
ABF3   128 230 80 E6 BRA -26 --> &ABDB Set IWA to TRUE (-1)
ABF5 6 032 054 173 20 36 AD JSR &AD36 Get value / result of expression (if bracketed)
ABF8   240 210 F0 D2 BEQ -46 --> &ABCC [JMP &9092 - Type mismatch error]
ABFA 0 048 240 30 F0 BMI -16 --> &ABEC
ABFC - 165 045 A5 2D LDA &2D
ABFE , 005 044 05 2C ORA &2C
AC00 + 005 043 05 2B ORA &2B
AC02 * 005 042 05 2A ORA &2A
AC04   240 223 F0 DF BEQ -33 --> &ABE5 [LDA #&40 : RTS]
AC06 - 165 045 A5 2D LDA &2D
AC08 0 048 209 30 D1 BMI -47 --> &ABDB Set IWA to TRUE (-1)
AC0A   169 001 A9 01 LDA#&01
AC0C   128 177 80 B1 BRA -79 --> &ABBF [JMP &AE18 Set IWA to the 8-bit value (in A)]

 


 Back to 8BS
Or