assemblymacrosmasmmasm32

Concatenate in macro assembler


I want use in my code something like that:

.data?
my_macro_var db MAX_PATH DUP (?)

.code

mov esi, offset my_macro_var 
my_macro esi, "hello and bye"

For that i create this macro but i get few errors that i cant resolve..

my_macro macro reg, characters  
 LOCAL v1,v2,v3
 LOCAL c1,c2,c3,c4,cTotal

 v1 TEXTEQU  %(@SizeStr(<characters>)) -2 ;; -2 is for the double quote
 v2 textequ %(v1/4) 
 v3 = 0 

 ;% echo @SubStr(<characters>, 2, 4)   

 repeat v2     
     c1 Substr <characters>,v3,1

     cTotal equ c1
     mov dword ptr [reg+v3], cTotal
     v3=v3+4
 endm

endm

I want this result..

mov dword ptr [esi+00d], 'lleh'
mov dword ptr [esi+04d], 'na o'
mov dword ptr [esi+08d], 'yb d'
mov dword ptr [esi+12d], 'e' 

This is the errors that i get:

Code.asm(14) : error A2090: positive value expected
MacroLoop(1): iteration 1: Macro Called From 
my_macro(16): Macro Called From
Code.asm(14): Main Line Code
Code.asm(14) : error A2006: undefined symbol : a
MacroLoop(4): iteration 1: Macro Called From 
my_macro(16): Macro Called From
Code.asm(14): Main Line Code
Code.asm(14) : error A2006: undefined symbol : l
MacroLoop(4): iteration 2: Macro Called From 
my_macro(16): Macro Called From
Code.asm(14): Main Line Code
Code.asm(14) : error A2006: undefined symbol : a
MacroLoop(4): iteration 3: Macro Called From 
my_macro(16): Macro Called From
Code.asm(14): Main Line Code

I think that my problem will be solved if i can use substr and concatenate 4 variable...


Solution

  • The first error is the caused by the fact that SUBSTR uses one based indexing and you're trying to use zero based indexing with it. The rest of the errors are the result of cTotal not having quote characters.

    So to fix the errors try this:

    my_macro macro reg, characters  
     LOCAL v1,v2,v3
     LOCAL c1,c2,c3,c4,cTotal
    
     v1 TEXTEQU  %(@SizeStr(<characters>)) -2 ;; -2 is for the double quote
     v2 textequ %(v1/4) 
     v3 = 0
    
     ;% echo @SubStr(<characters>, 2, 4)   
    
     repeat v2     
         c1 Substr <characters>, v3 + 1, 4
    
         cTotal CATSTR <'>, c1, <'>
         mov dword ptr [reg+v3], cTotal
         v3=v3+4
     endm
    
    endm