标签:
一、Call和Ret指令
二、在子过程中需要自己保存可能会修改掉的寄存器值,这里可以使用USES伪指令来生成
三、一个数组求和的汇编例子
1 TITLE Call a Proc Demo 2 INCLUDE Irvine32.inc 3 includelib Irvine32.lib 4 includelib kernel32.lib 5 includelib user32.lib 6 7 8 .data 9 array DWORD 1000h,2000h,3000h,4000h 10 11 .code 12 13 ;--------------------------------------------------- 14 ; 15 ; Calcute the sum of an array of 32-bit int integers 16 ; Receives: ESI = the array offset 17 ; ECX = the size of array 18 ; Returns: EAX = sum of an array 19 ;--------------------------------------------------- 20 21 ArraySum PROC 22 23 push esi 24 push ecx 25 mov eax,0 26 L1: 27 add eax,[esi] 28 add esi,TYPE DWORD 29 loop L1 30 31 pop ecx 32 pop esi 33 ret 34 35 ArraySum endp 36 37 ;--------------------------------------------------- 38 ; 39 ; Calcute the sum of an array of 32-bit int integers 40 ; Receives: ESI = the array offset 41 ; ECX = the size of array 42 ; Returns: EAX = sum of an array 43 ;--------------------------------------------------- 44 45 ArraySumWithUses PROC USES esi ecx 46 47 mov eax,0 48 L2: 49 add eax,[esi] 50 add esi,TYPE DWORD 51 loop L2 52 53 ret 54 55 ArraySumWithUses endp 56 57 58 59 main PROC 60 61 mov esi,offset array 62 mov ecx,LENGTHOF array 63 call ArraySum 64 call DumpRegs 65 mov esi,offset array 66 mov ecx,LENGTHOF array 67 call ArraySumWithUses 68 call DumpRegs 69 ret 70 71 main endp 72 73 END main
执行结果:
标签:
原文地址:http://www.cnblogs.com/doudouyoutang/p/4937878.html