나는 거품 정렬을 x86 (masm32)에 쓰려고합니다. 정렬이 작동하지 않습니다. 일부 코드를 테스트 한 결과 비교 섹션과 스왑 섹션에서 엉망이 된 것으로 보입니다. 어떤 이유인지 비교 함수는 항상 EAX에 2를 할당합니다. 내가 왜 프로그램을 작동시킬 수 있는지 알아낼 수 있다면.거품 정렬 (masm32), 내가 쓴 정렬 작동하지 않습니다.
미리 도움을 주셔서 감사합니다. 이와
cmp ebx, eax
jg swap
swap:
mov [aa + edi * 4h], eax
mov [aa + edi * 4h + 4], ebx
jmp inner
이는 g
플래그가 설정되어있는 경우 스왑 점프 -하지만 g
플래그가 하지 경우 스왑을 통해 해당 될
.data
aa DWORD 10 DUP(5, 7, 6, 1, 4, 3, 9, 2, 10, 8)
count DWORD 0
; DB 8-bits, DW 16-bit, DWORD 32, WORD 16 BYTE 8
.code ; Tell MASM where the code starts
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start: ; The CODE entry point to the program
mov esi, count ;loop count
outer:
inc esi
mov edi, count
cmp esi, 9
je end_loop
inner: ;this loop represents a full pass on the entire array
inc edi
cmp edi, 9 ;after 9 passes goes to outer loop
je outer
compare:
mov eax, [aa + edi * 4h] ;higher indexed one
mov ebx, [aa + edi * 4h - 4h]
;testing print chr$(13,10)
;testing print str$(eax)
;testing print chr$(13, 10)
;testing print str$(ebx)
;testing print chr$(13, 10)
cmp ebx, eax
jg swap
swap:
mov [aa + edi * 4h], eax
mov [aa + edi * 4h + 4], ebx
jmp inner
end_loop:
;print out array elements
sub esi, esi
mov esi, [aa]
print str$(esi)
print chr$(" ")
sub esi, esi
mov esi, [aa + 4h]
print str$(esi)
print chr$(" ")
sub esi, esi
mov esi, [aa + 4h * 2]
print str$(esi)
print chr$(" ")
sub esi, esi
mov esi, [aa + 4h * 3]
print str$(esi)
print chr$(" ")
sub esi, esi
mov esi, [aa + 4h * 4]
print str$(esi)
print chr$(" ")
sub esi, esi
mov esi, [aa + 4h * 5]
print str$(esi)
print chr$(" ")
sub esi, esi
mov esi, [aa + 4h * 6]
print str$(esi)
print chr$(" ")
sub esi, esi
mov esi, [aa + 4h * 7]
print str$(esi)
print chr$(" ")
sub esi, esi
mov esi, [aa + 4h * 8]
print str$(esi)
print chr$(" ")
sub esi, esi
mov esi, [aa + 4h * 9]
print str$(esi)
print chr$(" ")
sub esi, esi
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start ; Tell MASM where the program ends
고마워요! 나는 그것을 바로 바꿀 것이다. 그러나 EAX를 출력 할 때 왜 항상 2인지는 모르겠다. (비교 함수에서, 테스트 노트에있는 주석) – grey
@grey : 오히려, 나는 그것에 대해 확신하지 못한다. 나는 그것이 스케일링 문제라고 생각 하겠지만, 디버거에서 실행하는 것이 유일한 방법 일 것이다. –