flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > [Question] A macro that calculates
Author
l4m2

Joined: 15 Jan 2015
Posts: 667
l4m2 13 Mar 2016, 05:41
Code:
```macro calcu expr {
match a p b, expr \{
mov eax, a
if (p) eq (+)
else if (p) eq (-)
sub eax, b
else if (p) eq (*)
mul b
else if (p) eq (/)
div b
else if (p) eq (%)
div b
mov edx, eax
end if
\}
}       ```
A simple macro calculating a op b and put the result into eax.
1) for equations like ecx*edx+ebx, an improved macro is required.
2) for (4+5)*eax, is it possible that 4+5 is calculated when compiling?
13 Mar 2016, 05:41
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 19284
revolution 13 Mar 2016, 06:52
l4m2 wrote:
2) for (4+5)*eax, is it possible that 4+5 is calculated when compiling?
Yes.
13 Mar 2016, 06:52
l4m2

Joined: 15 Jan 2015
Posts: 667
l4m2 13 Mar 2016, 13:27
"irps x, 2*(3+5)" splits it into 2, *, (, 3, +, 5, ). Therefore blanket matching needed to be done in the code
13 Mar 2016, 13:27
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 19284
revolution 13 Mar 2016, 13:41
You can use "match" for more sophisticated expressions.
13 Mar 2016, 13:41
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum