.386;368指令集
.model flat, stdcall;内存平坦模式
option casemap : none;区分大小写
include msvcrt.inc;包含c运行时库文件
includelib msvcrt.lib
include user32.inc;包含c运行时的链接库
includelib user32.lib
.data
szdata1 db " ", 0ah, 0dh, 0
szdata2 db "*", 0
szdata3 db " ", 0
.code
;打印“ ”
fun2 proc
;用到edx eax先保存起来
push edx
push eax
;通过寄存器传值 参数在ecx 放到edx中
mov edx, ecx
;对应行数
mov eax, 25
;eax -= ecx
sub eax, edx
allen :
;如果 == 0退出
cmp eax, 0
je boy2
;------------------------------------------------------------
;//////////////fun//////////////////////
;全部入栈
pushad
;printf()
push offset szdata3
call crt_printf
add esp, 04h
;全部出栈
popad
;//////////////fun//////////////////////
;--x
dec eax
jmp allen
;------------------------------------------------------------
boy2:
;还原edx eax
pop eax
pop edx
ret
fun2 endp
;打印*
fun proc
;用到edx先保存
push edx
push eax
;------------------------------------------------------------
;取参数
;mov edx, ecx n * 2 + 1
mov eax, ecx
mov edx, 2
mul edx
add eax, 1
mov ecx, eax
myloop :
;打印*
;//////////////fun//////////////////////
;全部入栈
pushad
;printf()
push offset szdata2
call crt_printf
add esp, 04h
;全部出栈
popad
;//////////////fun//////////////////////
loop myloop
;------------------------------------------------------------
;还原edx
pop eax
pop edx
ret
fun endp
;main
start :
;int x = 0
mov ecx, 0
allen:
;打印 " "
;//////////////fun1//////////////////////
;全部入栈
pushad
push ecx
;fun2 proc
call fun2
;平衡堆栈
add esp, 04h
;全部出栈
popad
;//////////////fun1//////////////////////
;打印*
;//////////////fun2//////////////////////
;全部入栈
pushad
push ecx
;fun proc
call fun
;平衡堆栈
add esp, 04h
;全部出栈
popad
;//////////////fun2//////////////////////
;打印换行
;//////////////fun3//////////////////////
;全部入栈
pushad
push offset szdata1
call crt_printf
;平衡堆栈
add esp, 04h
;全部出栈
popad
;//////////////fun3//////////////////////
;if ecx == 4 循环打印行数
cmp ecx, 25
;if x == 4->boy
je boy
;++x
inc ecx
;else continue
jmp allen
boy :
ret
end start
end
转载于:https://blog.51cto.com/haidragon/2097413