我想写一个加法的函数,要用堆栈传参数, 应该怎么写啊,能不能给个例子啊
------解决方案--------------------------------------------------------
- Assembly code
code segment assume cs:code_add proc near mov bp,sp mov ax,[bp+2] add ax,[bp+4] ret_add endpstart: mov ax,1 push ax mov ax,9 push ax call _add ;now result in ax == 1+9 mov ah,4ch int 21hcode ends end start
------解决方案--------------------------------------------------------
code segment
assume cs:code
_add proc near
push bp // 保存bp
mov bp,sp
mov ax,word ptr [bp+4]
add ax,word ptr [bp+6]
pop bp
ret
_add endp
或者:
_add proc near
mov ax,word ptr [sp+2]
add ax,word ptr [sp+4]
ret
_add endp
------解决方案--------------------------------------------------------
如2楼,可以先声明子过程原型:
- Assembly code
.code_addsub PROTO BYTE,BYTEmain PROC...invoke _addsub 1,2...main ENDP_addsub PROC x:DWORD,y:DWORD..._addsub ENDPEND main