×   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

B32B Set Numeric Variable

Submitted by Steve Fewell

Routine:setnumericvar
Name: Store numerical value in the specified variable
Starting Address: &B32B
Entry criteria: Either the IWA or the FWA
contains the value & the variable address and type details are stored on the Stack (3 bytes).
Exit: The specified variable has been set to the numerical value from the IWA or FWA.

Description:

(if called from &B328 then evaluate the expression value (this will be the value that we
will set the variable to).

Temporarily pop the return address from the Stack (that is the address to return to after the end
of subroutine RTS statement!).
Pop the variable return type from the stack and store this value in &39.
Pop the Variable value address from the stack and store this address in &37-&38.
Push the return address back onto the stack.
If called from &B338, then the stack manipulation is skipped, as the variable address details and variable type
information has already been set (and ae not located on the stack).

If the variable return type is 5 then the variable requires a Floating-Point value, so do the following:
* If the value type (for the current value in the IWA/FWA, in &27) is zero then we have
   a string value, so issue a Type Mismatch error, as we cannot assign a String to our variable.
* If the value type is positive then we have an Integer value that we need to assign to a Floating-Point
   variable, so convert the Integer to a Floating-Point value.
* Store the FWA to the variable's Memory address (&B369) to output the FWA value
   to the address pointed to by &37-&38, and then exit.
   Note: the FWA will be stored in it's 5-byte packed format, as follows:
      Byte 1: The FWA Exponent
      Byte 2: The FWA Sign Bit (MSB) followed by the lower 7-bits of Mantissa Byte 1
         (as the FWA value is normalised, we don't need to store the TOP bit of
          the FWA Mantissa byte 1 value (as it is always 1), so the FWA sign
          value replaces this bit).
      Byte 3: The FWA Mantissa Byte 2
      Byte 4: The FWA Mantissa Byte 3
      Byte 5: The FWA Mantissa Byte 4

Otherwise, the variable return type is Integer, so do the following:
* If the value type (for the current value in the IWA/FWA, in &27) is zero then we have
   a string value, so issue a Type Mismatch error, as we cannot assign a String to our variable.
* If the value type is negative then we have a Floating-Point value that we need to assign to an Integer
   variable, so convert the Floating-Point value to an Integer.
* Continue to the Store IWA to Memory address routine (&B347) to output the IWA value
   to the address pointed to by &37-&38, and exit.
   Note The Store IWA to address routine will check the variable type (&39)
   to see if we need to store a 1-byte or 4-byte value, as if the variable is a direct
   memory access (e.g. ?&70 = 1), then we must only store 1-byte; all other Integer values
   are 4-byte variables.


Disassembly for the Set Numerical variable routine

B325 L 076 146 144 4C 92 90 JMP &9092 Type mismatch error
B328 ; 032 059 157 20 3B 9D JSR &9D3B Get result of expression
B32B z 122 7A PLY
B32C   250 FA PLX
B32D h 104 68 PLA
B32E 9 133 057 85 39 STA &39
B330 h 104 68 PLA
B331 8 133 056 85 38 STA &38
B333 h 104 68 PLA
B334 7 133 055 85 37 STA &37
B336   218 DA PHX
B337 Z 090 5A PHY
B338 9 165 057 A5 39 LDA &39
B33A   201 005 C9 05 CMP#&05
B33C " 240 034 F0 22 BEQ 34 --> &B360 Set Float variable
B33E ' 165 039 A5 27 LDA &27
B340   240 227 F0 E3 BEQ -29 --> &B325 issue 'Type mismatch' error
B342   016 003 10 03 BPL 3 --> &B347 Store IWA to address
B344   032 195 150 20 C3 96 JSR &96C3 Convert Float to Integer
B347 ... Store IWA to address [iout]

Set Float variable routine
B360 ' 165 039 A5 27 LDA &27
B362   240 193 F0 C1 BEQ -63 --> &B325 Issue 'Type mismatch' error
B364 0 048 003 30 03 BMI 3 --> &B369
B366   032 133 129 20 85 81 JSR &8185 Convert Integer to Floating-Point
B369 0 165 048 A5 30 LDA &30
B36B 7 146 055 92 37 STA (&37)
B36D   160 001 A0 01 LDY#&01
B36F . 165 046 A5 2E LDA &2E
B371 E1 069 049 45 31 EOR &31
B373 ) 041 128 29 80 AND#&80
B375 E1 069 049 45 31 EOR &31
B377 7 145 055 91 37 STA (&37),Y
B379   200 C8 INY
B37A 2 165 050 A5 32 LDA &32
B37C 7 145 055 91 37 STA (&37),Y
B37E   200 C8 INY
B37F 3 165 051 A5 33 LDA &33
B381 7 145 055 91 37 STA (&37),Y
B383   200 C8 INY
B384 4 165 052 A5 34 LDA &34
B386 7 145 055 91 37 STA (&37),Y
B388 ` 096 60 RTS

 


 Back to 8BS
Or