问题
I am working on an assignment where the user enters the number of values they will input in to an array inputs that amount of numbers. After all of this however I need to do a bubble sort that will put the inputted numbers in the array from smallest to biggest.
The confusing part is that it says "the inner loop of the bubble sort is to be in a procedure". I'm not even sure where to begin on how to do this let alone creating inner and outer loops. All of the examples that I have found online use some "esi" thing or something that I don't have in my code and none of them had inner and outer loops. I'm just trying to get this started so if anyone has anything that could help me out or get me on track it would be greatly appreciated. I put in the question the code I have so far below and an explanation of at least what I think it does.
Let me give you a brief run down of what I have so far... The first procedure just displays an error message and ends the program. It is called when "count" isn't in the correct range. The second procedure is where the user enters "count" numbers in to the "values array". And lastly the main procedure is where I have the user input their "count" number and I validate it to be in the correct range (2 to 12) or the error is displayed and the program ends. The main procedure also calls the procedure where the numbers are entered.
INCLUDE Irvine32.inc
.data
count SDWORD ?
values SDWORD 12 DUP (?)
prompt1 BYTE "Enter the number of values to sort",0
prompt2 BYTE "Error. The number must be between 2 and 12",0
.code
Error PROC
mov edx, OFFSET prompt2
call WriteString
exit
Error ENDP
EnterValues PROC
mov ecx, count
mov edx, 0
Loop3:
mov eax, values[edx * 4]
call WriteInt
call CrLf
inc edx
dec ecx
jnz Loop3
ret
EnterValues ENDP
main PROC
mov edx, OFFSET prompt1
call WriteString ; prints out prompt1
call ReadInt
mov count, eax ; save returned value from eax to count
cmp count, 12
jle Loop1 ; If count is less than or equal to 12 jump to Loop1, otherwise continue with Error procedure
call Error ; performs Error procedure which will end the program
Loop1: cmp count, 2
jge Loop2 ; If count is greater than or equal to 2 jump to Loop2, otherwise continue with Error procedure
call Error ; performs Error procedure which will end the program
Loop2: call EnterValues
exit
main ENDP
END main
来源:https://stackoverflow.com/questions/43623977/sort-contents-of-array-in-assembly