On Sat, 28 Oct 2000, Sean H. Breheny wrote: > Hi all, > > The recent flurry of code challenges has piqued my interest and I have > wanted to get in on it. Unfortunately, being very busy with school, I don't > have much time, but I thought I would throw out two simple code challenges: > > 1) The object is to take a number in the range of 0x0 to 0xF in W and > output the corresponding hex ASCII character 0 through 9 and A through F in > W, without any temp registers. You may affect STATUS. My code does it in 4 > cycles,isochronous, with no return. No great accomplishment considering how > simple the task, but I still ask, can anyone do it faster? OTTOMH addlw 6 skpndc addlw 'A'-('9'+1) addlw '0'-6 PIC 4-cycles is the fastest I've seen for this. > > 2) Same thing, except we now want to take a number in the range of 0x00 to > 0xFF in W and output two ASCII characters, the most significant character > into CHAR_HI and the least significant into W. No other registers can be > used. (NOTE: To solve this you will need some kind of routine to swap > CHAR_HI and W, as far as I can tell. I came up with a 3 cycle one, and then > found out that it was already listed on www.piclist.com. It would be > interesting to see if there are others). movwf char_hi swapf char_hi,w andlw 0x0f addlw 6 skpndc addlw 'A'-('9'+1) addlw '0'-6 xorwf char_hi,w xorwf char_hi,f xorwf char_hi,w andlw 0x0f addlw 6 skpndc addlw 'A'-('9'+1) addlw '0'-6 > > My resulting code is 15 cycles, isochronous Hmm, so is mine. But I bet Dmitry or Nikolai has a 12-cycle solution. Scott -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu