Inline Assembler Basics

Source: Internet
Author: User

A few days to see the Sun Yuan and several other friends about assembly language, a few articles, quite interested. So I looked up the 98 MSDN, and there were a few basics about inline compilations, which are ASM. Not too difficult to speak, so try to write down its contents, hereby posted.

I. Inline compilation Brief

Under the Visual C + + 6.0 compiler, the inline assembler can use all the Intel486 processor instruction sets. And the target processor can be set up pseudo directive to implement additional instruction function. Inline assembler can use an expression allowed by the MASM compiler, some of which can operate on a single fine value by combining operators and operands.

Although inline assembler can access data variables and class objects in c\c++, it is not possible to define data and objects through MASM directives and operators. In particular, you cannot use the DB, DW, DD, DQ, DT, and DF definition directives as well as the DUP and the This operator. The structure records in the assembly are also not available. Inline assembler also does not support Directives Struc, record, WIDTH, and mask instructions. However, inline assembler can be used to a _EMIT macro directive, it is similar to the DB instruction in MASM, which defines a byte type within the region, although it can define only one byte at a time, but it is still possible to define a string, see the example:

#define randasm __asm _emit 0x4A __asm _emit 0x43 __asm _emit 0x4B

__asm
{
   randasm
}

Although the inline assembler does not support many of the instructions in MASM, it supports even and align directives. They are used for assembly instructions that require the use of align labels to specify a dividing line.

Inline assembly can not be a macro assembler, you can not use the macros in MASM to define directives and macro operators. Inline assembler, however, can define macros by using the c\c++ instructions in the.

When dealing with segments, you can only use registers, not names, because this is illegal in inline assembly. And the segment must explicitly use registers, such as: ES:[BX]

The inline assembler uses the operator length, SIZE, and type to measure the length of the variable as well as the type, which you can use to obtain the length of the variable and the type in the c\c++:

The *length operator can return the number of elements in an array of variables, and if returned to 1 it means that this is not an array of variables.

The *size operator can derive the total length of a variable and a type. This value can also be evaluated by length and type product.

The *type operator can derive the length of a variable and a type, unlike size, which returns the length of a single element in the array if the variable name is an array.

For details, please see the following table:

__asm C Size
LENGTH arr sizeof (arr)/sizeof (arr[0)) 8
SIZE arr sizeof (ARR) 16
TYPE arr sizeof (Arr[0]) 2

Programs that contain inline compilations can be compiled using the/ZI option, which allows for code-level debugging. In this way, you can set breakpoints in both the c\c++ and inline assembly segments, and if you use the/FAS option to allow mixed assembly and c\c++ source debugging, you can see a collection of code that mixes the assembly with the source program.

The Visual C + + compiler allows you to use the Intel processor's MMX instruction set in an inline assembler. However, a warning occurs if the MMX instruction set compiler is used. For more information, check out the MSDN Web site.

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.