6 example: adding two 4, 6 processor status flag op, 1 sign flag – Maxim Integrated MAXQ7667 User Manual
Page 37: 2 zero flag, 3 equals flag, 4 carry flag, 6 processor status flag operations -10, 1 sign flag -10, 2 zero flag -10, 3 equals flag -10
__________________________________________________________________________________________________________
3-10
MAXQ7667 User’s Guide
3.5.6 Example: Adding Two 4-Byte Numbers Using Autoincrement
move A[0], #5678h
; First number – 12345678h
move A[1], #1234h
move A[2], #0AAAAh
; Second number – 0AAAAAAAh
move A[3], #0AAAh
move APC, #81h
; Active Acc = A[0], increment low bit = mod 2
add A[2]
; A[0] = 5678h + AAAAh = 0122h + Carry
addc A[3]
; A[1] = 1234h + AAAh + 1 = 1CDFh
; 12345678h + 0AAAAAAAh = 1CDF0122h
3.6 Processor Status Flag Operations
The Processor Status Flag (PSF) register contains five flags that are used to indicate and store the results of arithmetic and logical oper-
ations, four of which can also be used for conditional program branching.
3.6.1 Sign Flag
The Sign flag (PSF.6) reflects the current state of the high bit of the active accumulator (Acc.15 for the MAXQ20). If signed arithmetic
is being used, this flag indicates whether the value in the accumulator is positive or negative.
Since the Sign flag is a dynamic reflection of the high bit of the active accumulator, any instruction that changes the value in the active
accumulator can potentially change the value of the Sign flag. Also, any instruction that changes which accumulator is the active one
(including AP autoincrement/decrement) can also change the Sign flag.
The following operation uses the Sign flag:
•
JUMP S, src (Jump if Sign flag is set)
3.6.2 Zero Flag
The Zero flag (PSF.7) is a dynamic flag that reflects the current state of the active accumulator Acc. If all bits in the active accumula-
tor are zero, the Zero flag equals 1. Otherwise, it equals 0.
Since the Zero flag is a dynamic reflection of (Acc = 0), any instruction that changes the value in the active accumulator can poten-
tially change the value of the Zero flag. Also, any instruction that changes which accumulator is the active one (including AP autoin-
crement/decrement) can also change the Zero flag.
The following operations use the Zero flag:
•
JUMP Z, src (Jump if Zero flag is set)
•
JUMP NZ, src (Jump if Zero flag is cleared)
3.6.3 Equals Flag
The Equals flag (PSF.0) is a static flag set by the CMP instruction. When the source given to the CMP instruction is equal to the active
accumulator, the Equals flag is set to 1. When the source is different from the active accumulator, the Equals flag is cleared to 0.
The following instructions use the value of the Equals flag. Note that the ‘src’ for the JUMP E/NE instructions must be immediate.
•
JUMP E, src (Jump if Equals flag is set)
•
JUMP NE, src (Jump if Equals flag is cleared)
In addition to the CMP instruction, any instruction using PSF as the destination can alter the Equals flag.
3.6.4 Carry Flag
The Carry flag (PSF.1) is a static flag indicating that a carry or borrow bit resulted from the last ADD/ADDC or SUB/SUBB operation.
Unlike the other status flags, it can be set or cleared explicitly and is also used as a generic bit operand by many other instructions.
The following instructions can alter the Carry flag:
•
ADD src (Add source to active accumulator)
•
ADDC src (Add source and Carry to active accumulator)
•
SUB src (Subtract source from active accumulator)
•
SUBB src (Subtract source and Carry from active accumulator)