|Easy68k - Division Case (decimal point)
|Page 1 of 1|
|Author:||ulyses [ Thu Nov 17, 2011 5:25 am ]|
|Post subject:||Easy68k - Division Case (decimal point)|
I've just received my task for microprocessor class. The question given is, R = (A-B) / (A+B). The problem is, I don't know how to display the results in decimal point. (Such, 2 divide by 4 equal to 0.5). I need your help to solve the problem.
Here's the source code I did:
CR EQU $0D
LF EQU $0A
START ORG $1000
A LEA AVALUE,A1
B LEA BVALUE,A1
AVALUE DC.B 'ENTER THE A VALUE =',0
BVALUE DC.B 'ENTER THE B VALUE =',0
|Author:||profkelly [ Thu Nov 17, 2011 1:30 pm ]|
Have you verified with the instructor that your solution must display decimal numbers?
If so, the simplest solution would be to use fixed point math.
There are also several posts on this forum about doing
fixed point math. Try searching the forum for more examples.
If you need a floating point solution check out the Fast-Floating-Point code provided by Paul R. Santa-Maria on the Examples page
|Author:||clive [ Thu Nov 17, 2011 4:45 pm ]|
Your could also look at the remainder, and pull the information from there
R = (A-B) / (A+B) ; integer digits
S = (A-B) % (A+B)
Then repeating for each decimal place
S = S * 10
T = S / (A+B) ; fractional digit
S = S % (A+B)
|Page 1 of 1||All times are UTC|
|Powered by phpBB® Forum Software © phpBB Group