在汇编中操作字符串 (MASM)

发布于 2024-11-17 14:58:54 字数 764 浏览 2 评论 0原文

.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许仙没带伞 2024-11-24 14:58:54

是的,你是对的 - esi 应该指向 source,而不是 target - 看起来你的教授在该代码中至少有一个错误。更改:

          mov  esi, OFFSET target

至:

          mov  esi, OFFSET source

Yes, you're right - esi should point at source, not target - it looks like your professor has at least one bug in that code. Change:

          mov  esi, OFFSET target

to:

          mov  esi, OFFSET source
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文