Difference between revisions of "Label"
From Free Pascal wiki
Jump to navigationJump to searchm (grammar) |
(hint to math.sign) |
||
Line 28: | Line 28: | ||
{$else} | {$else} | ||
begin | begin | ||
+ | // This is what virtually math.sign does. | ||
+ | // The compiled code requires _two_ cmp instructions, though. | ||
if x > 0 then | if x > 0 then | ||
begin | begin |
Revision as of 22:47, 1 February 2018
│
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 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
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
// This is what virtually math.sign does.
// The compiled code requires _two_ cmp instructions, though.
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.