Fact-checked by Grok 2 weeks ago

Negative flag

The negative flag, also known as the sign flag (often abbreviated as N or SF), is a single-bit indicator in the (or ) of a computer's (CPU) that signals whether the result of the most recent , logical, or is negative when interpreted as a signed in . It is typically set to 1 if the most significant bit (MSB) of the result is 1, indicating a negative value, and cleared to 0 otherwise, thereby reflecting the sign of the outcome for signed number processing. This flag plays a crucial role in enabling efficient conditional branching and decision-making in programming, particularly for signed comparisons such as " if less than" () or " if greater than or equal" (BGE) instructions, where the negative flag, often in combination with the , helps determine the relative order of signed operands without additional computations. It is updated automatically by arithmetic instructions like and , as well as certain logical operations that affect the , though the specific instructions that update it vary by . The negative flag has been a standard feature in numerous processor architectures since the early days of computing, including the (introduced in 1976), the (used in systems like the Commodore 64), processors, and modern x86 architectures from and . In these designs, it works in tandem with other status flags—such as the (Z), (V or OF), and (C)—to provide comprehensive feedback on operation results, supporting both low-level optimization in embedded systems and high-level abstractions in compilers for signed integer handling. Its implementation ensures portability across signed arithmetic routines while distinguishing signed from unsigned behaviors, a distinction critical for avoiding errors in numerical computations.

Overview

Definition

The negative flag, also known as the flag, is a single-bit indicator in a processor's that reflects the most significant bit (MSB) of the result from the previous or logical . This bit position serves as a direct copy of the MSB from the operation's outcome, providing a simple mechanism to track the of the computed value. In arithmetic, the negative flag signals whether the result is negative when the MSB is 1 or non-negative when the MSB is 0. This interpretation aligns with the standard use of the MSB as the in signed representations. The flag's general behavior is to be set to 1 if the MSB of the operation's result is 1 and cleared to 0 otherwise, while remaining unaffected by instructions that do not explicitly modify the , such as data movement operations. This ensures the flag retains its prior state unless updated by a relevant .

Purpose in Computing

The negative flag, often referred to as the , plays a crucial role in enabling processors to handle signed integers by distinguishing positive, zero, and negative results from arithmetic and logical operations without requiring additional instructions. It captures the most significant bit () of the operation's outcome, typically in representation, allowing hardware to immediately signal whether the result represents a negative value. This mechanism ensures that signed computations can proceed efficiently at the hardware level, integrating seamlessly with the processor's (ALU). For example, in architectures, the N flag is set to the (bit 31 for 32-bit operations) if the result is negative, providing a direct indicator for signed integer processing. Similarly, in the , the negative flag reflects bit 7 of the result, facilitating straightforward sign detection in 8-bit signed arithmetic. This further supports conditional execution and branching based on signed comparisons, such as determining if a value is less than () or greater than or equal to () another in signed contexts. By testing the N flag, processors can trigger jumps or alter program flow without computing the sign separately, optimizing control structures in code. In processors, signed conditional branches like "" (branch if minus, when N=1) or "bpl" (branch if plus, when N=0) rely on this flag to evaluate inequalities efficiently. The 6502 employs analogous instructions, such as (branch if minus) when the negative flag is set, enabling developers to implement signed decision logic with minimal overhead. This capability is vital for algorithms involving comparisons, like or conditional loops, where signed semantics must guide execution. The negative flag also facilitates efficient signed in programming and higher-level languages by permitting immediate post-operation inspection of results. After an ALU operation, software can query the flag to assess the sign, bypassing the need for or extra loads, which enhances performance in resource-constrained environments. In the 6502, for instance, instructions like (add with carry) or CMP (compare) update the flag automatically, allowing assemblers to build robust signed routines with direct hardware feedback. This integration reduces software overhead, making signed operations as streamlined as unsigned ones. Historically, the negative flag emerged as an essential feature in microprocessors to support signed number processing and emulate higher-level mathematical abstractions without excessive software intervention. Its design traces back to early systems like the (1970), which included sign detection in its status logic, influencing subsequent chips such as Intel's 8008 (1972) and 8080 (1974). By the late , processors like the (1978) and (1975) standardized this flag in their status registers, enabling efficient signed computations in the burgeoning era of personal and embedded computing.

Arithmetic Foundations

Two's Complement Representation

