1.1.3.2 Flag Register
The Flag Register contains 8 flags indicating the
statusoftheST9.Duringaninterrupttheflagregister
is automaticallystoredin thesystemstack area and
recalledat theend of theinterruptservice routine so
that the ST9 is returnedto the original status. This
occursfor all interruptsand, when operatingin the
nestedmode,up tosevenversionsof the flagregistermay bestored.
FLAGR R231 (E7h) System Read/Write
Flag Register
Reset value: undefined
b7 =C:
Carry Flag
. The carry flag C is affectedby
the followinginstructions:
Addition(add, addw, adc, adcw),
Subtraction(sub, subw, sbc, sbcw),
Compare(cp, cpw),
Shift Right Arithmetic(sra, sraw),
Rotate (rrc, rrcw, rlc, rlcw, ror, rol),
DecimalAdjust (da),
Multiplyand Divide (mul, div, divws).
When set, it generally indicates a carry out of the
most significant bit position of the register being
used asan accumulator(bit7 forbyte andbit15 for
word operations).
ThecarryflagcanbesetbytheSetCarryFlag(scf)
instruction,clearedbytheResetCarryFlag(rcf)in-
struction,and complemented(changedto “0” if “1”,
andviceversa) bytheComplementCarryFlag(ccf)
instruction.
b6 =Z:
Zero Flag
. The Zero flag is affectedby the
followinginstructions:
Addition(add, addw, adc, adcw),
Subtraction(sub, subw, sbc, sbcw),
Compare(cp, cpw),
Shift Right Arithmetic(sra, sraw),
Rotate (rrc, rrcw, rlc, rlcw, ror, rol),
DecimalAdjust (da),
Multiplyand Divide (mul, div, divws),
Logical (and, andw, or, orw, xor, xorw,
cpl),
Increment and Decrement (inc, incw, dec,
decw),
Test (tm, tmw, tcm, tcmw, btset).
In most cases,the Zero flag is setwhenthe register
beingused as an accumulator register is zero, following oneof theabov eoperations .
b5 = S:
SignFlag
. TheSign flag is affected by the
sameinstructions asthe Zeroflag.
The Sign flag is set when bit 7 (for byte operation)
or bit15(for wordoperation)of theregisterusedas
an accumulatoris one.
b4 = V:
Overflow Flag
. The Overflow flag is affected by the same instructions as the Zero and
Sign flags.
Whenset, theOverflow flagindicates that a two’scomplementnumber,in a resultregister,isin error,
since it has exceeded the largest (or is less than
the smallest), number that can be represented in
twos-complementnotation.
b3 =DA:
DecimalAdjust Flag
. TheDecimal Adjust
flagis usedfor BCDarithmetic.Sincethealgorithm
for correctingBCD operations is different for addition and subtraction, this flag is used to specify
whichtype of instructionwas executedlast, so that
the subsequentDecimalAdjust (da) operationcan
performits functioncorrectly.
The Decimal Adjust flag cannot normally be used
as a test condition by the programmer.
b2 = H:
Half Carry Flag
. The Half Carry flag indicates a carry out of (or a borrow into) bit 3, as the
resultof addingorsubtractingtwo8-bit bytes,each
representingtwo BCD digits.The Half Carry flagis
used bythe DecimalAdjust (da) instructionto convert the binary result of a previousadditionor subtraction intothe correct BCD result.
Like the Decimal Adjust flag, this flag is not normallyaccessed by the user.
b1 =UF:
UserFlag
. Bit1 in the flagregister (UF) is
available to the user, but it must be set or cleared
by an instruction.
b0 = DP:
Data/Program Memory Flag
. This bit in
the flag register indicates which memory area is
addressed. Its value is affected by the Set Data
Memory(sdm) andSet Program Memory (spm) instructions.
If the bit is set, theST9 addressesthe Data Memory Area; when the bit is cleared, the ST9 addresses the Program Memory Area. By reading
this bit, the user can verify in which memory area
the processor is working. The user writes this bit
with the sdm or spm instructions.
SYSTEM REGISTERS(Continued)
ST9291
12/20