Fourth Lecture x64 assembler, c / C ++ x64 assembler call

Fourth Lecture x64 assembler, c / C ++ x64 assembler call

A Dian Profile

1. Description

In x86, our C / C ++ compilation can call directly __asm inline.
Or you can statically linked directly

Specific details can refer to previous blog:

https://www.cnblogs.com/iBinary/p/7555503.html

In fact, we like x64 x32 call. But does not support inline compiled. Or support you compiled obj way to call you declare it ready for use.

Now we use a new method for direct preparation of a x64ASM file.

Two Dian C / C ++ function calls asm64.asm.

1. Configure involved in generating asm

First we create a C / C ++ project using VS to create a space that should be very simple not in a screenshot....
Then create a .c or .cpp file inside to follow the journey of writing, write your program..
Are as follows:


You can perform normal

Then we add a suffix .asm file. This file is like adding .cpp file. .Asm can change themselves.

as follows:

The most important step
you have this file, but can not participate in projects to generate so you need to change what attributes of the file so that it could participate in the project to generate and compile a compendium of compile time format...
Are as follows:

Generated from the project on behalf of your choice whether to participate in this file is generated.
The second is the selection tool, select Custom .... Because I set before. So the left have a custom
build tool

And an output setting command line compiler.
Follows:

Command line: Output:ml64 /Fo $(IntDir)%(fileName).obj /c %(fileName).asm
$(IntDir)%(fileName).obj

At this point we can participate in asm generated.

2. Asm file to add the function code

At this time, files can be generated. You can write x64 code. Below



.data

.const

.code

addNumber proc

    mov rax,rcx
    add rax,rdx
    ret
addNumber endp
end

3.C / C ++ function calls of asm

Above we wrote a asm function. When our C / C ++ statement about the call can be used
as the above code we operated rcx, rdx that we have two parameters.

as follows:

If your project is relatively large. Then you can compile your 64asm file add a header file

Header file a function declaration. Exported C way.
Your CPP file contains the header files.

Guess you like

Origin www.cnblogs.com/iBinary/p/10959448.html