Label

This is an old revision of Label, edited by Kai Burghardt at . The current revision is 45536.

grammar

The label keyword is used for declaration of labels (markers for unconditional jumps using goto keyword) used further in the unit/program.

A label section is also required for jump targets in asm-blocks.

program sign(input, output, stderr);

type
    signumCodomain = -1..1;

{ returns the sign of an integer }
function signum(const x: longint): signumCodomain;
{$ifdef CPUx86_64}
assembler;
{$goto on}
label
    signum_done;
{$asmMode intel}
asm// result := 1// x = 0 ?// if x > 0 then goto signum_done// result := -1// if x < 0 then goto signum_done// result := 0
    mov @result, 1  // result := 1
    cmp x, 0        // x = 0 ?
    jg signum_done  // if x > 0 then goto signum_done
    mov @result, -1 // result := -1
    jl signum_done  // if x < 0 then goto signum_done
    mov @result, 0  // result := 0
signum_done:	
END;
{$else}
begin
    if x > 0 then
    begin
        signum := 1;
    end
    else if x < 0 then
    begin
        signum := -1;
    end
    else
    begin
        signum := 0;
    end;
end;
{$endif}

var
    x: longint;
begin
    readLn(x);
    writeLn(signum(x));
end.