On Mon, Aug 01, 2005 at 03:04:52PM -0300, luis wrote: > Hi all, > > I?m looking a rotine in asm to INC ou DEC 2 packed BCD numbers. > For example: 00000100 10011001 (499) + 1 = 00000101 00000000 (500) I have conversion routines in my sunrise/sunset outdorr light controller. You can find it here: http://www.finitesite.com/d3jsys/clock.asm The hex2bcd routine converts a hex number to its BCD equivalent. However, the principles are the same: 1) Each digit needs to be checked to see if it's greater than 9. Digits greater than 9 need to be compensated by adding/substracting 6. So for your example (switching to hex for simplicity): 0499 + 1 Increment --------------- 049A Check for overflow in LSD. It's greater than 9 so adjust + 6 --------------- 04A0 Last digit adjusted. Work on next digit. Compensate 60 --------------- 0400 On the upper nybble you need to check carry. It carried so 100 You need to increment the low nybble of the high byte ----------------- 0500 You check the low nybble of the high byte to see if it overflowed. It didn't so you are done. Now the decrement is interesting. You have to subtract 6 to compensate and take one away from the succeeding digit. Let's try decrementing 1000. 1000 - 1 Take away one. ------------------- 10FF Compensate for borrow in MSB -100 ----- 0FFF Now start compensating for digits. - 6 ----- 0FF9 -060 ----- 0F99 -600 ----- 0999 No need to do the MSD. That should be enough to get you going. BAJ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist