Branch (computer science)


Branch (computer science)

A branch is sequence of code in a computer program which is conditionally executed depending on whether the flow of control is altered or not (at the branching point). The term can be used when referring to programs in high level languages as well as program written in machine code or assembly language. Explicit branches in high-level programming languages usually take the form of conditional statements of various forms that encapsulates the branches of code that should be executed (or not) upon some condition; machine level instructions that define corresponding branches of code are denoted jump instructions. The principal function of a jump instruction can thus be compared to the GOTOs needed to build control structures in older high level languages.

Jump instructions typically have unconditional and conditional forms where the latter may be taken or not taken depending on some condition. The truthness of this condition is typically evaluated and temporarily stored by some previous instruction (not necessarily the one immediately before) and then used such as in jump if overflow-flag set. This temporary information is often stored in a flag register but may also be located elsewhere. There are also machines (or particular instructions) where the condition may be checked by the jump instruction itself, such as branch <label> if register X negative. When a branch is taken, the next instruction executed is defined by the argument to the jump instruction; when not taken, the next instruction executed is the instruction immediately following the jump instruction in memory so that the flow of control is unchanged.

Depending on computer architecture, the assembly language mnemonic for a jump instruction is typically some shortened form of the word jump or the word branch, often along with other informative letters (or an extra parameter) representing the condition. Sometimes other details are included as well, such as the range of the jump (the offset size) or a special addressing mode that should be used to locate the actual effective offset.

Typical branch/jump instructions exemplified by some well-known architectures

condition or result x86 PDP-11, VAX ARM (partly 6502) equation
zero (implies equal for sub/cmp) JZ; JNZ BEQ; BNE BEQ; BNE zero; not zero
negative (N), sign (S), or minus (M) JS; JNS BMI; BPL BMI; BPL negative; not negative
arithmetic overflow (flag called O or V) JO; JNO BVS; BVC BVS; BVC overflow; not overflow
carry (from add,cmp,shift, etc.) JC; JNC BCS; BCC BCS; BCC carry; not carry
unsigned below (lower) JB BLO BLO * borrow
unsigned below or equal (lower or same) JBE BLOS BLS * borrow or zero
unsigned above or equal (higher or same) JAE BHIS BHS * not borrow
unsigned above (higher) JA BHI BHI * not borrow and not zero
signed less than JL BLT BLT sign≠overflow
signed less or equal JLE BLE BLE sign≠overflow or zero
signed greater or equal JGE BGE BGE sign=overflow
signed greater than JG BGT BGT sign=overflow and not zero

* x86, the PDP-11, VAX, and some others, set the carry-flag to signal borrow and clear the carry-flag to signal no borrow. ARM, 6502, the PIC, and some others, do the opposite for subtractive operations. This inverted function of the carry flag for certain instructions is marked by (*), that is, borrow=not carry in some parts of the table, but if not otherwise noted, borrow≡carry. However, carry on additive operations are handled the same way by most architectures.

External links

See also


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Computer science — or computing science (abbreviated CS) is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems. Computer scientists invent algorithmic… …   Wikipedia

  • COMPUTER SCIENCE — The term Computer Science encompasses three different types of research areas: computability, efficiency, and methodology. General Introduction Computability deals with the question of what is mechanically computable. The most natural way to… …   Encyclopedia of Judaism

  • computer science — noun the branch of engineering science that studies (with the aid of computers) computable processes and structures • Syn: ↑computing • Topics: ↑computer, ↑computing machine, ↑computing device, ↑data processor, ↑electronic computer, ↑ …   Useful english dictionary

  • Vectorization (computer science) — Vectorization, in computer science, is the process of converting a computer program from a scalar implementation, which does an operation on a pair of operands at a time, to a vectorized program where a single instruction can perform multiple… …   Wikipedia

  • Offset (computer science) — For other uses, see Offset. In computer science, an offset within an array or other data structure object is an integer indicating the distance (displacement) from the beginning of the object up until a given element or point, presumably within… …   Wikipedia

  • Recursion (computer science) — Recursion in computer science is a way of thinking about and solving problems. It is, in fact, one of the central ideas of computer science. [cite book last = Epp first = Susanna title = Discrete Mathematics with Applications year=1995… …   Wikipedia

  • Unification (computer science) — Unification, in computer science and logic, is an algorithmic process by which one attempts to solve the satisfiability problem. The goal of unification is to find a substitution which demonstrates that two seemingly different terms are in fact… …   Wikipedia

  • Slipstream (computer science) — A slipstream processor is an architecture designed to reduce the length of a running program by removing the non essential instructions.It is a form of speculative computing.Non essential instructions include such thing as results that are not… …   Wikipedia

  • Category:Logic in computer science — Logic in computer science is that branch of mathematical logic which is approximately the intersection between mathematical logic and computer science. It contains: Those investigations into logic that are guided by applications in computer… …   Wikipedia

  • Computability theory (computer science) — In computer science, computability theory is the branch of the theory of computation that studies which problems are computationally solvable using different models of computation.Computability theory differs from the related discipline of… …   Wikipedia