It is currently Sat May 30, 2020 5:15 am

 All times are UTC

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Easy68k - Division Case (decimal point)Posted: Thu Nov 17, 2011 5:25 am

Joined: Wed Nov 16, 2011 4:27 pm
Posts: 1
Dear friends,

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.

Thank you.

Here's the source code I did:
Code:
CR    EQU    \$0D
LF    EQU    \$0A

START    ORG    \$1000

*-----------------------------------------------------------

A    LEA     AVALUE,A1
MOVE.B    #14,D0
TRAP    #15

MOVE.B    #4,D0
TRAP    #15
MOVE.L    D1,D2
BEQ    ZR

B    LEA     BVALUE,A1
MOVE.B    #14,D0
TRAP    #15

MOVE.B    #4,D0
TRAP    #15
MOVE.L    D1,D3
MOVE.L    D3,D4

SUB.L    D3,D2
MOVE.L    D2,D5
MOVE.L    D4,D6
DIVS.W    D6,D5

MOVE.L    D5,d1

MOVE.L    #3,D0
TRAP    #15

AVALUE    DC.B    'ENTER THE A VALUE =',0
BVALUE    DC.B    'ENTER THE B VALUE =',0

END    START

Top

 Post subject: Posted: Thu Nov 17, 2011 1:30 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
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.
http://en.wikipedia.org/wiki/Fixed-point_arithmetic
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
http://www.easy68k.com/codeLibrary.htm

_________________
Prof. Kelly

Last edited by profkelly on Thu Nov 17, 2011 6:03 pm, edited 1 time in total.

Top

 Post subject: Posted: Thu Nov 17, 2011 4:45 pm

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
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)

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Google [Bot] and 12 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ EASy68K Forum    FAQ    Latest Features    EASy68K Questions    68000 Programming Questions    Wish List    Wishes Granted    Undocumented Features    Documented Features    General Discussion    EASy68K Projects