flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > match for addition 3 or more components
Author

Joined: 09 Jun 2017
Posts: 2
Hi,
Here is a macro for addition four-digit numbers.
Obviously it works only for two items
But I need the code to work with forms like S=A+B+D, S=A+B+D+E, etc (with 2 or more components in temp2)
How can I change the code? Are there any ways to use recursion in macro or some other solvations?
Code:
``` macro sum argument
{
\{
xor eax, eax
xor ebx, ebx
mov ax, [temp1]
mov bx, [temp2]
daa
ror ax, 8
ror bx, 8
daa
jnc mm
mov [MCR], 01h
mm:
rol ax, 8
\}
}

;*******************************************************************************

sum S=C+D

```
09 Jun 2017, 07:21
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 18604
revolution
You can use irp and irps to iterate through arguments. Although with your syntax it might be tricky to separate the correct terms. You might want to consider changing the syntax, maybe like:

sum S,C,D

That would be easier to parse with a combination match and irp
Code:
```macro sum result,[values] {
common
irp v,values \{
mov eax,[v]
;...
\}
mov [result],eax
}    ```
Or you can use forward:
Code:
```macro sum result,[value] {
forward
mov eax,[value]
;...
common
mov [result],eax
}    ```
09 Jun 2017, 08:39

Joined: 09 Jun 2017
Posts: 2
Yeah, I've thought about irps but I need to keep syntax
But thank you for help
09 Jun 2017, 09:11
 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