EASy68K  
It is currently Thu Nov 14, 2019 5:42 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Feb 03, 2010 8:22 pm 
Offline

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
 Profile  
 
 Post subject:
PostPosted: Wed Feb 03, 2010 8:49 pm 
Offline

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
 Profile  
 
 Post subject:
PostPosted: Wed Feb 03, 2010 11:10 pm 
Offline

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
 Profile  
 
 Post subject:
PostPosted: Thu Feb 04, 2010 12:54 am 
Offline

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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 6 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group