![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2005
Posts: 17
Rep Power: 0
![]() |
Could anyone please convert this into assembly ?
Could someone please convert this code into assembly for me to see ?
and btw is the only way to convert HL lanuage into assembly is by using linux ? void quickSort(int numbers[], int array_size)
{
q_sort(numbers, 0, array_size - 1);
}
void q_sort(int numbers[], int left, int right)
{
int pivot, l_hold, r_hold;
l_hold = left;
r_hold = right;
pivot = numbers[left];
while (left < right)
{
while ((numbers[right] >= pivot) && (left < right))
right--;
if (left != right)
{
numbers[left] = numbers[right];
left++;
}
while ((numbers[left] <= pivot) && (left < right))
left++;
if (left != right)
{
numbers[right] = numbers[left];
right--;
}
}
numbers[left] = pivot;
pivot = left;
left = l_hold;
right = r_hold;
if (left < pivot)
q_sort(numbers, left, pivot-1);
if (right > pivot)
q_sort(numbers, pivot+1, right);
} |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Aug 2004
Location: The Netherlands
Posts: 111
Rep Power: 5
![]() |
i suppose you want it on windows?
i would do this: compile the program and open the exe with a disassembler like ollydbg or win32dasm. now you will have the assembly code of the program. if you know assembly well enough then it shouldn't be much of a problem reading it and writing it in an .asm file.
__________________
http://www.white-scorpion.nl |
|
|
|
|
|
#3 |
|
Expert Programmer
|
there are ways to do it with a compiler switch. Do some research. Come back if you need more help.
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jan 2005
Posts: 17
Rep Power: 0
![]() |
a complier switch, so i can basically stick in like visual.net but with a different switch ?
btw , how would i pass the function parameters using stack call, instead of register or memory ? if it was written in x86 asm already. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jan 2005
Posts: 17
Rep Power: 0
![]() |
so no one can convert it for me ? :\
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0
![]() |
I'll do it, just wait till I get a chance.
Probably by Monday or Tuesday.
__________________
Small is beautiful Last edited by liquidsilver; Mar 11th, 2005 at 6:18 AM. Reason: mistake made |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0
![]() |
I had some time so here we go:
ArraySize db 4 ;largest entry (number of entries - 1) Array db 00h,02h,01h,03h,04h Left db ? Right db ? Pivot db ? lHold db ? rHold db ? QSort proc mov lHold,0 mov al,Arraysize mov rHold,al mov al,Array mov Pivot,al StrWhile1: mov al,Left cmp al,Right jge EndWhile1 StrWhile2: mov di,offset Array xor bx,bx mov bl,Right mov al,[di+bx] cmp al,Pivot jl EndWhile2 mov al,Left cmp al,Right jge EndWhile2 mov al,Right dec al mov Right,al EndWhile2: mov al,Left cmp al,Right jz EndIf1 mov di,offset Array xor bx,bx mov bl,Right mov al,[di+bx] mov di,offset Array xor bx,bx mov bl,Left mov [di+bx],al mov al,Left inc al mov Left,al EndIf1: StrWhile3: mov di,offset Array xor bx,bx mov bl,Left mov al,[di+bx] cmp al,Pivot jg EndWhile3 mov al,Left cmp al,Right jge EndWhile3 mov al,Left dec al mov Left,al EndWhile3: mov al,Left cmp al,Right jz EndIf2 mov di,offset Array xor bx,bx mov bl,Left mov al,[di+bx] mov di,offset Array xor bx,bx mov bl,Right mov [di+bx],al mov al,Right dec al mov Right,al EndIf2: EndWhile1: mov al,Pivot mov di,offset Array xor bx,bx mov bl,Left mov [di+bx],al mov al,Left mov Pivot,al mov al,lHold mov Left,al mov al,rHold mov Right,al mov al,Left cmp al,Pivot jge EndIf3 mov al,Pivot dec al mov Right,al call QSort EndIf3: mov al,Right cmp al,Pivot jle EndIf4 mov al,Pivot inc al mov Left,al call QSort EndIf4: ret QSort endp I haven't checked this for errors or done any optimization, you can do that. This will be easier to read this way. I haven't even passed variables to the function, I've just created some globals, I hope that doesn't mess up the recursion that takes place. Unless I'm horribly mistaken, you're trying to do a simple sort. Search the net for a more optimized version and in future first search the net, then you can find exactly what you're looking for. ![]()
__________________
Small is beautiful |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Jan 2005
Posts: 17
Rep Power: 0
![]() |
Wow thanks so much Liquidsilver !!
I kinda know what you are doing, but kinda not too ... not sure if it is the format problem, sorry im a newbie..
void q_sort();
void quickSort(int numbers[], int array_size)
{
__asm
{
push eax
push ebx
push ecx
push edx
push edi
push esi
//START
.......
//END
pop esi
pop edi
pop edx
pop ecx
pop ebx
pop eax
}
}
__declspec(naked)
void q_sort()
{
__asm
{
//START
........
//END }
}that's frame that I suppose to code this quicksort into, basically I have pass the function parameters using stack call ?? (Which I have no clue how.. ) It seem like you just have a whole function without calling the other function. Again, I am newbie, can't really understand it that well, espeically when you do the xor bx,bx.. that was really confusing And yea, i did search the net, but the way they do thier asm is like linux or something, not like what I learned, but I did find this site http://cs.hofstra.edu/~cscccl/csc111/qsort.asm which is pretty close to what I am trying to do, but still, he uses ;; [ebp+8] is start address, [ebp+12] is end address of partition and i don't know how would i make the frame thats given to me with the start address, and the end address, so im stucked here again. Sorry for such a long reply, you are very helpful ! thanks Last edited by oxyi; Mar 12th, 2005 at 1:38 AM. |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Mar 2005
Location: South Africa
Posts: 21
Rep Power: 0
![]() |
I can't help you much more, I suck at C, but I think I can help a bit.
I thought you wanted it for use in pure assembly, I don't know to call it from C. Also, my function refers to global variables for the arguments, this isn't a good way, but I did that as it's easier to understand. Yes I do only have one function. And if you xor a value by itself then it becomes 0. In that file you found they used the stack for the variables, this is the better way, but I didn't do it as I thought you wouldn't understand. The arguments are pushed onto the stack and then the function refers to that memory instead. I can't help you call the function from C, I don't know how, sorry. I suggest you type the whole program in assembly or C, I can't help with mixing the two.
__________________
Small is beautiful |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Jan 2005
Posts: 17
Rep Power: 0
![]() |
Oh, it's okay , it has nothing to do with C (i think
) but it is just asssembly embedded in C, and your explantion did clear up some of my problem too ;] thank you so much for that ! I will try to code it tomorrow see how it goes ;] ty |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|