firstNUM SDWORD ?
firstDEN SDWORD ?
secNUM SDWORD ?
secDEN SDWORD ?
prompt BYTE "Please enter a two numerators and two denominators for two fractions.", 0
prompt2 BYTE "Please enter the first numerator: ", 0
prompt3 BYTE "Please enter the first denominator: ", 0
prompt4 BYTE "Please enter the second numerator: ", 0
prompt5 BYTE "Please enter the second denominator: ", 0
prompt6 BYTE "The first fraction you entered is: ", 0
SDWORD firstNum, "/", firstDEN, 0
prompt7 BYTE "The second fraction you entered is: ", 0
To output the fraction, of course you need to convert both the numerator and denominator to decimal ASCII strings and then output those. Doesn't your library have a function for that? What needs to be done is the reverse of what ReadDec obviously does internally with a character string read in from the console and stored into an internal buffer. (It actually may do that on the fly without buffering as well, but that wouldn't change anything about the principle.)
In case your library doesn't have a binary-to-decimal conversion function, you can't find documentation on that process (which I consider to be unlikely) and/or just to quench your curiosity: Here's a thread that discusses exactly that topic: http://www.codeguru.com/forum/showthread.php?t=503267.
Wh1t3gh0st
November 8th, 2011, 02:14 PM
Thanks, this is my resolved diplaying fraction after the last line, but for some reason it outputs a
+(number entered)/+(number entered).
Another question how would you reduce that fraction after multiplying two fractions? More code coming...
Wh1t3gh0st
November 8th, 2011, 03:17 PM
This is my code after multiplying. Now I have a problem when I enter a negative number. The number results in a +0. Why and how to make it say -(Number). I am using the signed and imul, so I don't know what the problem is. Also I know that I need to use the cmp instruction when reducing just don't know how to completly do it.
firstNUM SDWORD ?
firstDEN SDWORD ?
secNUM SDWORD ?
secDEN SDWORD ?
newNUM SDWORD ?
newDEN SDWORD ?
prompt BYTE "Please enter a two numerators and two denominators for two fractions.", 0
prompt2 BYTE "Please enter the first numerator: ", 0
prompt3 BYTE "Please enter the first denominator: ", 0
prompt4 BYTE "Please enter the second numerator: ", 0
prompt5 BYTE "Please enter the second denominator: ", 0
prompt6 BYTE "The first fraction you entered is: ", 0
prompt7 BYTE "The second fraction you entered is: ", 0
prompt8 BYTE "The result of multiplying the two fractions together is: ", 0
Naturally, I have no idea of what's going on inside that library you use. Hopefully you have proper documentation on that library or its source code to aid you in finding out. But even without the library source code you may find out some things by stepping into the library code with your debugger. After all, in assembly language source code and object code aren't too far away from each other anyway. Perhaps all that you're observing actually is somehow by design of the library. And, of course, first thing you should do is make sure that you actually are passing correct data to the library functions - by debuging your own code.
One thing I can tell you, thogh: Yes, IMUL is the correct instruction for signed integer multiplication. But you probably already knew that anyway...
Another question how would you reduce that fraction after multiplying two fractions?
In assembly language that doesn't work differently than in any other language (except perhaps in some language specifically geared towards arithmetic/math that provides readily available instructions for that) - just like you would do it with an ordinary calculator - or with pencil and paper... Perhaps this is helpful in fortifying your background on fractional multiplication: http://en.wikipedia.org/wiki/Fraction_(mathematics)#Multiplication
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.