incf W ??
Postat: 25 oktober 2008, 22:43:05
Dvs:
Noterade att raden "incf W" rör ett helt annat register, 0x55? wrwg är 00 före och efter instruktionen?? Vad katten är fel?
Kod: Markera allt
;******************************************************************
; Convert 32-bit binary number in REGA into a bcd number
; at <bcd>. Uses Mike Keitz's procedure for handling bcd
; adjust; Modified Microchip AN526 for 32-bits.
b2bcd
btfss rega3,7 ;Check if egative
goto positive ; No
xorlw 0xff ; Yes, make positive
movwf rega3
movf rega2,W
xorlw 0xff
movwf rega2
movf rega1,W
xorlw 0xff
movwf rega1
movf rega0,W
xorlw 0xff
incf W
movwf rega0
movlw '-' ; and et sign
movwf sign
goto positive1
positive
movlw '+'
movwf sign
positive1
movlw .32 ; 32-bits
movwf mcount ; make cycle counter
clrf bcd ; clear result area
clrf bcd+1
clrf bcd+2
clrf bcd+3
clrf bcd+4
b2bcd2
movlw bcd ; make pointer
movwf fsr
movlw .5
movwf cnt
; Mike's routine:
b2bcd3 movlw 0x33
addwf indf,f ; add to both nybbles
btfsc indf,3 ; test if low result > 7
andlw 0xf0 ; low result >7 so take the 3 out
btfsc indf,7 ; test if high result > 7
andlw 0x0f ; high result > 7 so ok
subwf indf,f ; any results <= 7, subtract back
incf fsr,f ; point to next
decfsz cnt
goto b2bcd3
rlf rega0,f ; get another bit
rlf rega1,f
rlf rega2,f
rlf rega3,f
rlf bcd+4,f ; put it into bcd
rlf bcd+3,f
rlf bcd+2,f
rlf bcd+1,f
rlf bcd+0,f
decfsz mcount,f ; all done?
goto b2bcd2 ; no, loop
return ; yes