Вопрос

I wrote some assembler modules and used constant variables to define their size in FASM.

How can I use these variables in VC++ after linking with an FASM object file?

For example, if my assembler code is like so:

start: //function declaration, exported
xor eax, eax
inc eax
retn
end_func:

The size is end_func - start

How can I export the size of end_func - start into VC++?

Это было полезно?

Решение

You can export a variable with the public directive on the FASM side, and import it into your C++ code with extern.

Here's a short example:

// --- test.asm ---
format MS COFF

public counter as '_counter' 

section '.data' data readable writeable
counter dd 0x7DD

// --- example.cpp ---
#include <iostream>

extern "C" long int counter;

int main() {
    std::cout << "Hello " << ++counter << "!" << std::endl;
    return 0;
}

// --- Compile, Link and Run ---
> fasm test.asm
> cl /EHs example.cpp test.obj
> example.exe

// --- Output: ---
Hello 2014! 

The example uses the MSVC cl.exe compiler directly on the command line for illustrative purposes, however in your case it should be trivial to add the fasm .obj output files to link with your code in the VS link project settings.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top