On Tuesday myke predko wrote: > Does anybody see any problems with the routine below or a better way to > do it? No problems, but you can make it a wee bit smaller and a little bit more general. The following 6 lines are duplicated: > andlw 0x00F > addlw '0' + 6 ; Is it too Large for '0' to '9'? > btfsc STATUS, DC > addlw 'A' - ( '0' + 10 ) ; Yes, Make it "A" to "F" > addlw 0 - 6 ; Convert Back to Valid Number > call LCDCHAR So they can be turned into a function like this: DispHexDigit andlw 0x00F addlw '0' + 6 ; Is it too Large for '0' to '9'? btfsc STATUS, DC addlw 'A' - ( '0' + 10 ) ; Yes, Make it "A" to "F" addlw 0 - 6 ; Convert Back to Valid Number goto LCDCHAR ; save a return, we'll use the one in LCDCHAR And now DispHex looks like this: DispHex movwf Temp swapf Temp,w call DispHexDigit movf Temp,w goto DispHexDigit ; the above line is a faster smaller version of ; call DispHexDigit ; return ; It also uses one less stack level. Thus eliminating 7 words at the cost of code readability. Now, we'll make it a little more flexible and even harder to read. We don't need to limit ourselves to base 16, we can support anything up to base 36 in our digit display routine. This is usefull when we want to cram just a little bit more information onto our tiny little LCD screen. DispHexDigit ; this will display the low 4 bits of W in Hex andlw 0x00F DispDigit ; This entry is good for any base up to base 36 addlw 0 - 10 ; Is it larger than 9? btfsc STATUS, C addlw 7 ; or ('A' - '0') - 10 addlw 10 + '0' goto LCDCHAR Let me know if this is clear enough, my toddler is demanding attention. -- paulh@hamjudo.com http://www.hamjudo.com The April 97 WebSight magazine describes me as "(presumably) normal".