Stack-based math (STAKMATH) for ASM8 updated

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Stack-based math (STAKMATH) for ASM8 updated

1,558 Views
tonyp
Senior Contributor II

(For some reason I cannot change the subject when replying to a previous thread, so I started a new one.)

 

I have updated the STAKMATH module for ASM8 to include an expression parser set of macros.  You need the latest ASM8 v8.80

 

This allows you to write an expression like the one below, and it will be converted to the appropriate macro calls.

For example: @Eval32 Ans=123*(N1+N2)/(N1-N2)-5

will result in the following sequence.

 

--------------------------------------------------

Expr: Ans=123*(N1+N2)/(N1-N2)-5

--------------------------------------------------

Load32 #5

Load32 N2

Load32 N1

Sub32

Load32 N2

Load32 N1

Add32

Load32 #123

Mul32

Div32

Sub32

Save32 Ans

 

You can use nested parentheses, spaces between operands/operators, and the assignment variable is optional.  If not used, the result will remain on top-of-stack.  Numeric constants are recognized automatically, while named constants must be given as #CONSTANT

You can also use SP-based variables (in #SPAUTO mode).


Hope you like it.  (If you find errors in parsing, please let me know.)

tonyp

Labels (1)
4 Replies

1,278 Views
tonyp
Senior Contributor II

The print macro(s) can now print any combination of strings, variables, and constants in a single statement (much like a HLL).  They can be found here.

0 Kudos

1,278 Views
tonyp
Senior Contributor II

The latest version has these enhancements.

* Optional atomic loading/saving of stack for use under a multitasker (for 16-bit or longer variables).

* Eval guesses the right size to use based on largest var/constant used.

* EvalN (eg., Eval32) will use a N-bit or higher library, but nothing smaller.  Previously, it would require exactly 32-bit.  This allows to optionally include only the highest-bit version needed in the whole application, and it will still automatically select the same or next higher bit version, in case multiple versions are included.

* ABS(), NEG(), and SQR() function simulations.

(ASM8 v9.31 is the latest, so you would need to update that, also!)

1,278 Views
tonyp
Senior Contributor II

Another update is available that uses the new features of the ASM8 v8.90 assembler (just released -- for details, see other message in that thread).  Use the same link as in my previous message above.

In short,

1. You can now use with different size variables, and the macros will auto-adjust the operand sizes to match.  (Note: Wrong or excessive use may inflate the produced code significantly.)

2. The expression parsing (Eval* macro) is done much more efficiently (and faster) by using the new MSET syntax extensions.

Hope you like them.  (If you find problems, please let me know.)

0 Kudos

1,278 Views
Monica
Senior Contributor III

Tony,

this is extremely helpful, thanks for contributing!

Best regards!

0 Kudos