Manipulating Strings in Assembly (MASM)

前提是你 提交于 2021-02-16 21:59:14

问题


.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.


回答1:


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


来源:https://stackoverflow.com/questions/6522386/manipulating-strings-in-assembly-masm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!