Two's complement is the predominant method for encoding signed integers in binary systems, utilizing the most significant bit (MSB) as the sign bit, where a value of 0 denotes a non-negative number (positive or zero) and 1 indicates a . This representation allows for a symmetric treatment of arithmetic operations across positive and negative values within a fixed number of bits. To represent a positive in , its equivalent is used directly, padded with leading zeros to the desired bit length if necessary. For negative s, the process involves first expressing the in , then inverting all bits (complementing to one's complement), and finally adding 1 to the result. For instance, in an 8-bit system, the positive number 5 is represented as 00000101. To obtain -5, invert to 11111010 and add 1, yielding 11111011. This method ensures that the negative value's pattern, when added to its positive counterpart, results in zero ( the bit width), facilitating efficient computations. In an n-bit system, the representable range spans from -2^{n-1} to $2^{n-1} - 1, providing one more negative value than positive ones due to the absence of a distinct for -[0](/page/0). For an 8-bit example, this covers -128 to +127, as the pattern 10000000 uniquely denotes -128 while 00000000 is , and no separate encoding exists for +0 beyond this. This asymmetry arises inherently from assigning the MSB weight as negative, specifically -2^{n-1}. The adoption of stems from its simplification of hardware arithmetic: addition and subtraction operations mirror those for unsigned integers, requiring no special circuitry for sign handling, with results wrapping around $2^n and status flags detecting anomalies like . This uniformity reduces complexity in and execution, making it the in modern computing architectures. In the context of processor flags, the negative flag reflects the state of the in the result of an operation, signaling whether the outcome is negative.

Sign Bit Operation

The negative flag directly reflects the most significant bit (MSB) of the result produced by an operation in representation, serving as an indicator of whether the result is negative, irrespective of the signs of the operands involved. This mapping ensures that the flag captures the sign of the outcome post-calculation, providing a straightforward mechanism for signed value assessment in processor status registers. In arithmetic operations such as and , the negative is set to 1 if the MSB of the result is 1, signifying a negative value, and cleared to 0 otherwise. For instance, performing 100 minus 150 in 8-bit arithmetic results in -50, represented as 11001110 , where the MSB of 1 sets the flag. This behavior holds across operations that update the flag, treating the result uniformly under interpretation. Logical operations, including AND, OR, and XOR, also set the negative based on the MSB of their bitwise result, effectively treating the output as a signed . For example, an AND operation yielding a result with MSB 1 will set the flag, mirroring the logic applied to arithmetic results. Certain edge cases arise in shift and rotate operations, where the negative flag's state depends on sign bit handling. Arithmetic shifts preserve the original sign bit by propagating it into vacated positions, ensuring the flag aligns with the resulting sign; for instance, a right arithmetic shift on a negative value maintains the MSB as 1, keeping the flag set. Rotates, by contrast, may cycle bits without preservation, potentially altering the flag based on the new MSB configuration.

Implementations in Architectures

x86 Architecture

In the x86 architecture, the negative flag, known as the , occupies bit 7 of the in 32-bit mode or the RFLAGS register in 64-bit mode. It reflects the most significant bit (MSB) of the result from an arithmetic, logical, comparison, or operation, being set (1) if the MSB indicates a negative value in representation and cleared (0) otherwise. This behavior applies uniformly across operand sizes of 8, 16, 32, or 64 bits, with the 64-bit extension in maintaining the same semantics but supporting larger RFLAGS operands via the .W prefix. SF is updated by arithmetic instructions such as ADD, , , , , , and , which compute the result and set SF based on its MSB, though (, ) and (, ) instructions leave SF undefined. Logical instructions including AND, OR, , and NOT similarly set SF to the MSB of the destination after the operation. The instruction sets SF as if performing an AND without storing the result, while CMP performs a subtraction-like comparison to update SF without altering operands. Shift instructions like (arithmetic right shift) preserve and propagate the , thereby setting SF to match the new MSB of the shifted value. Explicit manipulation of occurs through dedicated instructions, as it lacks direct set or clear opcodes like those for the . The LAHF instruction loads the lower 8 bits of the (including SF) from the register, while SAHF stores bits from AH into the corresponding flags, allowing indirect control over SF. Broader access is provided by PUSHF/PUSHFD/PUSHFQ, which push the FLAGS or EFLAGS or RFLAGS onto the , and their POP counterparts, enabling full register save and restore operations that include SF. In , these instructions extend to 64-bit RFLAGS handling.

