; Description:
; Decrement DPTR. CY == 1 If Underflow
;
; Entry Requirements:
; DPTR Has Value To Decrement
;
; On Exit:
; DPTR = DPTR - 1, CY Set Accordingly
;
; Affected:
; PSW.CY, DPTR
;
; Stack:
; 1 Bytes, Not Including Space Used By Called Routines
;
; Comments:
; None
UTIL_DPTRDEC:
push acc ; Save Acc
clr c ; Clear For SUBB
mov a,dpl ; Move Low Of DPTR To A
subb a,#1 ; Subtract 1
mov dpl,a ; Store Back
mov a,dph ; Get High Of DPTR
subb a,#0 ; Subtract CY If Set
mov dph,a ; Move Back
pop acc ; Recover Acc
ret ; Return To Caller
Source: Assorted Utilities, John C. Wren 11/23/96
; another approach
DEC_DPTR:
XCH A,DPL ;Exchange A for DPL
DEC A ; Decrement A (which is DPL)
CJNE A,#0FFh,_dec_dptr2 ; If A (DPL) is not #0FFh, continue normally
DEC DPH ; If A=FFh, we need to decrement DPH
_dec_dptr2: XCH A,DPL ; Exchange A for DPL (thus saving DPL and restoring A)
RET
Related topics:
8051 Program - add acc to dptr | 8051 Program - add ba to dptr | 8051 Program - subtract acc from dptr | 8051 Program - subtract ba from dptr | 8051 Program - 2s complement dptr | 8051 Program - memory subroutines | 8051 Program - math subroutines | 8051 Program - conversion subroutines
List of topics: 8051
Thank you very much, it helped a lot❤️
ReplyDelete