;代码转换
include irvine32.inc
.data
dat word 10 dup(?) ;对于这个参数设计模式不太明白
p word 10 dup(?)
no word ?
.code
main proc
call input
push lengthof dat
push offset dat
call judge
call output
exit
main endp
input proc ;子程序:输入数组
push esi
push ecx
push ebx
push eax
mov ebx,offset dat
mov ecx,10
xor esi,esi
start: cmp ecx,0
jz done1
xor eax,eax
call readint ;这种输出模式每输入一个数都要换行
mov dat[esi*2],ax
inc esi
dec ecx
jmp start
done1: pop eax
pop ebx
pop ecx
pop esi
ret
input endp
judge proc ;子程序:判断一个数组中的所有偶数并存放
;入口参数:顺序压入数据个数 数据偏移地址
push ebp ;将ebp入栈
mov ebp,esp ;esp放入ebp中进行操作
push ebx
push edi
push eax
push ecx
push edx ;保护寄存器
mov ebx,[ebp+8] ;堆栈中取出的偏移地址
mov ecx,[ebp+12];堆栈中取出数组个数
xor esi,esi ;控制dat数组
xor edi,edi ;控制p数组
start1: cmp ecx,0
jz done3
xor edx,edx
xor eax,eax
mov dx,[ebx+esi*2]
mov ax,dx
and dx,01h
cmp dx,01h
jz odd
mov p[edi*2],ax
inc edi
odd: dec ecx
inc esi
jmp start1
done3: mov no,di
pop edx
pop ecx
pop eax
pop edi
pop ebx
pop ebp
ret 8 ;因为主程序压入两个参数,使用堆栈区8个字节
judge endp ;返回一个数组
output proc ;子程序:数组输出程序
;参数:相关待输出数组
xor esi,esi
xor ecx,ecx
mov ecx,dword ptr no
xor eax,eax
mov eax,ecx
call writeint
call crlf
ha6: cmp ecx,0
jz done3
xor eax,eax
mov ax,p[esi*2]
call writeint
call crlf
inc esi
dec ecx
jmp ha6
done3: ret
output endp ;无输出
end main ;汇编结束
;总结:堆栈传递参数和其他的区别
;提前将数组的数量和偏移量入栈
;在最后要ret 8用于平衡堆栈
;其余的操作没有什么不一样
汇编 w5-1
最新推荐文章于 2024-08-28 21:01:03 发布