Delphi Embedded Assembly for beginners [3]-the first example of Delphi and assembly

Source: Internet
Author: User
I have known a value assignment instruction (mov) of an Assembly and an addition instruction (ADD), so I can give an example.

For example: Add ax, BX; this is equivalent to ax: = AX + bx in Delphi;

In addition, a list is provided in advance-Delphi can use assembler to manage the following registers:
32-bit register: eax EBX ECx edX ESP EBP ESI EDI
16-bit register: ax bx cx dx sp bp Si Di
8-bit register: Al BL Cl DL Ah BH ch DH
16-bit register: cs ds ss es and coprocessor register stack: St

Unit unit1; interfaceuses windows, messages, extensions, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; Procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} // use the function add (X, Y: integer) of the Assembly function: integer; var count: integer; begin ASM mov eax, X {put the X value into the register eax} mov ECx, y {put the Y value into the register ECx} Add eax, ECx {put the value of eax + ECx into eax} mov count, eax {returns the eax value to the variable count} end; Result: = count; {return value} {each statement in ASM can be divided into sentences by line feed. No need to add it here.} end; // Test Procedure tform1.button1click (Sender: tobject); var I: integer; begin I: = add (2, 4); showmessage (inttostr (I); {6} end; end.

  

Supplemented comments and clauses embedded in the Assembly:
1. Comments are the same as those in Delphi.
2. You can use semicolons (;) to separate sentences.
3. Use line breaks
4. You can even use comments to separate sentences.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.