Flag

From C64-Wiki
Jump to navigationJump to search

A flag is a term used to refer to the label of a predefined bit or collection of bits (known as a bit sequence, bit field or a flag field).

Purpose[edit | edit source]

The purpose of a flag is to act as a marker that signals “whether something has, or has not occurred”[1]. This marker may indicate the intermediate or final state of a hardware or software operation. As a component of a programming language's data structure (software) or of a logic circuit (hardware), the interpretation of the flag’s value is always relative. The flag can directly impact subsequent operations, but it means nothing outside of its context.

As a flag is based upon a bit (or bits) its condition is binary, and so will be in one of two states: one or zero, on or off, true or false. A flag is said to be 'set' when it is turned on and 'unset' or 'cleared' when turned off.

Sequences and Fields[edit | edit source]

If a flag represents a single bit, a number of bits used together to signal a result form a bit sequence, bit field or a flag field. When the bits are contained within the eight bits of a byte or word, then they can form an integer. Various interpretations can then be performed on the variable values of the Boolean bits in the integer. Flag field values often reflect the high-level conceptual state of the entity that the object represents, and flag changes correspond to changes in the conceptual state of the entity [2].

The Status Register Flags[edit | edit source]

Main article: Status Register

The CPU of the C64 has a byte-wide Status Register however, there are only seven meaningful flags; which indicate various post-operation conditions. The flags in the Status Register are affected by different (CPU) instructions in different ways. For example, there is a flag that is set when an instruction has caused a zero result, and is reset when a result is not zero. The instruction LDA #$00 will cause the zero result flag to be set, because the instruction has resulted in the accumulator containing a zero [3].

References[edit | edit source]