; Description:
; Removes Trailing Spaces From A String In External Memory That Is
; <= R0 In Length By Placing An ETX Character At The First Non-Space
; Character From The End.
;
; Entry Requirements:
; DPTR Points To String In External Memory
; R0 Contains Index Into String To Start Search From
;
; On Exit:
; DPTR Points To Location ETX Stored To
; Acc = ETX
;
; Affected:
; PSW.Z, PSW.P, Acc, DPTR
;
; Stack:
; 5 Bytes, Not Including Space Used By Called Routines
;
; Comments:
; If No Spaces Are Found, An ETX Is Stored To The First Position In
; The String.
;
ETX equ 3 ; ASCII ETX Character
SPACE equ 32 ; ASCII Space Character
UTIL_TRIM:
push 0 ; Save R0
push dph ; Save DPH
push dpl ; Save DPL
;
mov a,r0 ; Get Length To Acc
dec a ; Make 0 Based, Not 1
call UTIL_ADCAD ; Point To Last Byte
loop1: movx a,@dptr ; Get Character From Buffer
cjne a,#SPACE,loop2 ; If Not Space, Exit
call UTIL_DPTRDEC ; Next Location Back
djnz r0,loop1 ; Repeat R0 Times
;
pop dpl ; Recover Buffer Start Low
pop dph ; Recover Buffer Start High
mov a,#ETX ; ETX Character
movx @dptr,a ; Store Terminator
pop 0 ; Recover R0
ret ; Return To Caller
;
; Now Get The Modem Index Number From The Modem Buffer, And Append It
;
loop2: inc dptr ; 1st Char Past Non-Space
mov a,#ETX ; ETX Character
movx @dptr,a ; Store Terminator
;
pop dpl ; Recover DPL
pop dph ; Recover DPH
pop 0 ; Recover R0
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 - return length of string | 8051 Program - memory subroutines | 8051 Program - math subroutines | 8051 Program - conversion subroutines
List of topics: 8051
No comments:
Post a Comment