; Description:
; DPTR Points To An ETX Terminated String In External Memory. Count
; The Number Of ASCII Digits In The String. If The Number Of Digits
; Exceeds 255, Return CY == 1, Else Return Digit Count In Acc And
; CY == 0. DPTR Is Modified.
;
; Entry Requirements:
; DPTR Points To ETX Terminated String In External Memory
;
; On Exit:
; CY == 0, Acc Has Number Of Digits ('0'..'9') Found
; CY == 1, Number Of Digits Found Exceeds 255
; DPTR Points To ETX
;
; Affected:
; PSW.CY, PSW.Z, PSW.P, Acc, DPTR
;
; Stack:
; 1 Bytes, Not Including Space Used By Called Routines
;
; Comments:
; None
;
ETX equ 3 ; ASCII ETX Character
UTIL_CNTDG:
push 0 ; Save R0
mov r0,#0 ; Clear Counter
loop1: movx a,@dptr ; Get Character
cjne a,#ETX,temp ; Exit If End Of String
temp: jmp loop2 ;
inc dptr ; Next Character
cjne a,#'0',temp1 ; Skip If < '0'
temp1: jc loop1 ;
cjne a,#'9',temp2 ; Skip If > '9'
jmp temp3 ;
temp2: jnc loop1 ;
temp3: ;
inc r0 ; Increment Counter
mov a,r0 ; Get Counter
jnz loop1 ; Repeat Count
setb c ; Too Many Digits
pop 0 ; Recover R0
ret ; Return To Caller
;
loop2: mov a,r0 ; Get Count To Acc
clr c ; Clear For No Error
pop 0 ; Recover R0
ret ; Return To Caller
Source: Assorted Utilities, John C. Wren 11/23/96
Related topics:
8051 Program - unsigned divide | 8051 Program - unsigned mod | 8051 Program - signed divide | 8051 Program - signed mod | 8051 Program - sign fixup for divide | 8051 Program - divide | 8051 Program - memory subroutines | 8051 Program - math subroutines | 8051 Program - conversion subroutines
List of topics: 8051
No comments:
Post a Comment