Dave Birchall wrote: > I have found one possible soulution on a PIC FAQ but do not understand > the command 'BNC' I have waited but no one seemed to be answering this question or I missed it, so here goes. BNC is a pseudo-op which stands for Branch on Not Carry. It will branch the code to a LABEL if the Carry Flag is NOT set. It is used: BNC LABEL If you are counting cycles or if your assembler doesn't support it, it compiles to: BTFSS 3,0 ; Test if bit 0 of Register 3 (STATUS) is set. ; If set, then the next instruction is skipped. GOTO LABEL ; Thus, if the carry bit is NOT set, then this ; instruction will be executed and the flow will ; branch to LABEL IMHO the code that you posted doesn't work. It would loop forever. I have added code that I believe will do the job. I have denoted my code additions it by placing "@@@" in the expanded comments. Also be aware that some assemblers don't like blank lines, so you might need to take them out. ;@@@ equates for the destination register for operations so that we ;@@@ can use code such as: ;@@@ SUBWF REGISTER,w ;@@@ or ;@@@ ADDWF REGISTER,f w EQU 0 ;@@@ destination is the working register f EQU 1 ;@@@ destination is the file register ; ===== START OF OLD CODE HERE ===== ; ASCIIO will hold the working number and, later, the ONEs ASCII value ASCIIO EQU xxx ; xxx = A FILE REGISTER OF YOUR CHOOSING. ; ASCIIT will hold the TENs ASCII value ASCIIT EQU yyy ; yyy = ANOTHER FILE REGISTER. ; ASCIIH will hold the HUNDREDs ASCII value ASCIIH EQU zzz ; zzz = ANOTHER FILE REGISTER. ; ENTER WITH ORIGINAL 8-BIT VALUE IN "ASCIIO". ; EXITS WITH ASCII REPRESENTATION OF ONES' DIGIT IN "ASCIIO", ; TENS' DIGIT IN "ASCIIT", AND HUNDREDS' DIGIT IN "ASCIIH". ; Initialize the registers that will hold the ASCII values. NOTE that we ; should not initialize the ASCIIO register as it holds the number. CONVRT MOVLW '0' ; this places the number 48 (decimal) ; into the working register. 48 is the ASCII ; representation of the character '0' (zero). MOVWF ASCIIH ; copy it into the HUNDREDs register MOVWF ASCIIT ; copy it into the TENs register ; Check if the number is greater than 99 ; NOTE that the result of the subtraction is not used. The subtraction is ; being used solely to set the Carry Flag DO100S MOVLW d'100' ; place the value 100 (decimal) into the w regis ter SUBWF ASCIIO,w ; subtract 100 from the original number (held ; in the ONEs register) and place the result ; back in the working register. If the number ; less than 100, the carry flag will NOT be set. BNC DO10S ; If the carry flag is NOT set, then the ; number is less than 100. This means that ; the ASCII '0' that is already there is the ; correct number for the HUNDREDs digit. The ; BNC will branch past the next piece of code ; to handle the TENs next. ; If the code gets here then the original number is greater than 99. ; We will increment the ASCII value in the HUNDREDs register and subtract ; 100 from the working number held in ASCIIO. INCF ASCIIH,f ; increment the number in the HUNDREDs reg. ; ASCII 48 = '0', ASCII 49 = '1', etc. MOVLW d'100' ;@@@ put 100 back into the working register SUBWF ASCIIO,f ;@@@ subtract 100 from the original number but ; this time place the result back into the ONEs ; register. This will be the new working number. GOTO DO100S ; jump back up and repeat the 100's test. ; NOTE: Since the highest number that it is ; possible to place in an 8-bit register is 255, ; you needn't worry about incrementing above ; the legal ASCII numeric characters. ; Here we will essentially do the same thing to the TENs register that we did ; with the HUNDREDs above. DO10S MOVLW d'10' ; place the value 10 (decimal) into the w regist er. SUBWF ASCIIO,w ; subtract 10 from the working number (held ; in the ONEs register) and place the result ; back in the working register. If the number ; less than 10, the carry flag will NOT be set. BNC DO1S ; If the carry flag is NOT set, then the ; number is less than 10. This means that ; the ASCII '0' (48 decimal) is the correct ; number for the TENs digit. The BNC will ; branch past the next piece of code to handle ; the ONEs next. ; If the code gets here, the tens digit isn't zero INCF ASCIIT,f ; Increment the number in the TENs register. ; ASCII 48 = '0', ASCII 49 = '1', etc. MOVLW d'10' ;@@@ put 10 back into the working register. SUBWF ASCIIO,f ;@@@ subtract 10 from the working number but ; this time place the result back into the ONEs ; register as the new working number. GOTO DO10S ; Jump back up and repeat the 10's test. Each ; time through we will add 1 to the ASCII value ; in the TENs register, thus incrementing the ; ASCII number. ; Here we can have only 0-9 in the ASCIIO register. If we add it to an ASCII '0' ; it should produce the last digit for us. DO1S MOVLW '0' ; move the ASCII value for zero (48 decimal) int o ; the working register. ADDWF ASCIIO,f ; add the number to get the ASCII value for it. I hope I have not made any obvious errors, and that it will help you. Michael When the way of the Tao is forgotten, kindness and ethics must be taught. Men must learn to pretend to be wise and good. -- Lao Tzu