Question
MASM 32... Kip Irvine Can anyone help me write a function to call exchange PROC where it will swap the values if [esi] => [edi].
MASM 32... Kip Irvine
Can anyone help me write a function to call exchange PROC where it will swap the values if [esi] => [edi]. I am having trouble pushing the values and getting them to compare in the exchange PROC.
Here is the code. It is a bubblesort.
sortList PROC
push ebp ; Set up stack
mov ebp, esp ; Set up EBP to ESP pointer
mov ecx, [ebp + 8] ; Loop counter
dec ecx ; We will loop until n-1
outerloop:
push ecx ; Save the outer loop count
mov esi, [ebp + 12] ; Point to the first value in the array
innerloop:
mov eax, [esi] ; Get the element at index inside array
cmp [esi+4], eax ; Compare a pair of values
jb notgreater ; If [esi] => [edi], exchange
call exchange ; Else call Exchange
>> xchg eax, [esi+4] << ; How can I exchange these two values in the EXCHANGE PROC? and return to the next line?
mov [esi], eax
notgreater:
add esi, 4 ; Move both pointers forward
loop innerloop ; Inner loop
pop ecx ; Get outer loop count
loop outerloop ; Else repeat outer loop
bubblecomplete:
pop ebp
ret 8 ; Clear stack
sortList ENDP
exchange PROC
exchange ENDP
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started