.386
.model flat,stdcall;平坦模式,stdcall
option casemap:none;大小寫不敏感
include msvcrt.inc;包含msvcrt.inc
includelib msvcrt.lib;包含msvcrt.lib
.data
szPause db "pause",0
szFormat db "%s",0
str1 db "hello world",0
str2 db 20 dup(0),0
.code
main:
;求字符串長度
;al與edi中數據進行比較
lea edi,str1
lea esi,str1
mov al,0
repne scasb;循環從edi中比較al的值,直到相等退出循環
sub edi,esi;終止位置-起始位置=長度
mov ecx,edi;保存長度
;movsb 字符拷貝
lea edi,str2
lea esi,str1
cld ;清空方向
rep movsb
push offset str2
push offset szFormat
call crt_printf
add esp,8
push offset szPause
call crt_system
add esp,4
ret
end main
end
把str1的“hello world”拷貝到str2裏
方法二:
.386
.model flat,stdcall
option casemap:none
include msvcrt.inc
includelib msvcrt.lib;system("pause")
.data
szPause db "pause",0
szFormat db "%s",0
str1 db "hello world",0
str2 db 20 dup(0),0
.code
mstrcpy proc
push ebp
mov ebp ,esp;打開棧幀
xor eax,eax
mov edi, [ebp+0ch]
mov ecx,-1
repne scasb
not ecx;ecx保存數組長度
mov esi,dword ptr[ebp+0Ch]
mov edi,dword ptr[ebp+08h]
rep movsb
mov esp,ebp
pop ebp
ret 8
mstrcpy endp
main:
push offset str1
push offset str2
call mstrcpy
push offset str2
push offset szFormat
call crt_printf
add esp,8
push offset szPause
call crt_system
add esp,4
ret
end main
end