21,459
社区成员
发帖
与我相关
我的任务
分享
mov ebx, sort_arr[edi * arrTypeSize]
mov val, ebx
mov ebx, sort_arr[edi * arrTypeSize + arrTypeSize]
mov val_next, ebx
.IF val > ebx
mov sort_arr[edi * arrTypeSize], ebx
mov ebx, val
mov sort_arr[edi * arrTypeSize + arrTypeSize], ebx
.ENDIF
TITLE MASM Template (main.asm)
;..........................................
; Author : Roc_King-Seven
; Purpose : This program is to realise Bubble sort
; Data : 2016/09/27
; Update : 2016/10/20
;..........................................
.686P ; Pentium Pro or later
.MODEL flat, stdcall
.STACK 4096
option casemap:none ;大小写不敏感
Crlf PROTO
DumpRegs PROTO
printf PROTO C :ptr byte,:vararg
scanf PROTO C :dword,:vararg
gets PROTO C :ptr byte
getchar PROTO C
ExitProcess PROTO,dwExitCode:DWORD ; exit program
INCLUDELIB C:\Irvine\USER32.LIB
INCLUDELIB C:\Irvine\KERNEL32.LIB
INCLUDELIB C:\Irvine\MSVCRT.LIB
INCLUDELIB C:\Irvine\IRVINE32.LIB
exit equ <INVOKE ExitProcess,0>
chr$ MACRO any_text:VARARG
LOCAL txtname
.data
IFDEF __UNICODE__
WSTR txtname,any_text
align 4
.code
EXITM <OFFSET txtname>
ENDIF
txtname db any_text,0
align 4
.code
EXITM <OFFSET txtname>
ENDM
arrTypeSize = TYPE SDWORD
.data?
n SDWORD ?
val SDWORD ?
val_next SDWORD ?
eax_cpy SDWORD ?
sort_arr SDWORD 100 DUP(?)
.code
main PROC
invoke printf, chr$("请输入数组元素的个数1~100: ")
invoke scanf, chr$("%d"),offset n
invoke getchar
invoke printf, chr$("请按顺序输入所有元素: ")
mov ecx, n
lea esi, sort_arr
.WHILE ecx != 0
push ecx
invoke scanf, chr$("%d"), esi
invoke getchar
pop ecx
add esi, arrTypeSize
dec ecx
.ENDW
mov esi, n
xor eax, eax
.WHILE esi != 0
mov ebx, n
sub ebx, eax
lea ecx, [ebx-1]
xor edi, edi
.WHILE ecx != 0
mov ebx, sort_arr[edi * arrTypeSize]
mov val, ebx
mov ebx, sort_arr[edi * arrTypeSize + arrTypeSize]
mov val_next, ebx
;##############################################problem
.IF val > ebx
mov sort_arr[edi * arrTypeSize], ebx
mov ebx, val
mov sort_arr[edi * arrTypeSize + arrTypeSize], ebx
NOP
.ENDIF
;#######################################################
inc edi
dec ecx
.ENDW
inc eax
dec esi
.ENDW
invoke printf, chr$("排序后的结果为: ")
xor edi, edi
mov ecx, n
.WHILE ecx != 0
mov eax, sort_arr[edi * arrTypeSize]
push ecx
invoke printf, chr$("%d "),eax
pop ecx
inc edi
dec ecx
.ENDW
invoke printf, chr$(0dh,0ah,"BubbleSort Finished!")
invoke getchar
exit
main ENDP
END main
TITLE MASM Template (main.asm)
;..........................................
; Author : Roc_King-Seven
; Purpose : This program is to realise Bubble sort
; Data : 2016/09/27
; Update : 2016/10/20
;..........................................
.686P ; Pentium Pro or later
.MODEL flat, stdcall
.STACK 4096
option casemap:none ;´óСд²»Ãô¸Ð
Crlf PROTO
DumpRegs PROTO
printf PROTO C :ptr byte,:vararg
scanf PROTO C :dword,:vararg
gets PROTO C :ptr byte
getchar PROTO C
ExitProcess PROTO,dwExitCode:DWORD ; exit program
INCLUDELIB C:\Irvine\USER32.LIB
INCLUDELIB C:\Irvine\KERNEL32.LIB
INCLUDELIB C:\Irvine\MSVCRT.LIB
INCLUDELIB C:\Irvine\IRVINE32.LIB
exit equ <INVOKE ExitProcess,0>
chr$ MACRO any_text:VARARG
LOCAL txtname
.data
IFDEF __UNICODE__
WSTR txtname,any_text
align 4
.code
EXITM <OFFSET txtname>
ENDIF
txtname db any_text,0
align 4
.code
EXITM <OFFSET txtname>
ENDM
arrTypeSize = TYPE SDWORD
.data?
n SDWORD ?
val SDWORD ?
val_next SDWORD ?
eax_cpy SDWORD ?
sort_arr SDWORD 100 DUP(?)
.code
main PROC
invoke printf, chr$("ÇëÊäÈëÊý×éÔªËصĸöÊý1~100: ")
invoke scanf, chr$("%d"),offset n
invoke getchar
invoke printf, chr$("Ç밴˳ÐòÊäÈëËùÓÐÔªËØ: ")
mov ecx, n
lea esi, sort_arr
.WHILE ecx != 0
push ecx
invoke scanf, chr$("%d"), esi
invoke getchar
pop ecx
add esi, arrTypeSize
dec ecx
.ENDW
mov esi, n
xor eax, eax
.WHILE esi != 0
mov ebx, n
sub ebx, eax
lea ecx, [ebx-1]
xor edi, edi
.WHILE ecx != 0
mov ebx, sort_arr[edi * arrTypeSize]
mov val, ebx
mov ebx, sort_arr[edi * arrTypeSize + arrTypeSize]
mov val_next, ebx
;################################################problem
.IF val > ebx
mov sort_arr[edi * arrTypeSize], ebx
mov ebx, val
mov sort_arr[edi * arrTypeSize + arrTypeSize], ebx
NOP
.ENDIF
###############################################################
inc edi
dec ecx
.ENDW
inc eax
dec esi
.ENDW
invoke printf, chr$("ÅÅÐòºóµÄ½á¹ûΪ: ")
xor edi, edi
mov ecx, n
.WHILE ecx != 0
mov eax, sort_arr[edi * arrTypeSize]
push ecx
invoke printf, chr$("%d "),eax
pop ecx
inc edi
dec ecx
.ENDW
invoke printf, chr$(0dh,0ah,"BubbleSort Finished!")
invoke getchar
exit
main ENDP
END main