我想在我的代码中使用类似的东西:
.data?
my_macro_var db MAX_PATH DUP (?)
.code
mov esi, offset my_macro_var
my_macro esi, "hello and bye"
为此,我创建了这个宏,但我遇到了一些无法解决的错误..
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
我想要这个结果..
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'
这是我得到的错误:
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
我认为如果我可以使用 substr 并连接 4 个变量,我的问题就会得到解决...
第一个错误是由于 SUBSTR 使用基于零的索引而您尝试使用基于零的索引这一事实引起的。其余错误是 cTotal 没有引号字符导致的。
因此要修复错误,请尝试以下操作:
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