I have a Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. This my code
extern "C" int __fastcall Proc5(int* arr, int* freq, int raznost, int n, int N, int* result_5);
int main() {
const int N = 3;//2000; // количество элементов для подсчета количества значений
int raznost = N / 2; // рассчитывается смещение для отрицательных чисел
int arr[] = { 0,1};
int freq[N] = { 0 };
int n = sizeof(arr) / sizeof(arr[0]);
int* result_5 = new int[n];
Proc5(arr, freq, raznost, n, N, result_5);
cout << "Proc5" << endl;
for (int i = 0; i < n; i++)
{
std::cout << result_5[i] << " ";
}
@Proc5@24 proc
xor eax, eax
xor ebx, ebx
;xor ecx, ecx
;xor edx, edx
mov eax, ecx
mov ebx, edx
mov edx, [esp + 4]
;mov edi, [esp + 8]
;;;
push ebx
imul edx, 4
add ebx, edx
xor ecx, ecx
loop_1 :
cmp ecx, [esp + 12]
je loopend_1
mov edx, [eax + ecx * 4]
inc dword ptr [ebx + edx * 4]
inc ecx
jmp loop_1
loopend_1 :
pop ebx
xor edx, edx ; для количества элементов в новом массиве
xor ecx, ecx
outer_loop :
cmp ecx, [esp + 8]
je outer_loopend
push ecx
xor ecx, ecx ; счетчик
xor eax, eax ; максимальное значение
xor esi, esi ; количество
mov eax, 0
loop_2:
cmp ecx, [esp + 16]
je loopend_2
cmp esi, [ebx + ecx * 4]
jg end_if
mov esi, [ebx + ecx * 4]
mov eax, ecx
end_if :
inc ecx
jmp loop_2
loopend_2 :
xor ecx, ecx
push ebx
mov ebx, eax
push ebx
mov ebx, [esp + 28]
sub eax, [esp + 16]
loop_3 :
cmp esi, ecx
je loopend_3
mov[ebx + edx * 4], eax
inc edx
inc ecx
jmp loop_3
loopend_3:
pop ebx
mov edi, ebx
pop ebx
push eax
mov eax, 0
mov [ebx + edi * 4], eax
pop eax
pop ecx
;push ebp
inc ecx
jmp outer_loop
outer_loopend:
ret
@Proc5@24 endp
this is a program for sorting an array by the frequency of occurrence of elements
This comment help me. 32-bit fastcall is still a callee-pops convention, and you still have 4 stack args so you need ret 16 instead of the ret 24 you needed with stdcall before your edit. It's not a coincidence that 24 is the same number as in the symbol name Proc5@24 – Peter Cordes