; 寄存器传参 include io32.inc .data sum dword 0 .code start: main proc mov ebx, 1 .while ebx <= 8 call fac add sum, eax inc ebx .endw mov eax, sum call dispuid call dispcrlf ret main endp fac proc mov ecx, 1 mov eax, 1 .while ecx <= ebx imul eax, ecx inc ecx .endw ret fac endp end main
include io32.inc .data year dword ? flag dword ? .code main proc mov year, 2010 .while year <= 2060 call leap cmp flag, 1 jne next mov eax, year call dispuid call dispcrlf next: inc year .endw main endp leap proc mov flag, 0 mov eax, year xor edx, edx push eax push edx mov ebx, 400 div ebx .if !edx jmp lab1 .else pop edx pop eax mov ebx, 4 div ebx .if !edx mov eax, year xor edx, edx mov ebx, 100 div ebx .if edx jmp lab1 .else jmp lab2 .endif .else jmp lab2 .endif .endif lab1: mov flag, 1 lab2: ret leap endp end main
include io32.inc .data Parray dword 100 dup(0) flag dword ? .code main proc mov esi, offset Parray ; ESI 为指向 array 数组首地址的指针 mov ebx, 2 .while ebx <= 100 push ebx call Prime .if flag == 1 mov [esi], ebx add esi, 4 ; show1 mov eax, ebx call dispuid call dispcrlf .endif inc ebx .endw ; show2 ;mov ecx, lengthof Parray ;mov ebx, offset Parray ;again: ;mov eax, [ebx] ;.if eax == 0 ; ret ;.endif ;call dispuid ;call dispcrlf ;add ebx, 4 ;loop again ret main endp Prime proc push ebp mov ebp, esp ; 求素数的核心程序 mov ecx, 2 .while ecx < [ebp + 8] ;.if [ebp + 8] % ecx == 0 mov eax, [ebp + 8] mov edx, 0 div ecx .if edx == 0 mov flag, 0 jmp done .endif inc ecx .endw mov flag, 1 done: pop ebp ret 1 * 4 Prime endp end main
include vcIO.inc .data prompt byte '请输入三个整数(以空格分隔):', 0 fmt1 byte '%d %d %d', 0 fmt2 byte '最大公约数:%d', 13, 10, 13, 10, 0 dvar1 dword ? dvar2 dword ? dvar3 dword ? res dword ? .code main proc again: pushad invoke printf, offset prompt invoke scanf, offset fmt1, offset dvar1, offset dvar2, offset dvar3 popad push dvar1 push dvar2 call gcd ; 堆栈传参,结果保存在 EAX add esp, 8 push eax push dvar3 call gcd add esp, 8 mov res, eax pushad invoke printf, offset fmt2, res popad jmp again ret main endp gcd proc push ebp mov ebp, esp push ebx ; 保护寄存器 push edx mov eax, [ebp + 8] mov ebx, [ebp + 12] .if eax < ebx xchg eax, ebx .endif .while ebx != 0 xor edx, edx idiv ebx mov eax, edx xchg eax, ebx .endw pop edx pop ebx pop ebp ret gcd endp end main
include io32.inc .data msg1 byte '32位二进制:00110000011100101000000110101111B', 13, 10, 0 msg2 byte '8位十六进制:', 0 dvar dword 00110000011100101000000110101111B .code main proc mov eax, offset msg1 call dispmsg mov eax, offset msg2 call dispmsg push dvar call disp mov al, 'H' call dispc call dispcrlf ret main endp disp proc push ebp mov ebp, esp push ecx mov ecx, 8 mov eax, [ebp + 8] again: rol eax, 4 push eax and al, 0fh add al, 30h .if al > '9' add al, 7 .endif call dispc pop eax loop again pop ecx pop ebp ret 1 * 4 disp endp end main
; BubbleSort include vcIO.inc include io32.inc .data array dword 3, 2, -1, 3, 5 msg1 byte '原数组:', 0 msg2 byte '新数组:', 0 len dword lengthof array fmt byte '%d ', 0 .code main proc mov eax, offset msg1 call dispmsg call show call bubbleSort mov eax, offset msg2 call dispmsg call show ret main endp show proc push ebp mov ebp, esp push ebx pushad mov ebx, 0 .while ebx < len invoke printf, offset fmt, array[ebx * 4] inc ebx .endw popad call dispcrlf pop ebx pop ebp ret show endp bubbleSort proc push ebp mov ebp, esp push eax push ebx push esi push edi mov esi, 0 .while esi < len mov edi, esi inc edi mov eax, array[esi * 4] .while edi < len mov ebx, array[edi * 4] .if sdword ptr eax > sdword ptr ebx xchg eax, ebx mov dword ptr array[esi * 4], eax mov dword ptr array[edi * 4], ebx .endif inc edi .endw inc esi .endw pop edi pop esi pop ebx pop eax pop ebp ret bubbleSort endp end main
看后点赞,好运不断