Answer the question
In order to leave comments, you need to log in
Why subtract 4 and multiply by 4?
I don’t really understand why 4 is subtracted and multiplied by 4, why is this a number, about pushad, do I understand correctly that it puts RON values on the stack, that is, the address of the array in esi, and in ecx the size of the array?
Procedure Bubble(var A: array of Integer; M: Integer);
Asm
pushad
dec ecx
mov esi, 1
@1:
mov edi, ecx
mov edx, [eax+edi*4]
@2:
mov ebx, [eax+edi*4-4]
cmp ebx, edx
ja @3
mov [eax+edi*4-4], edx
mov [eax+edi*4], ebx
jmp @4
@3:
mov edx, ebx
@4:
dec edi
cmp edi, esi
jnl @2
inc esi
cmp esi, ecx
jle @1
popad
End;
Answer the question
In order to leave comments, you need to log in
Procedure Bubble(var A: array of Integer; M: Integer);
# var A: array of Integer - ссылка на A, передаётся в eax
# M: Integer - размер массива, передаётся в ecx
Asm
pushad
dec ecx
mov esi, 1
@1:
mov edi, ecx
mov edx, [eax+edi*4] # mov edx, A[edi], 4-байтные int
@2:
mov ebx, [eax+edi*4-4] # ebx, A[edi - 1]
cmp ebx, edx
ja @3
mov [eax+edi*4-4], edx #mov A[edi - 1], edx
mov [eax+edi*4], ebx # A[edi], ebx # вот и поменялись местами
..............................
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question