;project 2
include irvine16.inc
.data
prompt byte "Enter a positive divisor: ", 0ah, 0dh, 0
prompt2 byte "Enter a positive dividend, larger than the divisor: ", 0ah, 0dh, 0
mess byte " is the GCD ", 0ah, 0dh, 0
notPrime byte "This integer is not prime.", 0ah, 0dh, 0
prime byte "This integer is prime, therefore the GCD of this integer and any other is: 1", 0ah, 0dh, 0
prime2 byte "This integer is prime, therefore the GCD is: 1", 0ah, 0dh, 0
num1 dword ? ;variable to hold the user's first number
num2 dword ? ;variable to hold the user's second number
.code
main proc
getFirstNum:
mov ax, @data
mov ds, ax
mov edx, offset prompt
call writeString
call ReadInt ;have to write this
cmp eax, 2
je exitLabel
;compare the number to its half
mov ebx, eax ;copy num
mov num1, eax ;copy num again so there is a space available for the second inputed num
shr ebx, 1 ;ebx == last, divides in half
mov ecx, 2 ;eax == 2
testifdone:
cmp ecx, ebx
ja alldone
xor edx, edx
div ebx ;leaves the remainder in edx
cmp edx, 0
je alldone
inc ecx
jmp testifdone
alldone:
cmp ecx, ebx ;compare the counter with last
ja primemessage
mov edx, offset notprime
;the number is not prime so we can try to find the
;gcd of this num and another num
call writestring
jmp getSecondNum
primemessage:
mov edx, offset prime
jmp print
;----------------------------------------------------------------------------------------------
getSecondNum:
mov edx, offset prompt2
call writestring
call ReadInt ;have to write this
cmp eax, 2
je exitLabel
;compare the number to its half
mov ebx, eax ;copy num
mov num2, eax
shr ebx, 1 ;ebx == last, divides in half
mov ecx, 2 ;eax == 2
testifdone2:
cmp ecx, ebx
ja alldone2
xor edx, edx
div ebx ;leaves the remainder in edx
cmp edx, 0
je alldone2
inc ecx
jmp testifdone2
alldone2:
cmp ecx, ebx ;compare the counter with last
ja primemessage2
mov edx, offset notprime
call writestring
jmp stuff
;the number is not prime so we can try to find the
;gcd of this num and another num
primemessage2:
mov edx, offset prime2
jmp print
stuff:
xor eax, eax
xor ecx, ecx
xor edx, edx
mov eax, num1
mov ecx, num2
getGCD:
div ecx ;puts the remainder into edx
cmp edx, 0
je gotGCD
mov eax, ecx
mov ecx, edx
xor edx, edx
jmp getGCD
gotGCD:
mov eax, ecx ;this is where the GCD needs to get stored
mov edx, offset mess
call writedec
jmp exitLabel
print:
call writeString
jmp exitLabel
;GCD(12,30) = 12/30 = 2R6; 6/12 = 2R0; therefore the GCD is 6
exitLabel:
exit
main ENDP
END main
I think my problem is occurring at the stuff label and down. Again, thank you for any and all help.

New Topic/Question
Reply


MultiQuote







|