It is currently Tue Jun 02, 2020 6:03 pm

 All times are UTC

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: decimals, fractions, etc..Posted: Wed Feb 03, 2010 8:22 pm

Joined: Wed Feb 03, 2010 8:16 pm
Posts: 2
I am confused on how to get decimals in 68K.

For instance, if I want to divide 120 by 11 = 10.90

I have no idea how to get the .90 part. I understand you can get the remainder, but I need the fractional part.

Any help?

Top

 Post subject: Posted: Wed Feb 03, 2010 8:49 pm

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
Code:
ORG         \$1000

* divide longword 120 by word 11 to give a 16.16 bit fixed point result

start
MOVEQ       #120,d1           * set dividend
MOVEQ       #11,d0            * set divisor
DIVU.w      d0,d1             * divide 120 by 11
MOVE.w      d1,d2             * copy the result
SWAP        d2                * swap it to the high word
CLR.w       d1                * just leave the remainder * 65536
DIVU.w      d0,d1             * divide the remainder by 11
MOVE.w      d1,d2             * copy the fractional result

* this should leave the result \$000AE8BA in d2 which is the 16.16 bit
* fixed point equivalent of 10.90909

END         start

Lee.

Top

 Post subject: Posted: Wed Feb 03, 2010 11:10 pm

Joined: Wed Feb 03, 2010 8:16 pm
Posts: 2
What if you want to take the the number 000a.e8ba and multiply it with something? How does the computer know where the decimal point is?

Top

 Post subject: Posted: Thu Feb 04, 2010 12:54 am

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
The computer never knows where the decimal point is, it is up to you and your code to keep track of where it is.

Lee.

Top

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

 All times are UTC

Who is online

Users browsing this forum: No registered users and 7 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