ARM Architecture

In ARM processors, the negative flag (N) resides in the Current Program Status Register (CPSR) for AArch32 execution state or the Application Program Status Register (APSR) for application-level operations, where it is set to 1 if the most significant bit (bit 31) of the instruction's result is 1, indicating a negative value when interpreted as a signed . The N flag is updated by instructions that affect the condition flags, including arithmetic operations such as ADD and when suffixed with 'S' (e.g., ADDS, SUBS), logical operations like AND and ORR with the 'S' suffix (e.g., ANDS, ORRS), and comparison instructions like CMP, which always modify the flags based on the subtraction result without storing it. In ARMv8 architecture with execution state, the N flag is part of the NZCV condition flags register (accessible via system instructions like ), maintaining the same semantics as in earlier versions but applied to 64-bit operations, where it is set according to bit 63 of the result for signed integer interpretations. This ensures compatibility for flag-based decisions in 64-bit contexts, with the APSR providing AArch32 compatibility views when needed. The N flag plays a key role in conditional execution through instruction suffixes in AArch32 (e.g., ADDS to both perform and set flags) and condition codes in both AArch32 and , enabling branches or operations like (signed less than), which executes if N ≠ V (where V is the ), thus supporting efficient signed comparisons without additional jumps.

6502 Processor

In the 6502 microprocessor, the negative flag (N) occupies bit 7 of the 8-bit Processor Status (P) register and serves as the sign indicator for the most significant bit (MSB) of arithmetic and logical results, where a value of 1 denotes a negative number in two's complement representation. The flag is set to 1 if the MSB (bit 7) of the operation's result is 1 and cleared to 0 otherwise, mirroring the sign bit to facilitate signed comparisons and branching. The N flag is affected by several instruction categories. Arithmetic operations such as (add with carry) and (subtract with carry) set N based on bit 7 of the accumulator result after the addition or subtraction, respectively. Logical operations including AND (bitwise AND), (exclusive OR), and (bitwise OR) similarly update N to reflect bit 7 of the accumulator following the bitwise manipulation with the . Compare instructions—CMP (compare accumulator), CPX (compare X register), and CPY (compare Y register)—set N according to bit 7 of the difference between the register and , effectively indicating the of the subtraction result. Shift instructions also influence N: (arithmetic shift left) sets it to the original bit 6 of the (which becomes the new bit 7 after shifting), while (logical shift right) always clears N to 0, as the shift moves bit 7 out of the result. A key nuance arises in decimal mode (enabled by the D flag in the P register), where ADC and SBC perform binary-coded decimal (BCD) arithmetic but set the N flag based on bit 7 of the raw binary intermediate result prior to any BCD correction, rather than the final adjusted value in the accumulator. For instance, an operation yielding a binary result with bit 7 set to 1 will set N, even if subsequent BCD adjustment flips that bit for the stored decimal value. This behavior holds for the original NMOS 6502 but differs in CMOS variants like the 65C02, where N reflects bit 7 after full BCD correction. The 65C02, an enhanced version of the 6502, introduces additional instructions such as extensions and new addressing modes but maintains consistent N flag behavior for core , logical, compare, and shift operations in binary mode, with the noted decimal mode variation.

Interactions and Comparisons

Relation to

