在汇编中操作字符串 (MASM)
.data
source BYTE "Defense mechanism",0
target BYTE SIZEOF source DUP(0)
.code
main PROC
mov esi, OFFSET target
mov edi, OFFSET target
mov ecx, SIZEOF source
L1:
mov al,[esi] ; get a character from source
mov [edi],al ; store it in the target
inc esi ; move to next character
inc edi
loop L1
在 .data
部分中,我看到 source
被定义为字符串。 在 .code
部分中,我看到 target
的内存位置存储在源索引中。难道我不应该希望源索引 (ESI
) 指向 source
而不是 target
吗?该程序应该将一个字符串复制到已初始化为源字符串大小的目标框中,并用零填充每个字段。我没有汇编语言的经验。我错了什么? (注:这就是我的教授列出该程序的方式,但他没有提供任何相关材料,因为这是一门基于网络的“计算安全”课程。
.data
source BYTE "Defense mechanism",0
target BYTE SIZEOF source DUP(0)
.code
main PROC
mov esi, OFFSET target
mov edi, OFFSET target
mov ecx, SIZEOF source
L1:
mov al,[esi] ; get a character from source
mov [edi],al ; store it in the target
inc esi ; move to next character
inc edi
loop L1
In the .data
section, I see that source
is defined as the string.
In the .code
section, I see that the memory location of target
is stored in the source index. Shouldn't I want the source index (ESI
) to point to source
instead of target
? This program is supposed to copy a string into the target box that has been initialized to the size of the source string and to have each of the fields filled with zeroes. I have no experience with Assembly language. What am I getting wrong? (Note: this is how my professor has the program listed out, but he isn't offering any real material on this because this is a web based "security in computing" course.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你是对的 -
esi
应该指向source
,而不是target
- 看起来你的教授在该代码中至少有一个错误。更改:至:
Yes, you're right -
esi
should point atsource
, nottarget
- it looks like your professor has at least one bug in that code. Change:to: