Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Using the SUBWF instruction

Status
Not open for further replies.

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
 

Hi,

Looking at my old instruction set notes I have this for the Status bit 0 Carry Flag.

If the result of a Sub is Pos or Zero the Carry is set to 1
If the result of a Sub is Negtive the Carry is set to 0

To confirm your code is correct, just run it in Mplabs Simualtor and single step those lines of code watching the Status bits on the bottom toolbar, Carry c =0 C=1
 

Some time ago I wrote a utility to help write assembler code for Pic16 series micros and posted it on eda board here.




No install is needed, just extract all the files to a directory. Call the directory PicHelp or whatever you like.
Generates code for common constructs in programming.

Please give it a go and see if it helps.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top