1. FindLargest过程

FindLargest PROC pdwAry:PTR SDWORD, dwAryLen:DWORD
	mov esi, pdwAry
	mov ecx, dwAryLen 
	dec ecx
	mov eax, SDWORD PTR [esi]
	add esi, 4
	
L0:
	cmp eax, SDWORD PTR [esi]
	jge @F
	mov eax, SDWORD PTR [esi]
@@:
	add esi, 4
	loop L0
	ret 
FindLargest ENDP

2. 棋盘

.data
BGGRAY = (8 * 16)
BGWHITE = (15 * 16)

.code
DrawChess PROC
	mov ecx, 8
	mov eax, BGGRAY

Lx:
	push ecx
	mov ecx, 8
	cmp eax, BGGRAY
	je @F
	mov eax, BGGRAY
	jmp Ly
@@:
	mov eax, BGWHITE
Ly:
	cmp eax, BGGRAY
	jne WhiteSquare
	mov eax, BGWHITE
	call SetTextColor
	jmp Next
WhiteSquare:
	mov eax, BGGRAY
	call SetTextColor
Next:
	push eax
	mov al, 20h
	call WriteChar
	call WriteChar
	pop eax
	loop Ly
	call Crlf
	pop ecx
	loop Lx

	mov eax, 0
	call SetTextColor

	ret
DrawChess ENDP

3. 变色棋盘

include irvine32.inc
includelib irvine32.lib

.data
.code
InitColorAry PROC USES EAX ECX EDI, pColorAry:PTR DWORD, dwColor:DWORD
	xor eax, eax
	mov ecx, dwColor
	mov edi, pColorAry
L0:
	mov DWORD PTR [edi], eax
	inc eax
	add edi, TYPE DWORD
	loop L0			 
	ret
InitColorAry ENDP

DrawSquare PROC USES EBX EAX, pColorAry:PTR DWORD, AryLen:DWORD
	mov ebx, 10h
	mov eax, AryLen
	call RandomRange
	mul ebx
	call SetTextColor
	mov al, 20h
	call WriteChar
	call WriteChar
	; 恢复颜色
	mov eax, (16 * black + white)
	call SetTextColor
	ret
DrawSquare ENDP

DrawChess PROC USES ECX 
	LOCAL @ColorAry[16]:DWORD

	; 初始化颜色数组
	push LENGTHOF @ColorAry
	lea eax, [@ColorAry]
	push eax
	call InitColorAry
	; 画棋盘
	mov ecx, 8
Lx:
	push ecx
	mov ecx, 8
Ly:
	push LENGTHOF @ColorAry
	lea eax, [@ColorAry]
	push eax
	call DrawSquare
	loop Ly
	; 换行
	call Crlf
	pop ecx
	loop Lx

	; 恢复颜色
	mov eax, white
	call SetTextColor

	ret
DrawChess ENDP 

SixteenTimes PROC

	call Randomize
	mov ecx, 16
L0:
	call DrawChess
	mov eax, 500
	call Delay
	call Clrscr

	loop L0
	ret
SixteenTimes ENDP

start:
	call SixteenTimes

	call WaitMsg
	invoke ExitProcess, 0
end	start

4. FindThrees过程

includelib kernel32.lib
includelib user32.lib
include irvine32.inc
includelib irvine32.lib

ExitProcess PROTO STDCALL, uExitCode:DWORD

.data
dwNumAry	DWORD 25, 63, 11, 11, 11, 9, 53
AryLen		DWORD LENGTHOF dwNumAry
.code

FindThree PROC USES ecx esi ebx  pAry:PTR DWORD, dwAryLen:DWORD
	LOCAL @dwCurNum:DWORD 

	; 获取除了第1个值外的长度
	mov ecx, dwAryLen 
	dec ecx 
	; 获取第一个数值
	mov esi, pAry
	mov eax, [esi]
	mov @dwCurNum, eax 

	xor ebx, ebx 
L0:
	mov eax, DWORD PTR [esi]
	cmp eax, @dwCurNum
	jz @F 
	xor ebx, ebx 
	jmp NextNum
@@:
	inc ebx 
	cmp ebx, 2
	je FindOut
NextNum:
	mov @dwCurNum, eax 
	dec ecx 
	add esi, TYPE DWORD 
	test ecx, ecx 
	jnz L0 
	xor eax, eax 
	jmp Ending
FindOut:
	mov eax, 1
Ending:
	ret 

FindThree ENDP 

main PROC
	push AryLen
	push OFFSET dwNumAry
	call FindThree 
	call WriteDec 

Ending:
	call WaitMsg 
	invoke ExitProcess, 0
main ENDP
end	main

5. DifferentInputs

includelib kernel32.lib
includelib user32.lib
include irvine32.inc
includelib irvine32.lib

