Tracid
Member level 3
- Joined
- Nov 1, 2006
- Messages
- 57
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 1,288
- Location
- Neded, Slovakia
- Activity points
- 1,756
Hi
I am writing a simple code in ASM for PIC16F84A to compare two registers and depending on the result branch to locations... Its alredy clear for me that SUBLW substracts W from Literal and not the opposite as when using SUBWF. The only thing which is unclear for me is when is the Carry byt set or cleared. Because i have searched the web and found different explanation from which one must be the wrong.
So i write down the code here with explanation what is my desired result and i ask you please correct me if i am wrong.So:
Compare movf M1Time,W ;this is the first register to compare
subwf M3Time,W ;compare with the second register
BZ M3_Eq_M1 ;they are the same
movf M1Time,W
subwf M3Time,W
BNC M3_LT_M1 ;M3Time is less than M1Time
goto M3_GT_M1 ;M3Time is bigger than M1Time
M3_Eq_M1 movf .....
M3_LT_M1 movf .....
M3_GT_M1 movf ....
1, is this code correct?
2, if i substract a bigger value from a smaller value the Carry bit will be set? OR the carry bit will be cleared? its a little bit confusing me....this is about Carry and BORROW? C bit is set on overflow and is cleared on underflow?
3, please do not recommend me addlw and the twos complement solution )
Thank you very much
I am writing a simple code in ASM for PIC16F84A to compare two registers and depending on the result branch to locations... Its alredy clear for me that SUBLW substracts W from Literal and not the opposite as when using SUBWF. The only thing which is unclear for me is when is the Carry byt set or cleared. Because i have searched the web and found different explanation from which one must be the wrong.
So i write down the code here with explanation what is my desired result and i ask you please correct me if i am wrong.So:
Compare movf M1Time,W ;this is the first register to compare
subwf M3Time,W ;compare with the second register
BZ M3_Eq_M1 ;they are the same
movf M1Time,W
subwf M3Time,W
BNC M3_LT_M1 ;M3Time is less than M1Time
goto M3_GT_M1 ;M3Time is bigger than M1Time
M3_Eq_M1 movf .....
M3_LT_M1 movf .....
M3_GT_M1 movf ....
1, is this code correct?
2, if i substract a bigger value from a smaller value the Carry bit will be set? OR the carry bit will be cleared? its a little bit confusing me....this is about Carry and BORROW? C bit is set on overflow and is cleared on underflow?
3, please do not recommend me addlw and the twos complement solution )
Thank you very much