《Intel汇编第5版》 汇编调用子过程

一、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

执行结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值