|  | 
 
| 
写的第一个传参程序,同初学者分享
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  ;用栈传递参数示例:只要修改s就修改了输出
 
 date segment ;数据段
 s1 db '  shu chu 1$' ;输出参数1
 s2 db '  shu chu 2$' ;输出参数2
 s3 db '  shu chu 3$' ;输出参数3
 s  equ   s1; 方便修改参数
 date ends
 
 stack segment para stack 'stack' ;堆栈段
 dw 100 dup (?) ;开辟栈空间
 stack ends
 
 code segment ;代码段
 assume cs:code,ds:date,ss:stack
 start: mov ax,date
 mov ds,ax ;关联数据段
 lea ax,s  ;装s的偏移(参数)
 push ax   ; 将参数压栈   此时sp指向栈中的s(参数)
 call   shuchu    ;调用shuchu这个函数  此时sp指向栈中的(ip)
 mov ah,4ch;结束程序
 int 21h
 
 shuchu proc     ;定义shuchu函数
 push bp   ;保护bp  此时sp指向栈中的(bp)
 mov bp,sp ;关键的地方,bp此时(锁定)了参数的位置,
 ;bp+4就是参数在栈中的地址
 push ax   ;保护现场
 push bx
 push cx
 push dx
 mov dx,[bp+4] ;参数传递给dx
 mov ah,09h    ;调用中断显示字符串
 int 21h
 pop dx    ;恢复现场
 pop cx
 pop bx
 pop ax
 pop bp
 ret  2  ;因为只是传递了一个字参数,所以加2清除参数
 shuchu endp   ;函数定义结束
 
 code ends
 end start
 
 | 
 |