I'm either having a bit of trouble with my 24-bit addition routine or there's something else wrong. Basically I want to add 0F 42 44 to whatever is in the GPR's HI, MID and LO At the moment I'm using this code, but I'm not sure if it's correct or not, so if anyone can help re-write any errors I'd be very grateful: Code: MOVLW 0x44 ; LSB VALUE TO ADD ADDWF LO,F ; ADD IT TO THE REMAINDER ALREADY IN LSB BTFSC STATUS,0 ; INCF MID,F ; CARRY. LSB OVERFLOWED, SO INC MID MOVLW 0X42 ; MID VALUE TO ADD ADDWF MID,F ; ADD 0x42 TO THE REMAINDER ALREADY IN MID BTFSC STATUS,0 ; INCF HI,F ; CARRY. MID OVERFLOWED, SO INC MSB MOVLW 0X0F ; GET MSB VALUE ADDWF HI,F ; LOAD IN MSB
yup looks sound. two tips, the simulator in MPLAB will awnser this question quicker than posting, also when posting always use symbols (ie C for carry rather than the address). One slight issue u might have with the code, is initilisation of mid and high, when you use INCF they could have any number in them including FF, and u would lose a carry on the INCF. see www.piclist.com source code library for more on maths routines.
One thing to mention, its only ZERO thats effected by INCF/DECF and related instructions, CARRY isn't touched. (so test on ZERO, as for these ops CARRY = not ZERO
This is the problem I think I may be having issues with. How would you get around this problem? By adding 1 instead of incrementing the MID value then testing for carry again?
erm no its straight forward enough, the big question is how important overflow (one or more carrys) in the hi byte is. Code: MOVLW 0x44 ; LSB VALUE TO ADD ADDWF LO,F ; ADD IT TO THE REMAINDER ALREADY IN LSB BTFSS STATUS,C ; GOTO MIDADD INCF MID,F ; CARRY. LSB OVERFLOWED, SO INC MID BTFSC STATUS,Z ; Has CARRY occured? INCF HI, F ; Yes, yes it has MIDADD: MOVLW 0X42 ; MID VALUE TO ADD ADDWF MID,F ; ADD 0x42 TO THE REMAINDER ALREADY IN MID BTFSC STATUS,C ; INCF HI,F ; CARRY. MID OVERFLOWED, SO INC MSB MOVLW 0X0F ; GET MSB VALUE ADDWF HI,F ; LOAD IN MSB
Your okay until the numbers start dancing, hey they do that a lot for me (cuas i'm specail like the clineman kid down the road)