I have 2 8bit bytes that come in from the SPI. I need to add or subtract a 1 to the bytes. So I need help with a code that can add to the lower byte and be able to carry into the high byte when necessary. I also have no idea how to subtract.
The other option is a increment/decrement system for the 16bits.
z2012:
The other option is a increment/decrement system for the 16bits.
In my opinion this is the only approach that makes sense. From the description you've given it's apparent that the two bytes are conceptually holding a 16-bit value, so if you just store that value in a 16-bit int then manipulating the value becomes trivial.
unsigned char low, high;
void setup() { Â Â Â Â Â Â Â Â
}
void loop() {
 //add 1 with carry
 asm(
  "lds r24, (low)  \n\t"  //low byte
  "lds r25, (high) \n\t"  //high byte
  "ldi r23, 1    \n\t" Â
  "add r24, r23   \n\t"  //increment low byte by 1
  "adc r25, 0x00  \n\t"  //add carry to high byte
  "sts (low), r24  \n\t"  //save results
  "sts (high), r25 \n\t"
  ::: "r23","r24", "r25"
 );
 //subtract 1 with carry
 asm(
  "lds r24, (low) \n\t"
  "lds r25, (high) \n\t"
  "ldi r23, 1   \n\t"
  "sub r24, r23  \n\t"
  "sbc r25, 0x00 \n\t"
  "sts (low), r24 \n\t"
  "sts (high), r25 \n\t"
  ::: "r24", "r25"
 );
}
Edit note: for completeness I included the subtraction code. My original thought was that the OP was requesting an assembly language routine.
void loop() {
 asm(
  "lds r24, (low)  \n\t"  //low byte
  "lds r25, (high) \n\t"  //high byte
  "ldi r23, 1    \n\t" Â
  "add r24, r23   \n\t"  //increment low byte by 1
  "adc r25, 0x00  \n\t"  //add carry to high byte
  "sts (low), r24  \n\t"  //save results
  "sts (high), r25 \n\t"
  ::: "r23","r24", "r25"
 );
}
The compiler can handle adding one to an integer. You don't need to drop into assembler for that.