---------- From: Carlo Scoccia To: PICLIST@MITVMA.MIT.EDU Subject: Re: BCD Counting Techniques & Examples Date: Saturday, October 17, 1998 2:07 AM Hmmm.... OK, everything is really smart ... but what about division and multiplication ? Carlo Scoccia bas033k1@bassano.nettuno.it ******************** To answer Carlo Scoccia's question about handling division and multiplication with regards to using accumulation of data in BCD format (instead of using binary): *If* you mean how could we handle stuff like "divide that sucker by 13", then we would use a "prescaler" method. The subroutine would have a counter that counts from 0 to 12. When the count goes from 12 to 13, the counter would be reset back to 0, and *then* the BCD counter would be incremented. *If* you mean how could we handle stuff like "multiply that sucker by 17", then everywhere that we would normally have done a straight increment of the BCD counter set we would *instead* ADD 17. (This can be done by feeding the increment routine 17 increment requests, or by implementing an actual ADD 17 routine) *If* you mean how could we handle stuff like "multiply by 17 and divide by 13", then every input "increment" could trigger the sending of 17 counts to the divide by 13 prescaler, which would then eventually pass 17/13 counts on to the actual BCD increment routine. .............. Again, I am *not* saying that such methods are the optimal way to handle such requirements, but only that *at times* such methods might be quite appropriate. I put forward these posts in the hope that *someone* finds them helpful at some time or another. There are a number of fine programmers on this list who produce really excellent (and elegant) *optimal* code that is tweaked to cut the number of operating cycles down to a minimum. I am sure that they themselves would be the first to acknowledge that often such optimized code is difficult for a beginner to understand. Sub-optimal but fully operational and properly functional code that is intuitive and easy to understand also has its place, especially for beginners. By the way, I greatly appreciate the optimized code that is posted on this list and also made available on various websites of PIC list members. I am especially appreciative of optimized code that is fully and clearly commented to show the underlying logic. Whenever utilizing a 'trick', it is good practice to explain clearly what is being done. Otherwise others can only admire and use it. They can't learn from it unless it is well-commented. My thanks to all of those who do provide such tutorial comments. Hope this helps. Fr. Tom McGahee