Hey all,
Hopefully some of you know assembly. I'm using Boot Camp to do this, so there's my Mac tie-in. I trust this forum better.
I'm attempting to write an assembly program that performs Euclid's algorithm on two two-digit integers and then displays the highest common factor. We have to do the algorithm a certain way.
Here's the diagram of how it has to work: http://cl.ly/13FR
And here's my code: http://cl.ly/12iN
It's compiling beautifully with no errors (on the first try, no less!), so I'm guessing there's a problem with my logical flow here. It only works if A>B and if B is already the highest common factor. For example, 20 and 10, 40 and 20, 60 and 30...you get the idea. However it will only half work if you put in something like 66 and 33, or anything that will return an answer that doesn't end in zero. 66 and 33 produce an answer of 3N...which leads me to the second problem.
When we do the division, I'm dividing the answer by ten to get the first digit plus a remainder. I'm then multiplying the remainder by ten to get the second digit and then printing the two digits. According to my logic: say the HCF is 33 (as with 66=A and 33=B above), I would divide 33 by 10 to get 3 with a remainder of 3/10. I take the 3, convert it to ASCII and then save it. Then I take the 3/10, multiply it times ten, convert that answer to ASCII, and then store that. Then I print both digits. I'm guessing that I'm incorrect in thinking this way because I'm getting an "N" instead of a number as an output. That would mean me using the remainder from the division and converting that to ASCII is not actually what I want, since I'm getting a character, right?
Otherwise, if A<B or B is not already the highest common factor, the command prompt will freeze. It won't throw any errors, I just get Windows telling me to close the program because it's no longer responding.
I've commented this thing to death, so if anyone could read through it and see where my logic is flawed, I'd really appreciate it.
Thanks!
Hopefully some of you know assembly. I'm using Boot Camp to do this, so there's my Mac tie-in. I trust this forum better.
I'm attempting to write an assembly program that performs Euclid's algorithm on two two-digit integers and then displays the highest common factor. We have to do the algorithm a certain way.
Here's the diagram of how it has to work: http://cl.ly/13FR
And here's my code: http://cl.ly/12iN
It's compiling beautifully with no errors (on the first try, no less!), so I'm guessing there's a problem with my logical flow here. It only works if A>B and if B is already the highest common factor. For example, 20 and 10, 40 and 20, 60 and 30...you get the idea. However it will only half work if you put in something like 66 and 33, or anything that will return an answer that doesn't end in zero. 66 and 33 produce an answer of 3N...which leads me to the second problem.
When we do the division, I'm dividing the answer by ten to get the first digit plus a remainder. I'm then multiplying the remainder by ten to get the second digit and then printing the two digits. According to my logic: say the HCF is 33 (as with 66=A and 33=B above), I would divide 33 by 10 to get 3 with a remainder of 3/10. I take the 3, convert it to ASCII and then save it. Then I take the 3/10, multiply it times ten, convert that answer to ASCII, and then store that. Then I print both digits. I'm guessing that I'm incorrect in thinking this way because I'm getting an "N" instead of a number as an output. That would mean me using the remainder from the division and converting that to ASCII is not actually what I want, since I'm getting a character, right?
Otherwise, if A<B or B is not already the highest common factor, the command prompt will freeze. It won't throw any errors, I just get Windows telling me to close the program because it's no longer responding.
I've commented this thing to death, so if anyone could read through it and see where my logic is flawed, I'd really appreciate it.
Thanks!