一、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,4000h10 11 .code12 13 ;---------------------------------------------------14 ;15 ; Calcute the sum of an array of 32-bit int integers16 ; Receives: ESI = the array offset17 ; ECX = the size of array18 ; Returns: EAX = sum of an array19 ;---------------------------------------------------20 21 ArraySum PROC22 23 push esi24 push ecx25 mov eax,0 26 L1:27 add eax,[esi]28 add esi,TYPE DWORD29 loop L130 31 pop ecx32 pop esi33 ret34 35 ArraySum endp36 37 ;---------------------------------------------------38 ;39 ; Calcute the sum of an array of 32-bit int integers40 ; Receives: ESI = the array offset41 ; ECX = the size of array42 ; Returns: EAX = sum of an array43 ;---------------------------------------------------44 45 ArraySumWithUses PROC USES esi ecx46 47 mov eax,0 48 L2:49 add eax,[esi]50 add esi,TYPE DWORD51 loop L252 53 ret54 55 ArraySumWithUses endp56 57 58 59 main PROC60 61 mov esi,offset array62 mov ecx,LENGTHOF array63 call ArraySum64 call DumpRegs65 mov esi,offset array66 mov ecx,LENGTHOF array67 call ArraySumWithUses68 call DumpRegs69 ret70 71 main endp72 73 END main
执行结果: