Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Pascal Programming/Miscellaneous

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

The last Pascal-related standards were published in 1990, ISO International Organization for Standardization standard 7185 “[Standard] Pascal”, and ISO International Organization for Standardization standard 10206 “Extended Pascal”. But ever since IT information technology did not stop evolving. Several compiler manufacturers continued extending Pascal by miscellaneous extensions, some of which we are presenting here. Inline assembly Since TP Turbo Pascal version 1.0 there exists the possibility to include assembly language inside your Pascal source code. This is called inline assembly. While normal Pascal is surrounded by a begin … end frame, assembly language can be framed by asm … end. Here is an example that can be compiled with the FPC Free Pascal Compiler: program asmDemo(input, output, stdErr); {$ifNDef CPUx86_64} {$fail only for x86_64} {$endIf} var foo: int64; begin write('Enter an integer: '); readLn(foo); // This directive will tell FPC // a certain assembly language style is used // within the asm...end frame. {$asmMode intel} asm mov rax, [foo] // rax ≔ foo^ // ensure foo is positive test rax, rax // x ≟ 0 jns @is_positive // if ¬SF then goto is_positive neg rax // rax ≔ −rax @is_positive: // NOTE: Here we assume the popcnt instruction // was supported by the processor, // but this is bad style. // You ought to use the cpuid instruction // (if available) in order to determine // whether popcnt is available. popcnt rax, rax // rax ≔ popCnt(rax) mov [foo], rax // foo ≔ rax // An array of strings after the asm-block closing ‘end’ // tells the compiler which registers have changed // (you do not want to mess with the compiler’s understanding // which registers mean what) end ['rax']; writeLn('Your number has a binary digital sum of ', foo, '.'); end. Writing inline assembly code is useful if you have special knowledge about data and the compiler generates inefficient code. You can try to optimize for speed or size in order mitigate performance bottlenecks. All, Delphi, the FPC Free Pascal Compiler as well as the GPC GNU Pascal Compiler support asm frames, but each with a few subtle differences. We therefore refer to the compiler’s manuals, and not forgetting this book is about programming in Pascal. Resource strings Run-time type information Managed types Thread variables