Reputation: 33
Alright I have been looking into some questions trying to figure this out. My main concern is the V, N, Z, and C flag. I can easily identify when flags are set in AVR studio as it tell me. However, if I am given an example like 0xFE + 0x0A how can I determine with a pen a paper what flags are set. Hopefully this makes sense!
Any explanation would be appreciated!
Thanks.
Upvotes: 0
Views: 132
Reputation: 8449
For addition, the ADD
instruction is described on p. 17 of the instruction set manual.
V is overflow of signed addition. In 2's complement, the negative numbers have a 1 in the top bit. (128 to 255 in unsigned). Overflow occurs if both operands are positive and the result is negative, or both are negative and the result is positive.
N is the negative flag. Set if the result is signed negative (has the top bit 1).
Z set if the result is 0.
C is best described in unsigned arithmetic. If both operands have a 1 in the top bit (128 to 255), then the result would have a 1 in the "ninth bit" if it existed. (The result would be between 256 and 510.) This "ninth bit" is the carry bit. There would also be a carry if only one of the operands was in 128 to 255, but the result has a 0 in the top bit (is 127 or less).
Upvotes: 1