> On Wed, 4 Feb 1998 13:42:50 -0500 Rob <
.....robzsKILLspam
.....HICOM.NET> writes:
> >I need to be able to have a 16 bit wide number and be able to
> >implement it
> >in a PIC (16C73). The 16 bit length is a counter for cycles (65535).
> >
> >How do I handle this? Check for overflow in one register and then
> >increment another register?
>
> Yes, obviously you need two 8-bit registers to store a 16-bit number. I
> usually allocate registers for numbers larger than 8 bits in
> "little-endian" form, meaning the MSB is immediately after the LSB in
> RAM.
>
> The most obvious way to increment it is to always increment the low byte,
> and increment the high byte if the low byte is 0 after incrementing:
>
> incf num_l,f ;Inc. low count (always).
> skpnz ;Skip if didn't roll over
> incf num_h,f ;Inc. high only if low rolled
> over
>
> If you had allocated the registers little-endian, then you could use
> 'num_l+1' (instead of 'num_h') to access the high byte. This saves
> having to label every byte like I did in the example above. The routine
> always takes 3 instruction cycles, regardless of the value of the number
> (there is a 2-cycle way to do a 16 bit count, but it's not for
> beginners). After the routine, the Z flag will be set if num_h also
> rolled over, indicating the number has counted beyond the maximum and is
> now 0000.
>
> _____________________________________________________________________
> You don't need to buy Internet access to use free Internet e-mail.
> Get completely free e-mail from Juno at
http://www.juno.com
> Or call Juno at (800) 654-JUNO [654-5866]