将字符串中的所有值更改为“m”
我才刚刚开始玩弄masm。我不明白为什么这段代码不起作用。
.data
MsgBoxCaption db "Iczelion Tutorial No.2",0
MsgBoxText db "Win32 Assembly is Great!",0
savedAddr DWORD ?
.code
start:
mov eax, 10
mov savedAddr, OFFSET MsgBoxText
lab:
inc MsgBoxText
MOV MsgBoxText, 'm'
cmp eax, 0
dec eax
jnz lab
invoke MessageBox, NULL, savedAddr, addr MsgBoxCaption, MB_OK
invoke ExitProcess, NULL
end start
编辑:我希望看到 MsgBoxText 中的前 10 个字符是“m”。相反,只有第一个字母是“m”。我假设 inc MsgBoxText 增加了一个指针。
I'm just beginning to toy with masm. I don't understand why this code isn't working.
.data
MsgBoxCaption db "Iczelion Tutorial No.2",0
MsgBoxText db "Win32 Assembly is Great!",0
savedAddr DWORD ?
.code
start:
mov eax, 10
mov savedAddr, OFFSET MsgBoxText
lab:
inc MsgBoxText
MOV MsgBoxText, 'm'
cmp eax, 0
dec eax
jnz lab
invoke MessageBox, NULL, savedAddr, addr MsgBoxCaption, MB_OK
invoke ExitProcess, NULL
end start
Edit: I expect to see the first 10 characters in MsgBoxText be 'm's. Instead, only the first letter is an 'm'. I assume that inc MsgBoxText increments a pointer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
乍一看,这段代码除了将 Win32 的 'W' 更改为 'a' ,然后更改为单个“我”。
在每次循环迭代中,您将在
MsgBoxText
处递增内存中的单词(同一个单词)。要使用 'm' 字符破坏字符串,更好的策略是将字符串的地址加载到寄存器中,开始存储 'm' 字节,然后递增寄存器中的值,以及递减计数器。
更新:好的,要回答评论中的问题,请将循环更改为:
At first glance it seems like this code should do nothing except change the 'W' of Win32 to an 'a' and then to a single 'm'.
You are incrementing the word in memory at
MsgBoxText
, the same word, in each loop iteration.To clobber the string using the 'm' characters, a better strategy would be to load the address of the string into a register, start storing 'm' bytes, and then increment the value in the register, as well as decrementing the counter.
Update: Ok, to answer the question in the comment, change the loop to: