kevinwang128
March 28th, 2009, 12:24 PM
i am doing a major assembly assignment, one of the question is asking to convert shellqort to assembly, if anyone who is good with assembly and willing to give me a hand much appreciated !!
this is the c code:
#include <stdlib.h>
#include <string.h>
int largerThanForInt(const void *p, const void *q)
{
if(*((int*)p) > *((int*)q))
return 1;
else
return 0;
}
void shellsort(void * base, size_t num, size_t size,
int (*comparator) (const void *, const void *))
{
size_t gap, i;
int j;
char *temp, *pj, *pjgap;
temp = (char*)malloc(size);
for (gap = num/2; gap > 0; gap /=2)
for (i = gap; i < num; i++)
for (j = i - gap;
j >= 0 && comparator((char*)base+j*size, (char*)base+(j+gap)*size);
j -= gap)
{
pj = (char*)base + j * size;
pjgap = (char*)base + (j + gap) * size;
memmove(temp, pj, size);
memmove(pj, pjgap, size);
memmove(pjgap, temp, size);
}
free(temp);
}
A few comment could also help !!
thanks guys
this is the c code:
#include <stdlib.h>
#include <string.h>
int largerThanForInt(const void *p, const void *q)
{
if(*((int*)p) > *((int*)q))
return 1;
else
return 0;
}
void shellsort(void * base, size_t num, size_t size,
int (*comparator) (const void *, const void *))
{
size_t gap, i;
int j;
char *temp, *pj, *pjgap;
temp = (char*)malloc(size);
for (gap = num/2; gap > 0; gap /=2)
for (i = gap; i < num; i++)
for (j = i - gap;
j >= 0 && comparator((char*)base+j*size, (char*)base+(j+gap)*size);
j -= gap)
{
pj = (char*)base + j * size;
pjgap = (char*)base + (j + gap) * size;
memmove(temp, pj, size);
memmove(pj, pjgap, size);
memmove(pjgap, temp, size);
}
free(temp);
}
A few comment could also help !!
thanks guys