FLAGS

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/26

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

27 Terms

1
New cards

Program Status Register (PSR)

The register that holds the current machine state, including condition flags, execution mode, interrupt bits, and the Thumb state.

2
New cards

CPSR (ARM7TDMI)

The Current Program Status Register on ARM7TDMI, containing flags (N, Z, C, V), processor mode, interrupt bits, and the Thumb bit.

3
New cards

xPSR (Cortex-M4)

The combined status register on Cortex-M4 that includes condition flags, exception number, ICI bits, and the Thumb bit.

4
New cards

Condition Flags

Four bits (N, Z, C, V) stored in the uppermost nibble of the status register that control conditional execution of instructions.

5
New cards

N Flag (Negative Flag)

Set when the most significant bit (bit 31) of the result is 1, indicating a negative value in two’s complement representation.

6
New cards

Negative Number (Two’s Complement)

A value whose most significant bit is set to 1 in a two’s complement number system.

7
New cards

Important Caveat of the N Flag

Two positive numbers can add together and produce a result with the MSB set, causing the N flag to be set even though both operands were positive.

8
New cards

V Flag (Overflow Flag)

Indicates a signed overflow, meaning the result of an arithmetic operation cannot be represented in 32-bit two’s complement form.

9
New cards

Signed Overflow Condition

Occurs when the result of an addition or subtraction is ≥ 2³¹ or < −2³¹.

10
New cards

Calculated as the XOR of the carry into the most significant bit and the carry out of the most significant bit

How is the V Flag Computed?

11
New cards

S Suffix (Flag-Setting Instructions)

Appending S to an ALU instruction (e.g., ADDS, SUBS) causes the instruction to update the condition flags.

12
New cards

Z Flag (Zero Flag)

Set when the result of an operation is exactly zero (all 32 bits are zero).

13
New cards

Used in loops and counters to detect when a value reaches zero.

Common Use of the Z Flag

14
New cards

BNE (Branch if Not Equal)

A conditional branch instruction that jumps when the Z flag is clear (result ≠ 0).

15
New cards

Example Use of Z Flag in a Loop

A register is decremented using SUBS until it reaches zero; BNE repeats the loop while Z = 0.

16
New cards

C Flag (Carry Flag)

Set when an addition produces a result ≥ 2³², when a subtraction does not require a borrow, or due to a barrel shifter operation.

17
New cards

Carry Flag in Addition

Indicates an unsigned overflow where the result exceeds the 32-bit limit.

18
New cards

Carry Flag in Subtraction

Set when the result is positive; effectively represents “no borrow” due to inverted carry logic.

19
New cards

Carry Flag and Precision Arithmetic

Used to build higher-precision arithmetic, such as 64-bit addition or subtraction using multiple 32-bit operations.

20
New cards

Carry Flag and Shifts

Updated by inline barrel shifter operations in move and logical instructions.

21
New cards

Allows chaining arithmetic operations across multiple registers for extended precision calculations.

Why is the C Flag Useful?

22
New cards

Q Flag (Cortex-M4 Only)

Indicates that a value has saturated; governed by special rules and discussed separately from N, Z, C, and V.

23
New cards

Ways Flags Can Be Modified

  • Dedicated flag-setting instructions (e.g., CMP, TST)

  • ALU instructions with the S suffix

  • Direct writes to the Program Status Register

  • Certain 16-bit Thumb ALU instructions

24
New cards

CMP Instruction

Performs a subtraction internally to update flags without storing the result.

25
New cards

TST Instruction

Performs a bitwise AND internally to update flags without storing the result.

26
New cards

Signed vs Unsigned Interpretation of Flags

The same flag values can represent different meanings depending on whether numbers are treated as signed or unsigned.

27
New cards

Key Difference Between N and V Flags

N reflects the sign of the result, while V indicates whether a signed overflow occurred.