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