Lazarus inline assembler: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Lazarus Inline Assembler
| Old | New | Line | |
|---|---|---|---|
| 1 | + | This is a stub to encourage others to contribute further. Here is a very simple example to get you started: | |
| 2 | + | ||
| 3 | + | ``` pascal | |
| 4 | + | unit unt_asm; | |
| 5 | + | {$mode objfpc}{$H+} | |
| 6 | + | interface | |
| 7 | + | uses | |
| 8 | + | Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls; | |
| 9 | + | type | |
| 10 | + | { TForm1 } | |
| 11 | + | TForm1 = class(TForm) | |
| 12 | + | btnGo: TButton; | |
| 13 | + | edtInput: TEdit; | |
| 14 | + | edtOutput: TEdit; | |
| 15 | + | Label1: TLabel; | |
| 16 | + | Label2: TLabel; | |
| 17 | + | procedure btnGoClick(Sender: TObject); | |
| 18 | + | private | |
| 19 | + | { private declarations } | |
| 20 | + | public | |
| 21 | + | { public declarations } | |
| 22 | + | end; | |
| 23 | + | var | |
| 24 | + | Form1: TForm1; | |
| 25 | + | implementation | |
| 26 | + | { TForm1 } | |
| 27 | + | ||
| 28 | + | procedure TForm1.btnGoClick(Sender: TObject); | |
| 29 | + | var | |
| 30 | + | num, answer : integer; | |
| 31 | + | begin | |
| 32 | + | num := StrToInt(edtInput.Text); | |
| 33 | + | //This is required with Lazarus on x86: | |
| 34 | + | {$ASMMODE intel} | |
| 35 | + | asm | |
| 36 | + | MOV EAX, num | |
| 37 | + | ADD EAX, 110B //add binary 110 | |
| 38 | + | SUB EAX, 2 //subtract decimal 2 | |
| 39 | + | MOV answer, EAX | |
| 40 | + | end; | |
| 41 | + | edtOutput.Text := IntToStr(answer); | |
| 42 | + | end; | |
| 43 | + | ||
| 44 | + | initialization | |
| 45 | + | {$I unt_asm.lrs} | |
| 46 | + | end. | |
| 47 | + | ``` | |
| 48 | + | ||
| 49 | + | ## See also | |
| 50 | + | ||
| 51 | + | - [[VirtualTreeview Example for Lazarus]] | |
| 52 | + | ||
| 53 | + | --- | |
| 54 | + | *From the Free Pascal wiki, page "Lazarus Inline Assembler", as it stood on 2020-01-09 after a change by Bart, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 55 | + | Category: Tutorials |
