.686p
.model flat,stdcall
Option casemap:none
include windows.inc
include kernel32.inc
include masm32.inc
includelib "d:\vs\msvcrt.lib"
includelib masm32.lib
includelib kernel32.lib
printf PROTO C:dword,:vararg
scanf PROTO C:dword,:vararg
.data
hello db ‘hello‘,0
A dword 5,4,30,2,1
p byte ‘%s‘,0ah
hint1 byte "Please enter 5 numbers:",0ah,0
hint2 byte "like 5 2 3 1 4,",0ah,0
fmt byte "%d %d %d %d %d",0ah,0
lin byte "function:%d",0ah,0
edii byte " Before exchanging eax:%d,ebx:%d",0ah,0
edia byte " After exchanging eax:%d,ebx:%d",0ah,0
.code
start:
init:
mov edi,0
mov esi,0
JMP input_number
input_number:
invoke printf, offset hint1
invoke printf, offset hint2
invoke scanf , offset fmt,offset A[0],offset A[4],offset A[8],offset A[12],offset A[16]
JMP judge
judge:
cmp edi,4
JNS ju_esi
mov eax,A[edi*4]
mov ebx,A[edi*4+4]
;invoke printf,offset lin,2
add edi,1
cmp eax,ebx
JNS exchange;结果为负,则转移
JMP judge
exchange:
;invoke printf,offset edii,eax,ebx
mov A[edi*4-4],ebx
mov A[edi*4],eax
;invoke printf,offset edia,eax,ebx
;invoke printf, offset fmt,A[0],A[4],A[8],A[12],A[16]
JMP judge
ju_esi:
;invoke printf,offset lin,3
add esi,1
cmp esi,4
JNS exit
mov edi,0
JMP judge
exit:
;invoke printf,offset lin,4
invoke printf, offset fmt,A[0],A[4],A[8],A[12],A[16]
;invoke StdOut, addr hello
invoke ExitProcess,0
end start