Extra SYMBOL functionality

hippy

Ex-Staff (retired)
Two useful features for SYMBOL would be -

1) The ability to have more than two operands on the right of the equals rather than needing a long list of temporary definitions to create a constant value from a number of others.

2) Shift Left and Shift Right operators.
 

hippy

Ex-Staff (retired)
Example.

I'm wanting to create a constant multiplier based on a constant scale value, which is a power of two ...<code><pre><font size=2 face='Courier'> SYMBOL scale = 3 ' 0 1 2 3 4 5 6 7
SYMBOL multiplier = 1 &lt;&lt; scale ' 1 2 4 8 16 32 64 128 </font></pre></code> The best I can come up with so far is what I have below. If anyone has any better ideas then I'm all ears. Cannot test at the moment because it shows up a buggette in the compilers.<code><pre><font size=2 face='Courier'> SYMBOL scale = 3
'
' Adjust scale_xa so they are all balanced about each
' possible value. The scale_xa will be zero when the
' value matches, non-zero if not.
'
SYMBOL scale_0a = scale - 0
SYMBOL scale_1a = scale - 1
SYMBOL scale_2a = scale - 2
SYMBOL scale_3a = scale - 3
SYMBOL scale_4a = scale - 4
SYMBOL scale_5a = scale - 5
SYMBOL scale_6a = scale - 6
SYMBOL scale_7a = scale - 7
'
' Make all non-zero values 1. Only the value which
' matched will have a value of zero.
'
SYMBOL scale_0b = scale_0a MAX 1
SYMBOL scale_1b = scale_1a MAX 1
SYMBOL scale_2b = scale_2a MAX 1
SYMBOL scale_3b = scale_3a MAX 1
SYMBOL scale_4b = scale_4a MAX 1
SYMBOL scale_5b = scale_5a MAX 1
SYMBOL scale_6b = scale_6a MAX 1
SYMBOL scale_7b = scale_7a MAX 1
'
' Invert so only the value which matched has a value
' of 1 and the rest have value zero.
'
SYMBOL scale_0c = scale_0b ^ 1
SYMBOL scale_1c = scale_1b ^ 1
SYMBOL scale_2c = scale_2b ^ 1
SYMBOL scale_3c = scale_3b ^ 1
SYMBOL scale_4c = scale_4b ^ 1
SYMBOL scale_5c = scale_5b ^ 1
SYMBOL scale_6c = scale_6b ^ 1
SYMBOL scale_7c = scale_7b ^ 1
'
' Set the multiplier for each possible bit. If scale_xc
' is set then a multiplier will be set otherwise a zero
' is set.
'
SYMBOL multiply_0a = scale_0c * 1
SYMBOL multiply_1a = scale_1c * 2
SYMBOL multiply_2a = scale_2c * 4
SYMBOL multiply_3a = scale_3c * 8
SYMBOL multiply_4a = scale_4c * 16
SYMBOL multiply_5a = scale_5c * 32
SYMBOL multiply_6a = scale_6c * 64
SYMBOL multiply_7a = scale_7c * 128
'
' Add all the possible multipliers together, of which
' only one will be set and the others will be zero.
'
SYMBOL multiply_0b = multiply_0a
SYMBOL multiply_1b = multiply_1a + mutiply_0b
SYMBOL multiply_2b = multiply_2a + mutiply_1b
SYMBOL multiply_3b = multiply_3a + mutiply_2b
SYMBOL multiply_4b = multiply_4a + mutiply_3b
SYMBOL multiply_5b = multiply_5a + mutiply_4b
SYMBOL multiply_6b = multiply_6a + mutiply_5b
SYMBOL multiply_7b = multiply_7a + mutiply_6b
'
' Get the final multiplier to use
'
SYMBOL multiply = multiply_7b
'
' Report the result back to the console to check it
' worked as expected.
'
PAUSE 2000
SERTXD (#scale,&quot; &quot;,#multiply,CR,LF) </font></pre></code>
 

kwal

New Member
So, one could have
symbol pi = 355/113
instead of
w0 = 355*100/113
symbol pi100 = w0

WRT 2nd point construct such as
#define &lt;&lt; as *
would be nice to have
 
Top