将字符串传递给宏汇编器 MASM
好的,我已经在一定程度上完成了这个工作,但是当我尝试将变量名称传递给宏时,它会显示以下内容:
错误 A2071:初始值设定项幅度对于指定大小来说太大,
我看不出我在这里做错了什么。我正在遵循有关如何传递参数的示例,但这就是它给我的。这就是我到目前为止所拥有的。
TITLE MASM TestTExt (TestTExt.asm)
; Description:
;
; Revision date:
INCLUDE Irvine32.inc
;macro stuff
mWriteString MACRO text
LOCAL string
.data
string db text
.code
push edx
mov edx,OFFSET string
call WriteString
pop edx
ENDM
.data
myStr db "Test1",0
.code
main PROC
call Clrscr
mWriteString myStr
call Crlf
exit
main ENDP
END main
现在这不起作用,但如果当我在 .code 部分调用宏时将其放入像“Some Thing”这样的字符串中,则宏将起作用并继续其愉快的方式。这是为什么?我是否没有传递正确的字符串,或者我是否没有在 .data
部分中正确终止该字符串? 我使用的例子是这样的
.data
myString db "abcefg",0
.code
mWriteString myString
Ok so I have got this working to a degree but when I try to pass the variable name to the macro it says this:
error A2071: initializer magnitude too large for specified size
I don't see what I am doing wrong here. I am following the examples I have on how to pass parameters but that is what it gives me. So here is what I have so far.
TITLE MASM TestTExt (TestTExt.asm)
; Description:
;
; Revision date:
INCLUDE Irvine32.inc
;macro stuff
mWriteString MACRO text
LOCAL string
.data
string db text
.code
push edx
mov edx,OFFSET string
call WriteString
pop edx
ENDM
.data
myStr db "Test1",0
.code
main PROC
call Clrscr
mWriteString myStr
call Crlf
exit
main ENDP
END main
Now this does not work, but if is put in a string like this "Some Thing" when I call the macro in the .code section, the macro works and go on its merry way. Why is that? Am I not passing the right string or did I not terminate the string right in my .data
section?
The example I am using is like this
.data
myString db "abcefg",0
.code
mWriteString myString
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题在于该行:
试图将
text
参数的偏移量存储到一个字节中。我已经有一段时间没有使用汇编语言宏了,但我很确定您不需要在宏中使用
.data
指令。以下内容应该可以正常工作:I think the problem is that the line:
Is trying to store the offset of the
text
parameter into a byte.It's been quite a while since I worked with assembly language macros, but I'm pretty sure you don't need that
.data
directive in the macro. The following should work just fine:Adam,
据我所知,错误是...
在宏中...“字符串数据库文本”必须以零结尾...在
宏调用末尾添加“,0”...
1) ' .data myStr db "Test1",0' 条目不是必需的...
2) 调用您的宏,因此'mWriteString "Any Text"',它将为您设置'.data'。
该宏的作用是使您能够直接编写带引号的字符串。您可以将其保存在宏库中并重复使用。
我知道这是一篇旧文章,但希望它对您……或其他任何人有帮助。
问候,
萨姆·K
Adam,
The errors, as I see it, is ...
in the macro ... 'string db text' must be zero terminated ... add ',0' at the end
in macro call ...
1) the '.data myStr db "Test1",0' entry is not required ...
2) call your macro thus 'mWriteString "Any Text"' and it will setup the '.data' for you.
What this macro does is it enables you to directly write quoted strings. You can save it in a macro library and re-use it.
I know this is an old post, but hope it helps you ... or anyone else.
Regards,
Sam K