Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

strange variable problem, need help

Not open for further replies.


New Member
strange variable problem, *solved*

Hello guys,

I encountered a strange problem with variable today. It seems the variable i've declared are not changing even with simplest instruction like decfsz.

The code works and compiled. So, it also loaded some value using movwf too. But when it comes to decfsz, it does change. I wonder if the way i am declaring the variables makes it like this or some setting is wrong?

I'll insert my code so that you guys can help me out here.

	list      p=16f628A           ; list directive to define processor
	#include <p16F628A.inc>       ; processor specific variable definitions
	errorlevel  -302              ; suppress message 302 from list file


cblock 0x20
     ACCcLO, ACCcHI, ACCdLO, ACCdHI, Dcount

#include <muldiv.h>

w_temp        EQU     0x7E        ; variable used for context saving 
status_temp   EQU     0x7F        ; variable used for context saving

	ORG     0x000             ; processor reset vector
	goto    main              ; go to beginning of program

	ORG     0x004             ; interrupt vector location
	movwf   w_temp            ; save off current W register contents
	movf	STATUS,w          ; move status register into W register
	movwf	status_temp       ; save off contents of STATUS register

; isr code can go here or be located as a call subroutine elsewhere

	movf    status_temp,w     ; retrieve copy of STATUS register
	movwf	STATUS            ; restore pre-isr STATUS register contents
	swapf   w_temp,f
	swapf   w_temp,w          ; restore pre-isr W register contents
	retfie                    ; return from interrupt

	#include <muldiv.inc>

	movlw	0x02
	movwf	Dividend
	movlw	0x02
	movwf	Divider
	call DIV8

	goto	main		  ;loop forever, remove this instruction, for test only

;Dividend 16/16  (this has nothing to do with at the moment)
	clrf     count
	bsf      count,4         ; set count = 16
	clrf     ACCcHI
	clrf     ACCcLO
	clrf     ACCdLO
	clrf     ACCdHI
;  Looped code
	bcf      STATUS,C
	rlf     ACCbLO
	rlf     ACCbHI
	rlf     ACCcLO
	rlf     ACCcHI
	movfw    ACCaHI
	subwf	ACCcHI,W          ;check if a>c
	btfss	STATUS,Z
	goto	notz
	movfw    ACCaLO
	subwf     ACCcLO,W        ; if msb equal then check lsb
	btfss	STATUS,C    ; carry set if c>a
	goto    nosub           ; if c < a
	movfw    ACCaLO    ; c-a into c
	subwf     ACCcLO, F
	movfw    ACCaHI
	subwf    ACCcHI, F
	bsf      STATUS,C              ;shift a 1 into d (result)
	rlf     ACCdLO, F
	rlf     ACCdHI, F
	decfsz     Dcount, F
	goto    divLoop

; initialize eeprom locations

	ORG	0x2100
	DE	0x00, 0x01, 0x02, 0x03

	END                       ; directive 'end of program'

;multiply 8bit
	clrf H_byte
	clrf L_byte
	movlw 8
	movwf count
	movf mulcnd,W
	bcf STATUS,C ; Clear the carry bit in the status Reg.
	rrf mulplr, F
	btfsc STATUS,C
	addwf H_byte,Same
	rrf H_byte,Same
	rrf L_byte,Same
	decfsz count, F
	goto loop
	retlw 0

;dividend 8bit
DIV8	;	movlw	b'00001010'		; load the divider parameter
		;	movwf	Divider			; store it
		;	movlw	b'01100100'		; load the dividend parameter
		;	movwf	Dividend		; store it
                       movlw       0x01
                       movwf       Same
			movlw	8			; load counter parameter
			movwf	Counter			; store it
			clrf	Result			; clear the result
			clrf	Remainder		; clear the remainder
			bcf	StatusReg,CarryFlag	; clear the carry flag
process		rlf	Dividend,Same		; rotate bit into carry
			rlf 	Remainder,Same		; rotate carry into remainder file
			movf	Divider,w		; load the divider
			subwf	Remainder,w		; subtract it from remainder file store in w
			rlf	Result,Same		; rotate carry into result (1) pos (0) neg
			btfsc	Result,0		; check if last calculation was positive
			goto 	calc_remainder		; 
countdown	decfsz	Counter,Same		; coundown 8 bits
			goto 	process			; carry on
			return					; return to call stack
calc_remainder	movwf	Remainder		; store the remainder in Remainder file
			goto	countdown		; carry on

count, prodH, prodL, mulplr,mulcnd,answer,Counter
Same, Dividend, Divider, StatusReg, CarryFlag, Remainder, Result

i removed the variable "Same" and it worked. strange...
Last edited:


Coop Build Coordinator
Forum Supporter
Assemblers Assemble ...

Assemblers and compilers are both translators.

Compilers translate high level languages into something else.

Assemblers translate asm into machine code, most often in some hex format.

Assemblers assemble... Compilers compile... Assemblers do not compile !

Thanks for you time. :)



New Member
Forum Supporter
This is VERY suspicious:
countdown decfsz Counter,Same ; coundown 8 bits
How is SAME defined? I see you also use it as a variable:
movlw 0x01
movwf Same
These two uses are NOT compatable. Use F or W in the decfz statements and NOT "Same". F and W are one bit definitions. "Same" is probably defined as the location of an 8 bit variable address.
Last edited:


New Member
I confirmed the problem came from "Same"

it is originally defined as "Same equ 1"

so, in my code i made it wrongly and defined as variable block, just like kchriste said, it wouldn't work with a memory block for an instruction option.
Not open for further replies.

Latest threads

EE World Online Articles