ExitProcess PROTO STDCALL, uExitCode:DWORD

.data
szPromptInput	BYTE "请输入数字: ", 0

.code
DifferentInputs PROC 
	LOCAL @dwNum1:DWORD, @dwNum2:DWORD, @dwNum3:DWORD 

	mov edx, OFFSET szPromptInput
	call WriteString 
	call ReadDec 
	mov @dwNum1, eax 
	mov edx, OFFSET szPromptInput
	call WriteString 
	call ReadDec 
	mov @dwNum2, eax 
	mov edx, OFFSET szPromptInput
	call WriteString 
	call ReadDec 
	mov @dwNum3, eax 
	cmp eax, @dwNum2 
	jnz @F 
	cmp eax, @dwNum1 
	jnz @F 
	mov eax, 1
	jmp Ending 
@@:
	xor eax, eax 
Ending: 
	ret 
DifferentInputs ENDP 

main PROC
	call DifferentInputs 
	call WriteDec 
	call Crlf 
	call WaitMsg 
	invoke ExitProcess, 0
main ENDP
end	main

6. 整数交换

.386
.model flat, stdcall 
option casemap:none 
include windows.inc 
include kernel32.inc 
includelib kernel32.lib
include user32.inc 
includelib user32.lib 
include msvcrt.inc 
includelib msvcrt.lib

.data 
szPause         BYTE "pause", 0
szFmt           BYTE "%d %d", 0
dwNumAry        DWORD 24, 19, 42, 51, 95, 2, 69, 82
dwNumCnt        = ($ - dwNumAry) / TYPE dwNumAry 

.code 
_SwapNum PROC USES esi edi eax, piNum0:PTR DWORD, piNum1:PTR DWORD 
    mov esi, piNum0
    mov edi, piNum1
    mov eax, [esi]
    xchg eax, [edi]
    mov [esi], eax 
    ret 
_SwapNum ENDP 

_DoubleSwap PROC piNumAry:PTR DWORD, dwNum:DWORD 

    mov eax, dwNum
    mov ebx, 2
    xor edx, edx 
    div ebx 
    test edx, edx 
    jz EvenNum 
    dec dwNum 
EvenNum:
    mov ecx, eax 
    mov esi, piNumAry
L1:
    lea eax, [esi + 4]
    invoke _SwapNum, esi, eax
    add esi, 8
    loop L1 

    ret 
_DoubleSwap ENDP 

main PROC 
    invoke _DoubleSwap, OFFSET dwNumAry, dwNumCnt

    invoke crt_system, OFFSET szPause
    invoke ExitProcess, 0

main ENDP 
END main 

7. 最大公约数

.386
.model flat, stdcall 
option casemap:none 

include windows.inc 
include kernel32.inc 
includelib kernel32.lib
include user32.inc 
includelib user32.lib 
include msvcrt.inc 
includelib msvcrt.lib

.data 
szPause         BYTE "pause", 0
szFmt           BYTE "%d", 0

.code 
gcd PROC iNum0:DWORD, iNum1:DWORD 

    mov eax, iNum1 
    test eax, eax 
    jz Ending 
    mov eax, iNum0 
    mov ebx, iNum1 
L0:
    xor edx, edx 
    div ebx 
    mov eax, ebx 
    mov ebx, edx  
    test ebx, ebx 
    jnz L0
Ending:
    ret 

gcd ENDP 

main PROC 
    invoke gcd, 35, 14
    invoke crt_printf, OFFSET szFmt, eax 
    invoke crt_system, OFFSET szPause
    invoke ExitProcess, 0

main ENDP 
END main 

8. 相等元素数组计数器

.386
.model flat, stdcall 
option casemap:none 

include windows.inc 
include kernel32.inc 
includelib kernel32.lib
include user32.inc 
includelib user32.lib 
include msvcrt.inc 
includelib msvcrt.lib

.data 
szPause         BYTE "pause", 0
szFmt           BYTE "%d", 0

dwNumAry1       SDWORD 19, 25, 12, 22, 49, 92
dwNumAryCnt1    = ($ - dwNumAry1) / TYPE SDWORD 
dwNumAry2       SDWORD 11, 25, 12, 43, 42
dwNumAryCnt2    = ($ - dwNumAry2) / TYPE SDWORD 

CountMatches PROTO piNumAry1:PTR SDWORD, 
        iNumAryCnt1:DWORD, 
        piNumAry2:PTR SDWORD, 
        iNumAryCnt2:DWORD 

