Label (programming)

from Wikipedia, the free encyclopedia

A label (in German: jump label ) in a source code of a computer program is a label which is clearly identified by an identifier and which usually serves as a jump destination.

use

Assembly languages

To use in an assembly language e.g. B. To implement loops, it is usually possible to jump relative to the current command counter - for example 5 commands back. But this is very inflexible: if, for example, a command is inserted or removed, all relative jumps that jump over this point must be adjusted. In addition, this is difficult to read because it is then often necessary to count individual program sequences command by command.

Jump labels exist to circumvent these problems. These provide a position in the source text with a unique identifier. So you can go directly to this brand, i. H. You can jump to this code without the problems described above occurring.

Example in a pseudo assembly language:

mov $v0, 0
MeinLabel:                 ; hier wird ein Label mit dem Bezeichner "MeinLabel" gesetzt
  add  $v0, $s0            ; Code im "Schleifenkörper"
  subi $t0, 1              ; Code im "Schleifenkörper"
bne $t0, $zero, MeinLabel  ; bedingter Sprung zum Label
                           ; hier geht es weiter, wenn nicht gesprungen wird

Higher programming languages

Some higher-level programming languages - especially older ones - also offer the option of setting jump labels in order to get to specific code positions using direct jumps (usually called goto ). However, their use in larger programs quickly leads to source code that is confusing, difficult to read and difficult to maintain (so-called spaghetti code ).

Modern programming languages ​​therefore have suitable control statements that make the use of jump labels and direct jumps in the source text superfluous, so that they no longer exist in many programming languages ​​or only to a very limited extent (e.g. in the case statements of C # ).

Another construct that can replace jump statements in many high-level programming languages ​​is structured exception handling , usually with the statements try , finally and catch or except .

Algorithmics

In German-language descriptions of algorithms, the term is synonymous with identifier or attribute . Exemplary pairs of meanings are

  • labeled = marked and
  • Labels = attributes / identifiers.

See also