Prime Factors
I'm working on a program that will find the prime factors to an unsigned integer that is entered by the user. I just have to make sure the program can handle a number up to 1000. I'm writing assembly in x86. I have already got a prompt for the user and got the number from the user, but I don't know how to go from here. I know I have to find the prime factors that make up that number using a jump loop and using divide, but I'm kinda lost here. Any help would be appreciated.
Thanks for the help.
Sincerely yours;
jdm
TITLE MASM Template (main.asm)
INCLUDE Irvine32.inc
.data ;Declare values
myMessage BYTE "Enter an unsigned integer: ", 0 ;Stores a string
myMessage2 BYTE " ",0dh,0ah, 0 ;Stores a string
.code ;Declare main
main PROC ;Declare proc
call Clrscr ;Clears the screen
mov eax, 0 ;Clear eax
mov ebx, 0 ;Clear ebx
mov ecx, 0 ;Clear ecx
mov edx, OFFSET myMessage ;Mov message into edx
call writestring ;Display to screen
call readdec ;Reads the input number and store into eax in decimal form.
call writedec ;Display the value located in eax in decimal form on screen.
mov edx, OFFSET myMessage2 ;Mov message into edx
call writestring ;Display to screen
exit ;Exit main
main ENDP ;Exit proc
END main ;Tells the program that it is the end
jdm
Junior Poster in Training
55 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
This code:
mov edx,0
cmp eax,1
jle mEx
mov ecx,eax
shr ecx,1
mov ebx,2
mov edx,1
mMain:
cmp ebx,ecx
jg mEx
push eax
mov edx,0
div ebx
pop eax
cmp edx,0
je mEx
inc ebx
jmp mMain
mov edx,1
mEx:
checks if number in eax is prime. If it is prime edx will contain 1, otherwise 0. Insert this code before line 25. Number up to 1000 are fine.
Thank you for the help Skaa, I will give it a try, but I was wondering if it does what I need it too. I haven't really study push or pop or shr yet. What I need to do for example is have the user put the int 20 into the program, the program will display 2 * 2 * 5 as the prime factors that make up 20.
I really appreciate the help.
Sincerely yours;
jdm
jdm
Junior Poster in Training
55 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
Thank you for the help Skaa. I really appreciate it. I'm taking it that the program doesn't accept 0 and 1, because they are not prime?
Thanks for the help again.
Sincerely yours;
jdm
jdm
Junior Poster in Training
55 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
Thanks for the help. I really do appreciate it.
Sincerely yours;
jdm
jdm
Junior Poster in Training
55 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0