flat assembler
Message board for the users of flat assembler.

Index > Main > sequential mathematics assembly:

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
to compute formulas there are many possibilities.

what can be made with the accumulator concept? eax register holds the accumalator, instructions are processed by default on eax
Code:
db 'V0=(V1+V2)* V3/V4'
    

and after this stage, do a sort of serialisation:
Code:
formula: dd V0,'=','(',V1,'+',V2,')','*',V3,'/',V4,0
V1, dd ?
V2 dd ?
V3 dd ?
V4 dd ?
    

and then execute it!
exemple:
Code:
mov [acc],v1
mov [op],v2
call add
mov [op],v3
call mul
mov [op],v4
call div
mov v0,[acc]
    


it is just an idea, not a working concept.
Post 19 Oct 2009, 12:42
View user's profile Send private message Visit poster's website Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
edfed this is silly. You want a "HLL compiler/interpreter" inside of your ASM program? What would be utility / benefit of this?
Post 19 Oct 2009, 16:41
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
why the hell use parantheses? Use Reverse Polish Notation and get rid of them, at the very least...
Post 19 Oct 2009, 17:06
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
ok, for polish notation
but after, i want to do a math interpreter
like a command line
hit enter, it gives the result
like in a TI82

and use it as a feature for my shell.
i stil have an interpreter for my own command line functions (paused), and an interpreter for rudimental html, i just want to add an interpret for math formulas.
something callable easy.

Code:
dd f.maths,result,formula
formula db 'A+B'
result dd ?
    

math must do the interpretation of variables transparentlly.

for example, if A is not assigned, it gets the value of "null" and all operation with will be ignored.
if A is assigned, all operations with it will be made.
Post 19 Oct 2009, 17:35
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
SIMD is the wave of the future.
Ride the wave Smile
Post 19 Oct 2009, 19:45
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
Polish notation is more efficient, but parenthesis are easier to use.

@edfed - you need to...

1 - break the formula down into a TREE structure where every leaf node is a variable or constant and every junction is an operation.
Quote:

(A + B) * (C - 99)
*
/ \
+ -
/ \ / \
A B C 99


2 - Create a function for each binary operation (two parameters), don't forget unary operations (one parameter) if you want to support them like NOT, NEG, SQRT.

3 - Iterate through your tree in ?breadth first? perform the necessary operation and replace the leaf node(s) and operation node with the operation function's return value.

4 - Once you have the basic system working you can optimize it if you'd like. Using multiple threads to evaluate operations that are on the same TREE LEVEL (i.e. they are not dependent on eachother). Trying to optimize the TREE by simplifying the formula etc etc.
Post 19 Oct 2009, 20:03
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.