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.

Subtraction using PIC - Help needed

Status
Not open for further replies.

devonsc

Advanced Member level 4
Full Member level 1
Joined
Nov 30, 2004
Messages
115
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
1,931
subtraction using pic

Hi there,

Would like to ask you guys something about the PIC program to perform subtraction. Mind to comment about it? Thanks in advance.

In the following, am I right to say that '00011111' minus '00000001'? But it is 2's complement? Mind teaching about this matter? Not very sure about it.

Does it mean that '00011111' will be converted into '11100000' and this value will added with '1' and in the end, I obtained '11100001'?

But then, I do not know how to continue from here, mind teaching? Please? Hope you dont mind me asking such direct help. Please?

-------------------------------------
MOVLW B'00000001'
SUBLW B'00011111'
BTFSS STATUS,C
BTFSC STATUS,Z
BSF PORTC,2
GOTO START
END
-------------------------------------
 

2's complement only applies to negative numbers. It means that to invert the sign of a number (turn 5 into -5 for example) you invert the bits and add one, like you said.

The nice thing about 2's complement is that addition and subtraction can be done just like with unsigned numbers, so it's up to you to decide if "11111111" means -1 or 255.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top