I am learning 8080 assembly as part of a course that I am undertaking. I am referring to Intel 8080-8085 Assembly Language Programming manual (dated 1977).
In Chapter 3 Instruction Set of the manual, I see the following description in relation to DCX:
DCX decrements the contents of the specified register pair by one. DCX affects none of the condition flags.
The associated example says:
Assume that the H and L registers contain the address 9800H when the instruction DCX H is executed. DCX considers the contents of the two registers to be a single 16-bit value and therefore performs a borrow from the H register to produce the value 97FFH.
I tried the math on my own using two's complement addition and there is definitely a carry generated.
So my question is: Is carry bit set only in the case of arithmetic operations?
TIA
PV
Setting the particular CPU aside and just considering binary arithmetic, no borrow is generated when subtracting 1 from 9800H. A carry is generated when adding 0FFFF to 9800H, though. In both cases you get 97FFH in the 16 least significant bits of the result.
Irrespective of the design choices put into the CPU you need to simply follow the documentation, e.g. this document, MCS®-80/85 FAMILY USER'S MANUAL.
It says in 5.6.1 Data Transfer Group:
Condition flags are not affected by any instruction in this group.
5.6.2 Arithmetic Group:
Unless indicated otherwise, all instructions in this group affect the Zero, Sign, Parity, Carry, and Auxiliary Carry flags according to the standard rules.
Similarly in 5.6.3 Logical Group:
Unless indicated otherwise, all instructions in this group affect the Zero, Sign, Parity, Auxiliary Carry, and Carry flags according to the standard rules.
5.6.4 Branch Group:
Condition flags are not affected by any instruction in this group.
5.6.5 Stack, I/O, and Machine Control Group:
Unless otherwise specified, condition flags are not affected by any Instructions in this group.
You need to memorize how common instructions affect flags. You may compile a simple cheat sheet or, perhaps, find one made by someone else (some assembly books had those for the programmer's convenience).
If you're interested in why some instructions don't affect flags or some affect them in a particular way, it depends. The reasons can be different, depending on the particular instruction: cheaper circuitry, easier to program common problems, compatibility with earlier designs or just simply carrying forward what had worked well without giving it much additional thought.