Difference between revisions of "Lazarus inline assembler"

From Lazarus wiki
Jump to navigationJump to search
(New page: = Lazarus Inline Assembler = This is a stub to encourage others to contribute further. Here is a very simple example to get started: <pre> Code here </pre>)
 
m (Fixed syntax highlighting)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= Lazarus Inline Assembler =
+
{{Stub}}
 +
 
 
This is a stub to encourage others to contribute further. Here is a very simple example to get started:
 
This is a stub to encourage others to contribute further. Here is a very simple example to get started:
<pre>
+
 
Code here
+
<syntaxhighlight lang=pascal>
</pre>
+
unit unt_asm;
 +
{$mode objfpc}{$H+}
 +
interface
 +
uses
 +
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls;
 +
type
 +
  { TForm1 }
 +
  TForm1 = class(TForm)
 +
    btnGo: TButton;
 +
    edtInput: TEdit;
 +
    edtOutput: TEdit;
 +
    Label1: TLabel;
 +
    Label2: TLabel;
 +
    procedure btnGoClick(Sender: TObject);
 +
  private
 +
    { private declarations }
 +
  public
 +
    { public declarations }
 +
  end;
 +
var
 +
  Form1: TForm1;
 +
implementation
 +
{ TForm1 }
 +
 
 +
procedure TForm1.btnGoClick(Sender: TObject);
 +
var
 +
  num, answer : integer;
 +
begin
 +
  num := StrToInt(edtInput.Text);
 +
  //This is required with Lazarus on x86:
 +
  {$ASMMODE intel}
 +
  asm
 +
    MOV EAX, num
 +
    ADD EAX, 110B //add binary 110
 +
    SUB EAX, 2    //subtract decimal 2
 +
    MOV answer, EAX
 +
  end;
 +
  edtOutput.Text := IntToStr(answer);
 +
end;
 +
 
 +
initialization
 +
  {$I unt_asm.lrs}
 +
end.
 +
</syntaxhighlight>
 +
 
 +
[[Category:Proposals]]

Latest revision as of 01:13, 19 February 2020

An editor has declared this article to be a stub, meaning that it needs more information. Can you help out and add some? If you have some useful information, you can help the Free Pascal Wiki by clicking on the edit box on the left and expanding this page.


This is a stub to encourage others to contribute further. Here is a very simple example to get started:

unit unt_asm;
{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
  { TForm1 }
  TForm1 = class(TForm)
    btnGo: TButton;
    edtInput: TEdit;
    edtOutput: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure btnGoClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end; 
var
  Form1: TForm1; 
implementation
{ TForm1 }

procedure TForm1.btnGoClick(Sender: TObject);
var
  num, answer : integer;
begin
  num := StrToInt(edtInput.Text);
  //This is required with Lazarus on x86:
  {$ASMMODE intel}
  asm
    MOV EAX, num
    ADD EAX, 110B //add binary 110
    SUB EAX, 2    //subtract decimal 2
    MOV answer, EAX
  end;
  edtOutput.Text := IntToStr(answer);
end;

initialization
  {$I unt_asm.lrs}
end.