Jump to content
Sign in to follow this  
dmb

32 by 16 bit into 24 bit division

Recommended Posts

i have to divide a 32 bit (40000000h) by 16 bits, need a 24bit result...

 

does anyone have some working sample code?

Share this post


Link to post
Share on other sites

Since c2c implements integers as 16-bit, I think the only way to get a 24-bit result is to write it yourself in assembly.  You can't force the integers to be 24-bit if that functionality is not provided in the compiler.  

 

Your 32-bit integer, though, can probably be implemented with two 16-bit integers.  You just need to make sure that when the lower-int overflows, you need to increment the upper-int.  If the upper-int underflows, you will need to increment the lower-int.  You can usually check for overflow conditions with the STATUS reg's CARRY bit.  For underflow, if the MSB bit flips as a result of a arithmetic operation, then you know an underflow has occurred.

 

pic-dude

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...