Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/16/99 09:35
Read: times


 
#853 - Errors in DEC_DPTR routine
I download the file "DEC_DPTR.ZIP" that contains the file 'Dec_dptr.asm'.
in which the routine DEC_DPTR decrements by 1 the DPTR.
This file is included for reference at the end of this message.

In that file, is stated that "No other registers or flags will be affected. "
But after the instruction
CJNE A,#0FFh,DEC_DPTR_2
is executed, the carry flag is always affected. ( C=0, if DPL was 00, C=1 else).

The following instruction sequence, will really do the job without
affecting the flags and uses one code byte less.

Dec_Dptr: ;Bytes Cycles
xch a,DPL ;2 1
jnz Label1 ;2 2
;(CJNEA,0FFH,LABEL is 3 BYTES)
dec DPH ;2 1
Labe1:
dec A ;1 1
xch A,DPL ;2 1
ret ;2 2


Kostas Apostolakis
castel@x-treme.gr
-------------------------------------------------------------------------------------------------------------------------


The file "dec_dptr.asm" follows.
;#############################################################################
;# VAULT INFORMATION SERVICES - 8052 CODE EXAMPLE #
;# (C) Copyright 1997 by Vault Information Services #
;# #
;# This code fragment is provided to the public free of charge and WITHOUT #
;# OF ANY KIND, NEITHER EXPRESS OR IMPLIED. This code is offered as an #
;# example of 8052 programming. VIS extends no warranty regarding its #
;# functionality or fitness for a specific purpose.;# #
;# The user may utilize this code in any way he/she sees fit, including #
;# using it in his/her own program, commercial or otherwise. However, by #
;# using this code the user states his/her acceptance of the above and #
;# holds VIS indemnified against any and all claims that may arise due to #
;# the use or misuse of this code. #
;#---------------------------------------------------------------------------#
;# PURPOSE OF CODE FRAGMENT: The following code fragment includes a function #
;# called "DEC_DPTR." DEC_DPTR, when executed, will perform the exact #
;# opposite of the "INC DPTR" 8052 instruction--it will decrement the value #
;# in DPTR by one. No other registers or flags will be affected. #
;#############################################################################

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

END


No replies in thread

Back to Subject List