; Description:
; DPTR Points To A String In External RAM To Determine The Length Of.
; The String Must Be 0 Terminated, And Less Than 256 Bytes In Length.
; The Length Is Returned In Acc.
;
; Entry Requirements:
; DPTR Points To An ETX Terminated String In External Memory
;
; On Exit:
; DPTR Points To ETX
; Acc Has Length Of String
;
; Affected:
; PSW.CY, PSW.Z, PSW.P, Acc
;
; Stack:
; 3 Bytes, Not Including Space Used By Called Routines
;
; Comments:
; If String Is Longer Than 255 Bytes, Acc Will Report Length Mod 256
;
ETX equ 3 ; ASCII ETX Character
UTIL_STRLEN:
push b ; Save B
push dph ; Save DPH
push dpl ; Save DPL
mov b,#0 ; Clear Length Counter
;
loop1: movx a,@dptr ; Get Byte
cjne a,#ETX,temp ; If ETX, End Found
temp: jmp loop2 ;
inc dptr ; Next Location
inc b ; Increment Length
jmp loop1 ; Repeat Until 0x00
;
loop2: mov a,b ; Get Length To A
pop dpl ; Recover DPL
pop dph ; Recover DPH
pop b ; Recover B
ret ; Return To Caller
Source: Assorted Utilities, John C. Wren 11/23/96
Related topics:
8051 Program - replace 0x00 with ETX in string | 8051 Program - locate ETX in string | 8051 Program - remove trailing spaces | 8051 Program - memory subroutines | 8051 Program - math subroutines | 8051 Program - conversion subroutines
List of topics: 8051
No comments:
Post a Comment