Jump to content
Sign in to follow this  
rikpat

8x8 multiplication

Recommended Posts

Hello,

 

Is there someone that has some c-code examples on how to multiply two 8 bit variables in to 2 other variables?

 

example: 0xff X 0xff = FE01

 

ResultH = FE

ResultL = 01

 

patrick

Share this post


Link to post
Share on other sites

This has been posted for a while now and nobody has answered the question yet. Well, I don't know te answer either. YOu might want to check out this page. It gives you some examples but they are in assembler. http://www.piclist.com/techref/microchip/math/mul/index.htm

 

I haven't tried anything yet but perhaps instead of multiplying you should try ADDING.

 

for example 4x3 is really 4+4+4

 

So, maybe if you do a special function where it has a few counters. I think everytime there is an over flow there is a carry flag in one of the special register that get set. So you could do 0xff +0xff one time and the check the carry flag. then calle  a second function to store a number or something. then add another 0xff so on and so forth. THe point is ytou cannot have a number higher that 255. but you can have many 255 store in different places. then you could have a 3rd function that puts all teh counters together and give you the number you want.

 

THis is just a basic idea of the top ofmy head. I haven't ested this out yet and I'm sure there is a more efficient way of doing this. I hope that if this doesn't help maybe it will give you or somebody more ideas and come up with something. If you solve the problem please post it here so that we can all benefit.

Share this post


Link to post
Share on other sites
Guest Dave

Unless I'm missing the point, this is what you want:

main() 
{
       char num1, num2;
       int res;

       num1 = 20;
       num2 = 128;
       res = num1 * num2;
}

 

res ends containing a value of 20 * 128 = 2560

 

 

Regards

Dave

:D

Share this post


Link to post
Share on other sites

Now I have a question on this subject. I though the maximum number a counter or register can have is 255. Are you saying that C2C is smart enought to make the necesarry arangements so that a numbers bigger than 255 can be stored?

 

On a non related subject. When are we going to get a C level debuger?

Share this post


Link to post
Share on other sites
Guest Pavel
I though the maximum number a counter or register can have is 255. Are you saying that C2C is smart enought to make the necesarry arangements so that a numbers bigger than 255 can be stored?

The compiler works with 8 and 16 bit long data types. The max values it can handle is 0xFFFF or 65535.

On a non related subject. When are we going to get a C level debuger?

You will. A new compiler that will support C level debugging is under development.

 

Regards,

Pavel

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...