flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Reverend 06 Feb 2007, 20:35
Get some converting routines (ie. text -> number). Save all the converted alphabetic variables somewhere and do the calculations step by step (you have the formula nicely put inside braces, so no problem).
Code: 1 = 150-A 2 = [1] * 2 3 = 40 - B 4 = [2] - [3] ... Code: ; 1 = 150-A mov eax, 150 sub eax, [A] ; 2 = [1] * 2 shl eax, 1 ; this equals eax = eax*2 ; 3 = 40 - B mov ecx, 40 sub ecx, [B] ; 4 = [2] - [3] sub eax, ecx ... |
|||
![]() |
|
kasake36 07 Feb 2007, 07:14
That's what i didn't want to do first, because i still believe it ends up in a mess (at least for me) but anyways, i'll do it this way. Thanks.
|
|||
![]() |
|
Reverend 07 Feb 2007, 11:55
If you don't want mess than just put this code in a procedure like this:
Code: proc formula A, B, K, O, X ... endp Code: ... stdcall formula, [A], [B], [K], [O], [X] ... But generally my opinion is that sooner or later you will have to get used to the "messy" code if you choose assembly. |
|||
![]() |
|
kasake36 07 Feb 2007, 13:27
With messy i meant the part of the program that divides the formula into simple calculations. I wanted to do something similar using C several years ago and i failed, but i do not know the reason for the failure at the moment. The only thing i have in mind is that the program was a mess. On the other side i'm a bit more experienced nowadays.
|
|||
![]() |
|
PopeInnocent 08 Feb 2007, 23:09
If I understand you correctly, it sounds like you want to read in a formula and calculate it. An LR(1) recursive-descent parser would probably work perfectly for you, and it would distinctly non-messy.
![]() |
|||
![]() |
|
kasake36 09 Feb 2007, 08:52
Oh my gosh....
![]() Thanks for the keywords! I'll have to spent some thought on that! |
|||
![]() |
|
kandamun 10 Feb 2007, 08:25
What about "Reverse Polish Notation"
![]() It is another way of doing this. |
|||
![]() |
|
kasake36 12 Feb 2007, 07:41
RPN seems a bit more comfortable than the LR(1) stuff (for the calculation with assembler) and i believe the customer would appreciate to write down the formulas in that syntax - it looks more pro and he can brag around in front of his nice secretaries
![]() |
|||
![]() |
|
donkey7 12 Feb 2007, 11:24
you don't need the customer to write in rpn syntax. instead you can use algorithm to convert from classic notation to rpn.
Code: repeat get_next_element; if element_is_a_value then write_it_to_output else if element_is_a_operator then while priority_of_first_operator_on_stack >= priority_of_element do move_first_operator_from_stack_to_output push_element_on_stack if element_equal_( then push_it_on_stack if element_equal_) then while first_element_on_stack_is_a_operator do ; ( remove_elements_util_( ) move_it_from_stack_to_output delete_(_from_beginnig_of_stack end if until end_of_data while stack_non_empty do move_operator_from_stack_to_output then you apply algorithm to evaluate it: Code: repeat get_next_element if element_is_a_value then push_it_onto_stack else pop_needed_values_from_stack do_operation push_the_result_onto_stack end if until end_of_data because the evaluation algorithm is stack based you can easily implement it for 80387 fpu (which is also stack based). you can also look at: http://en.wikipedia.org/wiki/Reverse_Polish_notation http://en.wikipedia.org/wiki/Shunting_yard_algorithm _________________ Keep coding! |
|||
![]() |
|
kasake36 12 Feb 2007, 11:35
That is very helpful, thanks!
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.