.code 
CountMatches PROC USES esi edi ebx ecx, 
        piNumAry1:PTR SDWORD, 
        iNumAryCnt1:DWORD, 
        piNumAry2:PTR SDWORD, 
        iNumAryCnt2:DWORD 
    mov esi, piNumAry1
    mov edi, piNumAry2
    
    ; 获取最小值
    mov ecx, iNumAryCnt1
    cmp ecx, iNumAryCnt2
    jb @F
    mov ecx, iNumAryCnt2
@@: 
    mov ebx, ecx 
    repe cmpsd 
    lea eax, [ebx - 1]
    sub eax, ecx 
    ret 

CountMatches ENDP 

main PROC 
    invoke CountMatches, OFFSET dwNumAry1, dwNumAryCnt1, OFFSET dwNumAry2, dwNumAryCnt2

    invoke crt_printf, OFFSET szFmt, eax 
    invoke crt_system, OFFSET szPause
    invoke ExitProcess, 0

main ENDP 
END main 

9. 近似相等元素计数器

.386
.model flat, stdcall 
option casemap:none 

include windows.inc 
include kernel32.inc 
includelib kernel32.lib
include user32.inc 
includelib user32.lib 
include msvcrt.inc 
includelib msvcrt.lib

.data 
szPause         BYTE "pause", 0
szFmt           BYTE "%d", 0

dwNumAry1       SDWORD 13, 21, 12, 22, 49, 92
dwNumAryCnt1    = ($ - dwNumAry1) / TYPE SDWORD 
dwNumAry2       SDWORD 11, 25, 12, 43, 42
dwNumAryCnt2    = ($ - dwNumAry2) / TYPE SDWORD 

CountNearMatches PROTO piNumAry1:PTR SDWORD, 
                        dwAryCnt1:DWORD,
                        piNumAry2:PTR SDWORD,
                        dwAryCnt2:DWORD,
                        diff:SDWORD  

.code 

CountNearMatches PROC USES ebx ecx edi esi, piNumAry1:PTR SDWORD, 
                        dwAryCnt1:DWORD,
                        piNumAry2:PTR SDWORD,
                        dwAryCnt2:DWORD,
                        diff:SDWORD  
                        LOCAL @dwCntOfDiff:DWORD 
    ; 求出数组长度较小的那个
    mov ecx, dwAryCnt1
    cmp ecx, dwAryCnt2
    jl @F 
    mov ecx, dwAryCnt2
@@:
    mov esi, piNumAry1
    mov edi, piNumAry2
    mov @dwCntOfDiff, 0
L0:
    mov eax, DWORD PTR [esi]
    cmp eax, DWORD PTR [edi]
    jg @F 
    mov ebx, DWORD PTR [edi]
    sub ebx, eax 
    mov eax, ebx 
    jmp L1 
@@:
    sub eax, DWORD PTR [edi]
L1:
    cmp eax, diff 
    jg @F 
    mov eax, @dwCntOfDiff
    inc eax 
    mov @dwCntOfDiff, eax 
@@:
    add esi, TYPE SDWORD 
    add edi, TYPE SDWORD 
    loop L0 
    mov eax, @dwCntOfDiff

    ret 

CountNearMatches ENDP

main PROC 
    invoke CountNearMatches,
                OFFSET dwNumAry1, 
                dwNumAryCnt1, 
                OFFSET dwNumAry2, 
                dwNumAryCnt2, 6

    invoke crt_printf, OFFSET szFmt, eax 
    invoke crt_system, OFFSET szPause
    invoke ExitProcess, 0

main ENDP 
END main 

10. 显示过程参数

.386
.model flat, stdcall 
option casemap:none 

include windows.inc 
include kernel32.inc 
includelib kernel32.lib
include user32.inc 
includelib user32.lib 
include msvcrt.inc 
includelib msvcrt.lib

.data 
szPause         BYTE "pause", 0
szFmt           BYTE "%d", 0
szShowParams    BYTE "Address %08X = %08X", 0dh, 0ah, 0
szBuf           BYTE 128 DUP(0)

.code 

MySample PROC dwParam1:DWORD, dwParam2:DWORD, dwParam3:DWORD 
    paramCount = 3
    push paramCount
    call ShowParams 
    ret 

MySample ENDP 

ShowParams PROC dwParamsCnt:DWORD 

    mov eax, ebp 
    mov ebx, dwParamsCnt
    add eax, 14h 
L0: 
    push eax 
    invoke crt_printf, OFFSET szShowParams, eax, DWORD PTR [eax]
    pop eax 
    add eax, 4
    dec ebx 
    test ebx, ebx 
    jnz L0 

    ret 

ShowParams ENDP 

main PROC 
    invoke MySample, 1234h, 5000h, 6543h
    invoke crt_printf, OFFSET szFmt, eax 
    invoke crt_system, OFFSET szPause
    invoke ExitProcess, 0

main ENDP 
END main 

(完)

10-21 20:38