Help :) (FLAGS)
ok a question about the 8080 so if anybody can help me.
do the flags only change for the accumulator or are they affected for the other registers as well
because if you inc b the flags are affected....why?
do the flags only change for the accumulator or are they affected for the other registers as well
because if you inc b the flags are affected....why?
Post edited by ASH-II on

Comments
Because the value of C is tested on positive/negative/zero and the flags are set according to the value.
....not just the accumulator ?
if I DEC 1 from a reg (say B) from 0 so it becomes -1 the number is 1 but the sign flag is set to 1. ok.
now if I then INC the accumulator by 1 from 0 so it becomes 1 the sign flag is set to 0...ok
if I now DEC B again by 1 should B be 0 or -2 ?????
Not quite. If you perform DEC on a register that contains 0, it will become 255. There are two ways of looking at this:
1) The register is storing an unsigned 8-bit number, which has a range from 0 to 255. When you subtract one from 0, it has to 'wrap around' to 255.
2) The register is storing a number in "two's complement" notation, where bytes with the top bit set (i.e. ones which have a value of 128 or above, when read the 'usual' way) correspond to negative numbers: 255 = -1, 254 = -2 and so on up to 128 = -127. This means that you can correctly read the result as -1, without considering the sign flag at all.
Either way, the sign flag doesn't serve as an 'extension' to the number you're working with - the resulting number is entirely contained in the 8 bits of the register. The sign flag is only set as a convenience to you, so that you can use it in JP instructions for example. (In fact, after an arithmetic operation like DEC, it will always match the top bit of the register you just updated.)
It will become 254, or -2 if you choose to read it in that way. The previous value of the sign flag doesn't have an effect.