![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi I have a pair of 3 digit values. They are actual value & save value. I need to subtract the save value from the actual value & need to decide is it greater than the save value. I don’t need the exact result I need to know whether actual value > or < than the save value. I wrote a small routine needs to check is it ok or not, Code: 121 =actual value (D3,D2,D1) 103 =save value (SD3,SD2,SD1) movf SD1,W subwf D1,W ;substract digit1 btfsc STATUS,C goto $+2 decf D2,F movf SD2,W subwf D2,W ;substract digit2 btfsc STATUS,C goto $+2 decf D3,F movf SD3,W subwf D3,W ;substract digit3 btfss STATUS,C goto $+3 bsf Result,1 ;result possitive return bcf Result,1 ;result negative return | |
| |
| | (permalink) |
| You can do a much simpler comparison by just comparing the digits until you find a pair that are not equal. I'm assuming that D3 is the most significant byte. Code: movfw D3 subwf SD3,W btfss STATUS,Z goto GotResult movfw D2 subwf SD2,W btfss STATUS,Z goto GotResult movfw D1 subwf SD1,W GotResult ;if zero flag set then numbers are equal ;if carry flag set then SD > D | |
| |
| | (permalink) |
| | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Voltage Subtraction | JPW1966 | General Electronics Chat | 2 | 24th October 2007 10:58 PM |
| subtraction instruction in pic | 4electros | Micro Controllers | 10 | 13th August 2005 08:02 PM |
| PIC subtraction: Carry flag | eblc1388 | Micro Controllers | 4 | 19th June 2005 02:47 PM |
| subtraction in PIC16F876 ?? | zika1212 | Micro Controllers | 1 | 21st December 2004 01:14 AM |
| Background Subtraction | scout_54 | Electronic Projects Design/Ideas/Reviews | 1 | 16th March 2004 02:05 AM |