flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > match for addition 3 or more components

Author
Thread Post new topic Reply to topic
adele



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?
Thank you in advance
Code:
 macro sum argument
{ 
match answer==temp1+temp2, argument
\{
        xor eax, eax
        xor ebx, ebx
        mov ax, [temp1] 
        mov bx, [temp2]
        add al, bl      
        daa 
        adc ah, 0h 
        ror ax, 8 
        ror bx, 8  
        add al, bl 
        daa 
        jnc mm 
        mov [MCR], 01h
        mm: 
        rol ax, 8       
        mov [answer],ax  
\}      
}

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

        sum S=C+D

    
Post 09 Jun 2017, 07:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16098
Location: Squiddler's Patch
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
}    
Post 09 Jun 2017, 08:39
View user's profile Send private message Visit poster's website Reply with quote
adele



Joined: 09 Jun 2017
Posts: 2
Yeah, I've thought about irps but I need to keep syntax
But thank you for help
Post 09 Jun 2017, 09:11
View user's profile Send private message 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-2018, Tomasz Grysztar.

Powered by rwasa.