Label
From Lazarus wiki
Revision as of 22:38, 1 February 2018 by Kai Burghardt (talk | contribs) (label section for Asm-blocks containing jump targets required, too)
│
Deutsch (de) │
English (en) │
français (fr) │
русский (ru) │
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 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
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.