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