**some content deleted from internet**
Rev 1.0 Creat Document oct 4 2006
47.asm
;Created by DarkBlue Oct 4, 2006 Rev 1.0Title Copying a String and invert the string.386.model flat, stdcalloption casemap :none
include windows.incinclude kernel32.incinclude masm32.incInclude irvine32.inc
includelib kernel32.libincludelib masm32.libIncludeLib irvine32.lib
.data source BYTE "This is the source string, it will be copied.",0 target BYTE sizeof source dup(0),0 comment @ 注意此处的字符串共有45个字符,占用46个字节2E(结尾的那个0) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 <--本行为其前面的内存空间的数据 54 68 69 73 20 69 73 20 74 68 65 20 73 6F 75 72 63 65 20 73 74 72 69 6E 67 2C 20 69 74 20 77 69 6C 6C 20 62 65 20 63 6F 70 69 65 64 2E 00 最后说明一点原书未指名的一点,那就是他定义的Target比source要大一个字节, 因为Target要容纳source的所有数据,包括结尾的那个0,所以要大一点, 毕竟是个字符串和数据结构的习惯,不知道我说的对不对…… @.data? buffer BYTE MAX_PATH dup(?)
.code main PROC ;copy string mov esi,0 ;index register mov ecx, sizeof source ;loop counter call DumpRegs L1: mov al,source[esi] ;get a character from source mov target[esi],al ;store it in the target inc esi ;move to next character loop L1 ;repeat for entire string ;show the two string mov edx, offset source call WriteString call Crlf mov edx, offset target call WriteString call Crlf ;Invert the string ;specal Note: 下标从0开始,所以最后一个的元素的下标是(个数-1), ;而对于字符串数组来说最后一个字符是0(前面自己定义的),也就是 ;说我们的反转需要-2,循环(元素个数-1)次,然后补上最后的那个0 mov esi,0 mov ecx, (sizeof source)-1 ;在长度上去掉最后一个0 call DumpRegs L2: mov al,source[ecx-1] ;在实际中指向队尾 mov target[esi],al inc esi loop L2 mov target[esi],0 ;在指向最后一个元素后esi又加了1,故此处esi已指在结尾该添0处 ;dump Memory mov esi, offset target mov ecx, lengthof target mov ebx, type target call DumpMem call Crlf
;show the inverted string mov edx, offset target call WriteString ;暂停显示,回车键关闭 invoke StdIn,addr buffer,sizeof buffer invoke ExitProcess,0 ;如果不写入此语句,将会因非法退出被关闭 main ENDPEND main