The negative flag (N) and the (V or OF) play complementary yet distinct roles in handling signed within processor status registers. The negative flag directly mirrors the most significant bit () of the result, indicating whether the outcome represents a negative value (N=1) or a non-negative value (N=0) in representation. In contrast, the signals an error in signed when the result exceeds the representable range, such as producing an incorrect due to magnitude , but it does not reflect the sign itself. For addition in , the is set if the carry into the differs from the carry out of the , computed as their XOR; this is equivalent to the condition where the operands have the same but the result has a different . This detection can also be expressed using as V = (_A XOR _B) AND (_A XOR _result), highlighting how arises specifically from sign inconsistencies rather than merely the result's . For example, in an 8-bit system, adding +127 (01111111) and +1 (00000001) yields 10000000 (-128), setting =1 because both inputs are positive but the result appears negative, invalidating the signed operation. The negative flag, however, remains agnostic to such validity issues and simply reports the result's sign. A valid negative result, such as subtracting 100 from 50 to get -50 (11100010 in 8-bit two's complement), sets N=1 while leaving V=0, as no overflow occurs. This distinction ensures that N provides raw sign information for immediate use, whereas V requires checking to confirm arithmetic integrity. In signed comparisons, the flags are combined to achieve accurate relational tests that account for potential overflow. The condition for less-than (LT) is true when N XOR V = 1, which corrects for overflow scenarios by effectively using the "effective sign bit" (N XOR V) to determine the true ordering of signed operands. This approach, common in architectures like x86 and PDP-11, prevents misinterpretation of results tainted by overflow.

Relation to Zero Flag

The negative flag (N) and (Z) complement each other in analyzing operation results within CPU status registers, particularly in arithmetic and logical computations. The is set to 1 if the entire result is zero—all bits are 0—indicating equality or completion of a sequence, such as in or logical AND operations. In contrast, the negative flag is set to 1 if the most significant bit (MSB) of the result is 1, signifying a negative value in signed representations. This distinction allows N to focus solely on the , ignoring lower bits, while Z requires verification across all bits. In standard two's complement systems, the representation of zero is always the all-zero bit pattern, with the MSB cleared (0), ensuring that N=0 whenever Z=1. Both flags cannot be set simultaneously, as a negative zero does not exist distinctly; any apparent -0 is treated as positive zero. This behavior holds across architectures like ARM and x86, where instructions such as ADD, SUB, or CMP update both flags based on the result without overlap in the zero case. For combined usage, the serves as the primary indicator for checks (e.g., comparing two values yields =1 if identical), while the negative flag provides sign information only when =0, revealing whether a non-zero result is positive or negative. In logical operations like , or XOR, both flags are updated analogously: for instance, ANDing any value with produces an all-zero result, setting =1 and =0, as the MSB cannot be 1 in a zero pattern. This interplay supports efficient result analysis in algorithms, such as loop terminations where Z detects zero crossings and N assesses directional signs in signed magnitudes, without redundant bit inspections.

Applications

Conditional Branching

The negative flag, often denoted as N or SF in various architectures, plays a crucial role in enabling conditional branching based on signed arithmetic conditions in programming. Following arithmetic operations such as (SUB or CMP), the negative flag is set if the most significant bit of the result indicates a negative value in representation. This allows processors to perform branches that reflect signed comparisons, such as determining if one value is less than or greater than or equal to another, by examining the negative flag in conjunction with other status flags. In general, signed branching instructions like (branch if less than) evaluate to true when the differs from the (N ≠ V), while BGE (branch if greater than or equal) branches when they are the same (N = V). These conditions arise after a operation that sets the flags appropriately, providing a mechanism to implement signed inequalities without additional computations. This approach ensures that the behavior in arithmetic is correctly interpreted for decisions. In the x86 architecture, conditional jump instructions such as JL (jump if less than) and JGE (jump if greater than or equal) utilize the sign flag (, equivalent to N) XORed with the overflow flag (OF, equivalent to V) to determine the branch. Specifically, JL branches if SF ≠ OF, indicating a negative result from a signed , while JGE branches if SF = OF. This integration allows for efficient signed comparisons directly from the flags set by prior CMP instructions. Similarly, in architectures, conditional execution suffixes like LT (less than) and GE (greater than or equal) for branch instructions (e.g., B) check the negative flag (N) against the overflow flag (V). The LT condition holds when N ≠ V, and GE when N = V, enabling signed branching in a single instruction following data-processing operations that update the condition flags. In contrast, the 6502 processor employs simpler branching instructions (branch if minus) and BPL (branch if plus), which directly test the negative flag () without incorporating . BMI branches if N=1 (indicating a negative result), and BPL if N=0 (positive or zero). Programmers must manually account for overflow scenarios in signed comparisons, as the architecture lacks built-in integration of V with N for these branches. Overall, the use of the negative flag in these architectures facilitates efficient conditional branching for signed operations, often allowing single-instruction tests that avoid the need for explicit additional comparisons or multi-instruction sequences.

Usage in Assembly Programming

In assembly programming, the negative flag, often denoted as SF in x86 or N in ARM and 6502 architectures, serves as a key indicator for the sign of arithmetic results, enabling efficient conditional control flow for signed operations. Programmers leverage it primarily after comparison or arithmetic instructions to branch based on whether a value is negative, facilitating tasks like signed magnitude checks or inequality tests without additional computations. This flag's behavior aligns with two's complement representation, where it reflects the most significant bit of the result. A common pattern in x86 involves using the CMP instruction to set flags, followed by a conditional jump that incorporates the sign flag for signed comparisons. For instance, to branch if one holds a smaller signed value than another:
CMP AX, BX
JL label
Here, CMP subtracts BX from AX and sets SF if the result is negative, while JL (jump if less) branches if SF differs from the (OF), confirming AX < BX in signed arithmetic. This approach ensures correct handling of negative ranges, such as distinguishing -1 from 255 in byte operations. In , the negative flag (N) is tested via conditional branch suffixes after a CMP instruction, which performs a and updates the application program (APSR). An example checks if a register value is less than a constant in signed terms:
CMP R0, #10
[BLT](/page/BLT) loop
The CMP sets if R0 < 10 (signed), and (branch if less than) executes if N differs from the (), directing flow to the label for values like -5 but not 15. This idiom is prevalent in code for efficient decision-making in loops or handling. For the 6502 processor, common in retrocomputing and emulators, the (N) is set by CMP based on bit 7 of the implied result, with (branch if minus) providing a direct test for negative outcomes. A typical snippet loads a value and compares it to a :
LDA #50
CMP #100
BMI negative_handler
If the accumulator (50) is less than 100 in signed interpretation—though 50 is positive, this pattern shines for negative loads like LDA #$FF ( -1 ) versus #100, branching to negative_handler when is set. This simplicity makes it ideal for resource-constrained 8-bit systems. Best practices emphasize combining the negative flag with the for robust signed comparisons, as relying solely on N can fail in overflow scenarios; for example, in x86, use JL/ over JS/JNS to account for both and OF, preventing errors like misclassifying overflowed positive results as negative. Conversely, avoid applying signed flag tests (e.g., BMI or JL) in unsigned contexts, where carry or flags should dominate to prevent interpreting high-bit values (like 255) as negative, which could lead to incorrect branching in counters or addresses. Despite the rise of high-level languages, the negative flag remains relevant in modern low-level programming, appearing in OS kernels for interrupt handlers and context switches, embedded systems for sensor data processing, and emulators optimizing retro software, where inline assembly ensures performance-critical signed operations without abstraction overhead.

References

  1. [1]
    Condition Codes 1: Condition Flags and Codes - Arm Developer
    Sep 11, 2013 · N : Negative​​ The N flag is set by an instruction if the result is negative. In practice, N is set to the two's complement sign bit of the ...
  2. [2]
    Flag register in 8085 microprocessor - GeeksforGeeks
    Jul 11, 2025 · The Zero Flag is used to detect if the result of the logical operation was zero. The Sign Flag is used to detect if the result was negative.
  3. [3]
    CSCI 2400 - Computer Architecture
    The sign flag (SF) is used with signed arithmetic only. It tells you whether the result of an arithmetic operation results in a postive or negative value. The ...
  4. [4]
    When is the N (negative) flag set in assembly? - Stack Overflow
    Jan 19, 2017 · In all architectures that support flags, the N or Negative flag simply matches the most significant bit of the last number computed.Is the Negative condition flag N also set with an Overflow?Negative values with different flags - Stack OverflowMore results from stackoverflow.com
  5. [5]
    CSCI 2400 - Computer Architecture
    The sign flag (SF) is used with signed arithmetic only. It tells you whether the result of an arithmetic operation results in a postive or negative value. The ...Missing: CPU definition<|control11|><|separator|>
  6. [6]
    The general CPU Architecture - CS255 Syllabus
    PSR = processor status register (contains the state information of the processor ... N flag/bit = 1 means the result of the operation is negative, 0 means >= 0.
  7. [7]
    Most Significant Bit - an overview | ScienceDirect Topics
    The sign bit (msb) indicates a negative number. Whether or not a particular binary bit pattern represents a signed or unsigned number depends on the context in ...
  8. [8]
    Register Information in Detail - UMBC
    Sign is set when the result of an arithmetic or logical operation generates a negative number. Zero is set when the result of an arithmetic or logical operation ...
  9. [9]
    [PDF] Processor Status Flags Register
    Aug 9, 2021 · SF = 1 if the msb of a result is 1; it shows the result is negative if a signed interpretation is used. SF = 0 if the msb is 0 . 8/9/2021.
  10. [10]
    6502 Instruction Set - mass:werk
    The zero flag (Z) indicates a value of all zero bits and the negative flag (N) indicates the presence of a set sign bit in bit-position 7. These flags are ...
  11. [11]
    The 6502 Microprocessor - Syncopated Systems
    Feb 29, 2024 · Negative Flag (N). As already discussed, one of the uses of the microprocessor is to perform arithmetic operations on signed numbers. To ...
  12. [12]
    Silicon reverse-engineering: the Intel 8086 processor's flag circuitry
    Feb 11, 2023 · In this post, I take a close look at the flag circuitry in the Intel 8086 processor (1978), the chip that launched the PC revolution.
  13. [13]
    Two's complement – Clayton Cafiero - University of Vermont
    Signed integers are represented using the two's complement method. In this representation, all negative numbers have a leading 1 and non-negative numbers do not ...<|control11|><|separator|>
  14. [14]
    Sign(ed) 2's Complement
    The s2c form of a positive integer is identical to the sign-magnitude form of the positive integer. ... representation must be longer than 13 bits, say 16.
  15. [15]
    Two's Complement - CS@Cornell
    To get the two's complement negative notation of an integer, you write out the number in binary. You then invert the digits, and add one to the result.Contents and Introduction · Conversion from Two's... · Conversion to Two's...
  16. [16]
    Conversion of Signed Numbers to Two's Complement
    To convert a negative signed number to two's complement, first set the 8 th bit to zero. Then invert all 8 bits. Finally add 1.
  17. [17]
    Range of Integers with 2's Complement
    The range of integers that can be represented in eight bits using two's complement is: -( 2 (8-1) ) = -128 ... 0 ... 2 (8-1) - 1 = 127
  18. [18]
    The Two's Complement
    In the (8-bit) two's complement representation of a integer value between -127 and 127, positive integers are represented in the normal binary manner.
  19. [19]
    [PDF] Episode 3.04 – The Application of Twos Complement
    Twos complement representation not only allows us to represent negative integers using patterns of ones and zeros, it also fully supports addition for any ...
  20. [20]
    [PDF] 2's complement … … … Sign extension 42 = ________00101010
    If we use a two's complement representation for signed integers, the same binary addition mod 2n procedure will work for adding positive and negative numbers ( ...
  21. [21]
    x86 "Flag" Bits - CS 301 Lecture
    SF-- The "sign flag", which indicates a negative *signed* result. Used together with OF to implement signed comparison. OF-- The "overflow flag". Set by ...
  22. [22]
  23. [23]
    [PDF] Shift and Rotate Instructions
    An arithmetic shift is filled with a copy of the original number's sign bit. If we do a single arithmetic right shift on 11001111, it becomes 11100111. The ...
  24. [24]
    Shift operations - Arm Developer
    Arithmetic shift right by n bits moves the left-hand 32 - n bits of the register Rm , to the right by n places, into the right-hand 32 - n bits of the result.
  25. [25]
    [PDF] Intel® 64 and IA-32 Architectures Software Developer's Manual
    NOTE: This document contains all four volumes of the Intel 64 and IA-32 Architectures Software. Developer's Manual: Basic Architecture, Order Number 253665; ...
  26. [26]
    ADD — Add
    The SF flag indicates the sign of the signed result. This instruction can be used with a LOCK prefix to allow the instruction to be executed atomically. In 64- ...
  27. [27]
  28. [28]
    IMUL — Signed Multiply
    Performs a signed multiplication of two operands. This instruction has three forms, depending on the number of operands.
  29. [29]
  30. [30]
  31. [31]
    AND — Logical AND
    Performs a bitwise AND operation on the destination (first) and source (second) operands and stores the result in the destination operand location.
  32. [32]
    SAHF — Store AH Into Flags
    Loads the SF, ZF, AF, PF, and CF flags of the EFLAGS register with values from the corresponding bits in the AH register (bits 7, 6, 4, 2, and 0, respectively).
  33. [33]
    PUSHF/PUSHFD/PUSHFQ — Push EFLAGS Register Onto the Stack
    Decrements the stack pointer by 4 (if the current operand-size attribute is 32) and pushes the entire contents of the EFLAGS register onto the stack.
  34. [34]
    POPF/POPFD/POPFQ — Pop Stack Into EFLAGS Register
    Pops a doubleword (POPFD) from the top of the stack (if the current operand-size attribute is 32) and stores the value in the EFLAGS register.
  35. [35]
    The Application Program Status Register (APSR) - Arm Developer
    Negative condition flag. Set to bit[31] of the result of the instruction. If the result is regarded as a two's complement signed integer, then the processor ...
  36. [36]
    CPSR: Current Program Status Register - Arm Developer
    If the result is regarded as a two's complement signed integer, then N is set to 1 if the result was negative, and N is set to 0 if the result was positive or ...
  37. [37]
    Updates to the condition flags - Arm Developer
    Most ARM and Thumb data processing instructions only update the condition flags if you append an S suffix to the mnemonic.
  38. [38]
    CMP and CMN - Arm Developer
    These instructions update the N, Z, C and V flags according to the result. 16-bit instructions. The following forms of these instructions are available in Thumb ...
  39. [39]
    APSR: Application Program Status Register - Arm Developer
    Negative condition flag. Set to bit[31] of the result of the last flag-setting instruction. If the result is regarded as a two's complement signed integer ...
  40. [40]
    [PDF] ARM Instruction Set
    In ARM state, all instructions are conditionally executed according to the state of the. CPSR condition codes and the instruction's condition field.
  41. [41]
    Conditional execution - Arm Developer
    N = V. LT. Signed less than. N != V. GT. Signed greater than. Z = 0 AND N = V. LE. Signed less than or equal. Z = 1 OR N != V. AL. Always (this is the default ...
  42. [42]
    Conditional execution - Arm Developer
    N = V, Greater than or equal, signed. LT, N != V, Less than, signed. GT, Z = 0 and N = V, Greater than, signed. LE, Z = 1 and N != V. Less than or equal, signed.
  43. [43]
    Status flags - NESdev Wiki
    Oct 24, 2024 · On the original 6502, this flag causes some arithmetic instructions to use binary-coded decimal representation to make base 10 calculations ...
  44. [44]
    All About The Status Register - Classic Computer Magazine Archive
    N (bit 7)—Negative flag. (Some books call it S, for sign.) The N flag matches the high bit of the result of whatever operation the processor has just completed.
  45. [45]
    6502.org Tutorials: Decimal Mode
    Sep 12, 2016 · Decimal mode has some undocumented behavior. First, there is arthimetic when one or both numbers are invalid BCD. Second, there is the value of ...
  46. [46]
    Decimal mode Qs - nesdev.org
    Mar 24, 2022 · It sets all flags (N, Z, C, and V) after BCD fixing, not before as the original 6502. Thus, all flags reflect the result that ends up in the accumulator at the ...6502 Decimal Mode - nesdev.orgIllegal Instructions doing (A & Immediate), ANC/ALR/ARRMore results from forums.nesdev.org
  47. [47]
    [PDF] 3.4.3.1. status flags - cs.Princeton
    Sign flag.​​ sign bit of a signed integer. (0 indicates a positive value and 1 indicates a negative value.)
  48. [48]
    [PDF] Overflow: UB
    Overflow occurs when the result of adding two numbers is larger than the maximum possible, and can only occur when both numbers have the same sign.Missing: flag | Show results with:flag
  49. [49]
    Comparators - Harvard Extension School CSCI E-93
    z | (n xor v). • BLT. Branch if less-than. • Branch if source <SIGNED destination. • Branch if the previous operation causes N xor V to be 1: n xor v. 23. Page ...
  50. [50]
    Intel® 64 and IA-32 Architectures Software Developer Manuals
    Oct 29, 2025 · These manuals describe the architecture and programming environment of the Intel® 64 and IA-32 architectures.
  51. [51]
  52. [52]
    Condition code suffixes and related flags - Arm Developer
    Condition code suffixes and related flags ; GE, N and V the same, Signed >= ; LT, N and V differ, Signed < ; GT, Z clear, N and V the same, Signed > ; LE, Z set, N ...
  53. [53]
    Tutorials: Compare Instructions - 6502.org
    Dec 1, 2002 · The combination of these three flags indicate whether the register contents are less than, equal to (the same as), or greater than the operand " ...
  54. [54]
    [PDF] 2. Optimizing subroutines in assembly language
    Dec 23, 2015 · Signed integers are compared using the JL and JG instructions. Mixing signed and unsigned integers can have unintended consequences. 17 ...