I am new to assembly and AVR. What is the best way to compare two values like in C:
#define SOME_VAL 55
int current_counter = 0;
...
...
if(current_counter==SOME_VAL) {
}
In assembly I have the following code:
.EQU SOME_VAL = 55
.def current_counter = r19
What is the best way to compare the current value with a defined constant?
Best Answer
The instruction you need has the mnemonic CPI (compare with immediate).
This will set or clear a flag depending on the result.
You can then branch after checking the flag.
Have a look at the following example. It's from the [8-bit] AVR instruction summary (http://www.atmel.com/images/doc0856.pdf).
The example below is from page 24:
Example:
There are other instructions that will do slightly different comparisons (like compare two registers, instead of comparing a register with a literal).