flat assembler
Message board for the users of flat assembler.
Index
> Windows > linking c w/ asm |
Author |
|
decard 07 Dec 2003, 20:16
try this:
Code: format COFF ; or MS COFF public inc_var as "_inc_var" inc_var: push ebp mov esp,ebp mov eax,dword ptr [ebp+8] pop ebp inc eax ret it is mentioned in fasm manual: Quote: "public" directive declares the existing symbol as public, it should be followed by the name of symbol, optionally it can be followed by the "as" operator and the quoted string containing name under which symbol should be available as public. regards |
|||
07 Dec 2003, 20:16 |
|
Paul6253 07 Dec 2003, 22:34
Thanks for info...
still having probs with linker(ld) complaining of undefined symbol, using dev C++ compiler... i dunno, but too tired cya later _________________ Plez xcuce mi spelng |
|||
07 Dec 2003, 22:34 |
|
vid 08 Dec 2003, 06:14
in C++ code you must declare variable (inc_var, the one defined in asm part) in extern "c" {} block. It has what to do with way C++ compiler interprets names. C names were just "decorated" with "_" prefix (you see it in asm code, _inc_var), while C++ names do not have any standard, they differ on some compiler. extern "C" { } tells compiler to declare C names (_ prefix) in block
|
|||
08 Dec 2003, 06:14 |
|
milind 23 Feb 2004, 12:49
This thread was helpful, but I would like to know how to reference a variable declared in C++ in the assembly code??
I think in assembler we can use: extrn "_myvar" as myvar But how should the variable be defined in C++ ?? |
|||
23 Feb 2004, 12:49 |
|
milind 23 Feb 2004, 12:50
Another thing is how can we determine whether the routine in Assembly has been called via a far call or a near call?
|
|||
23 Feb 2004, 12:50 |
|
decard 23 Feb 2004, 12:54
proably it would be something like:
Code: extern "C" { int my_var; }; But I can't check it rightnow because I have recently reinstalled my system and I have to download and install mingw... regards |
|||
23 Feb 2004, 12:54 |
|
milind 23 Feb 2004, 13:13
So whats the difference between a variable declared in Assembly and a variable declared in C++ with respect to its referencing in C++??
|
|||
23 Feb 2004, 13:13 |
|
decard 23 Feb 2004, 13:22
- data defined in C and C++ goes automatically to the data section, while in assembly you can put it where you want
- names in C are "decorated" in object file - that's why you have to use "_" preffix in the assembly source. C++ makes even more complicated decorations, that's why the easiest way is tu use "extern "C" {" when using them in asm. regards |
|||
23 Feb 2004, 13:22 |
|
f0dder 23 Feb 2004, 16:39
If you use headers for use both with C and C++, a construct like the following saves the day
Code: #ifdef __cplusplus extern "C" { #endif // prototypes and stuff goes here #ifdef __cplusplus } #endif |
|||
23 Feb 2004, 16:39 |
|
Vortex 23 Feb 2004, 18:45
Paul6253,
About Dev C++ compiler, does it support MS COFF output? For an example of using Fasm with VC++ , have a look at this thread _________________ Code it... That's all... |
|||
23 Feb 2004, 18:45 |
|
vid 23 Feb 2004, 19:08
OK, the main problem with symbols decoration in C++ part is that there is no standard for this decoration. C decoration with "_" prefix is standard, but there is lack of such standard for C++ so every compiler uses another standard. If you want to know name for some compiler, just look at link errors saying some symbol is undefined. It usually shows already decorated name.
|
|||
23 Feb 2004, 19:08 |
|
decard 23 Feb 2004, 20:36
Vortex wrote: About Dev C++ compiler, does it support MS COFF output? It doesn't. Actually DevC++ is not a compiler, it's just an IDE for gcc compiler that produces "ordinary" COFF objects. When I was making simple tests with interfacing assembly and C, I realised that both formats (COFF and MS COFF) are at least partially compatible. When I compiled a small object (just a few bytes of code), the only two or three bytes were different. And I was able to link this simple MS COFF output using gcc linker, that normally works with "ordinary" COFF. I just wonder 'when' those formats would be incompatible... regards |
|||
23 Feb 2004, 20:36 |
|
f0dder 23 Feb 2004, 20:41
Afaik the only incompatibilities between GNU-coff and ms-coff are with regards to relocations. One format stores 0 for imm32 and relies on the linker to fix up the symbol completely, the other stores module-relative in imm32 and depends on the linker to just add the relocation delta... something like this, anyway. Thus, it should be possible to make a tool to convert between the two.
|
|||
23 Feb 2004, 20:41 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.