0 Replies - 443 Views - Last Post: 06 November 2018 - 10:29 AM Rate Topic: -----

#1 mhmtckr27   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-November 18

Inline assembly-visual studio (JMP vs. LOOP)

Posted 06 November 2018 - 10:29 AM

Hi there! I wrote a simple code for insertion sort using visual studio 2012. If I use [LOOP don2] and [t=2*n; t=t-2;] there is no problem and code works. But as soon as I write [t=2*n-2;] it doesn't work untill I change the [LOOP don2] to [JMP don2]. I know I shouldn't use LOOP if it is a while loop but I just wonder why this error occurs.I highlighted the code pieces. It is the error I get:


ERROR: 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.






#include <stdio.h>
#include <stdlib.h>

int main(){
extern short randdizi(short*);
static short dizi[1];
int i,n,t;
n=randdizi(dizi);
printf("Girilen dizi:\t ");
for(i=0;i<n;i++)
{
printf("%hu ",dizi[i]);
}
printf("\n\n");

//t=n*2;
	//t=t-2;
	t=n*2-2;  

_asm
{
MOV ESI,2
buyukdon: CMP ESI,t
JA son
MOV EDI,0
don1: MOV AX,dizi[ESI]
CMP AX,dizi[EDI]
JNA don1cik
ADD EDI,2
JMP don1
don1cik: PUSH AX
MOV EBX,0
don2: PUSH ESI
SUB ESI,EDI
CMP EBX,ESI
JA don2cik
POP ESI
PUSH ESI
SUB ESI,EBX
MOV DX,dizi[ESI-2]
MOV dizi[ESI],DX
POP ESI
ADD EBX,2
  JMP don2  //if I write LOOP don2; I get error.  

don2cik: POP ESI
POP AX
MOV dizi[EDI],AX
ADD ESI,2
JMP buyukdon
son:
}
printf("Siralanmis dizi: ");
for(i=0;i<n;i++)
{
printf("%hu ",dizi[i]);
}
printf("\n\n");
system("PAUSE");
return 0;
}




this is the randdizi function in another file:



#include <stdlib.h>
#include <time.h>
#include <stdio.h>

short randdizi(short* sayi)
{
short unsigned i,elemansayisi;
srand(time(NULL));
printf("Eleman sayisi giriniz: ");
scanf("%hu",&elemansayisi);
for(i=0;i<elemansayisi;i++)
{
*(sayi+i)=rand()%100;
}
return elemansayisi;
}

Is This A Good Question/Topic? 0
  • +

Page 1 of 1