piclist 2001\01\10\145841a >
Thread: yet another algorithm challange
www.piclist.com/techref/microchip/devices.htm?key=pic
picon face BY : Drew Vassallo email (remove spam text)



> >Interesting, because a lookup table would be only 15 lines by my
> >calculations for 2x mode.  1 byte returned for each nibble 0-F.  6x is
> >another story, 3 bytes per nibble, but maybe that could be simplified.
>
>How would that look, in code? I've seen the PIC idiom for lookup table
>that has a branch at the start, and N occurrances of RETLW xxx, but
>can't find an example at hand. Is this what you mean?

For 2x, this would be (and yes, it could probably be more elegant):

;;Result of 2x original byte is in Converted_Number (LSB)
;; and Converted_Number + 1 (MSB)
CBLOCK 0x0C
 Base_Number
 Converted_Number:2
ENDC

 movf Base_Number, w    ; in your example, "0xA1" moves to W
 swapf Base_Number, f   ; force "A" to lower nibble
 andlw 0x0F             ; Mask off the upper nibble
 call Get_2x_Conversion
 movwf Converted_Number ; dump off lower byte
 movf Base_Number, w
 andlw 0x0F             ; mask off the upper nibble
 call Get_2x_Conversion
 movwf Converted_Number + 1  ; dump off upper byte

Get_2x_Conversion
;; Conversion is 0->0, 1->3, 2->C, 3->F for each bit pair
;; Make sure you watch PCLATH and compensate accordingly
  addwf PCL
dt 0x00, 0x03, 0x0C, 0x0F, 0x30, 0x33, 0x3C, 0x3F, 0xC0, 0xC3, 0xCC
dt 0xCF, 0xF0, 0xF3, 0xFC, 0xFF


Actually, now that I did this table on paper, it's obvious that you can just
use bit pairs for lookups (ie., 0, 3, C, and F).  Mask off the unused bits
and send the remaining bit pair to the lower nibble.  This reduces your
table to only 4 lines, but increases your code length.  I'd say you could do
this pretty easily.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email KILLspamlistservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


<F2727AHfo98xKLVXfEF00001bc2@hotmail.com>

See also: www.piclist.com/techref/microchip/devices.htm?key=pic
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) yet another algorithm challange

month overview.

new search...