flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
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
match for addition 3 or more components
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+temp2argument
\{
        xor eaxeax
        xor ebxebx
        mov ax, [temp1
        mov bx, [temp2]
        add albl      
        daa 
        adc ah0h 
        ror ax8 
        ror bx8  
        add albl 
        daa 
        jnc mm 
        mov [MCR], 01h
        mm
        rol ax8       
        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: 14854
Location: Lost in translation
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.