Continue to Site

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.

Quick code question

Status
Not open for further replies.

imhereithink

New Member
Just checking to see if it is ok to do this, i have stored data into STORE1 and want to check it more than once to see what character it has stored in it. So is this ok the way i am testing the same location for different data?

MOVF STORE1, W
SUBLW D'13'
BTFSC STATUS, Z
RETURN
MOVF STORE1, W
SUBLW D'10'
BTFSC STATUS, Z
RETURN

I was wondering that by calling the same STORE1 again after the sublw, the data held will have changed from the previous sublw? or does it not store the new value after the first sublw?

Hope this makes sense to you guys :rolleyes:

Thanks
 
Last edited:
imhereithink said:
Just checking to see if it is ok to do this, i have stored data into STORE1 and want to check it more than once to see what character it has stored in it. So is this ok the way i am testing the same location for different data?

MOVF STORE1, W
SUBLW D'13'
BTFSC STATUS, Z
RETURN
MOVF STORE1, W
SUBLW D'10'
BTFSC STATUS, Z
RETURN

I was wondering that by calling the same STORE1 again after the sublw, the data held will have changed from the previous sublw? or does it not store the new value after the first sublw?

Hope this makes sense to you guys :rolleyes:

Thanks

hi,
As you are not writing W back into the STORE1 after each test, the original STORE1 is not changed.
Also you are reloading W with STORE1 before each new test, its OK.

How many tests are you planning to do on STORE1?
 
It is fine to do it that way.

There is a better way and that is to use xor. Because xoring the same value twice results in the original value, you can use this to your advantage.

Code:
	MOVF	STORE1, W
	xorlw	D'13' 		; is it 13
	BTFSC	STATUS, Z
	RETURN
	xorlw	D'13'^D'10'	; is it 10
	BTFSC	STATUS, Z
	RETURN
	xorlw	D'10'^'A'	; is it "A"
	BTFSC	STATUS, Z
	goto	CommandA

The ^ symbol tells the assembler to xor the values together.

BTW, when you do any operation with a literal (sublw) the answer always goes in W.

Mike.
 
Thanks for clearing that up guys :)

Eric i am planning on testing STORE1 four times, since i seem to be having sychronisation problems when reading in the received data, so i am wanting to test each bit stored for CR, LF, O, K. That way i should pick up what i am looking for even if it is out of sync.

Thanks again
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top