She works! After an insane amount of debugging, she finally works! I had to do 64 bit division by doing 32 at a time. I was trying to make it harder than it really was. Now that I know how, I could do any size of numbers, though I think anything beyond 2 ^ 64 would take longer than anyone would care to wait for. The time command seems to show pretty much the same time for anything I put in, so I'm a little skeptical of what it's saying. The time should be proportional to the square root of what you factor. But anyway, here's the new revised source code. Compile it the same as before. And I removed that isnumber crap so you shouldn't have to edit this to get it to work. This is a winner for sure. By the way, I was so frustrated that I didn't comment a lot of the new stuff. I doubt anyone was interested in looking through the assembler code anyway.

main.c:

factor.asm:Code:#include <stdio.h> #include <math.h> #include <stdlib.h> #include <limits.h> extern void factor(long long); unsigned long square_root(unsigned long long number) { double temp; temp = (double)number; temp = sqrt(temp); number = (unsigned long long)temp; return number; } int main(int argc,char *argv[]) { unsigned long long number; if(argc != 2) { printf("You must type in a single factor for a parameter.\n"); return 1; } number=strtoull(argv[1],0,10); factor(number); return 0; }

Code:SEGMENT .data fmt db '%lu %llu',10,0 number dd 0,0 sroot dd 0 extern printf extern square_root global factor quotient dd 0,0 SEGMENT .text factor: push esi push edi push ebx mov ebx,esp add ebx,010h mov eax,[ebx] mov [number+4],eax add ebx,04h mov edx,[ebx] mov [number],edx ; that was complicated but now we have the parameter passed from main in number push dword [number] push dword [number+4] call square_root mov [sroot],eax add esp,08h mov ecx,0h ; ecx will be incremented in the loop and we want to start factoring with 1 find_factors: inc ecx cmp ecx,[sroot] ; if ecx has passed root, return jng divide pop ebx ; let's return cleanly to mother pop edi pop esi ret divide: mov edx,0 ; dividing little pieces at a time mov eax,[number] ; high 32 bits of dividend div ecx ; divide by the divisor mov [quotient],eax mov eax,[number+4] div ecx mov [quotient+4],eax cmp edx,0 ; is remainder 0? jnz find_factors ; next factor if remainder push ecx ; preserve ecx push dword [quotient] ; pass the quotient push dword [quotient+4] push ecx ; pass our factor push dword fmt ; pass the format string call printf ; let's do this the easy way and use printf add esp,010h ; clean up after printf pop ecx jmp find_factors ; continue with the next factor

## Bookmarks