News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

integrating masm source and object files into C++ Builder 2006 projects?

Started by bobl, April 26, 2013, 04:11:59 AM

Previous topic - Next topic

bobl

I've tried a couple of "simple" but seemingly incomplete examples on the net
re how to incorporate STAND-ALONE asm files into C Builder projects but have singularly failed to get anything to work.

I'd welcome some help to get something working...ideally...a function that takes a parameter doubles it and spits it back...for e.g. a button to ShowMessage().

In the Build configuration Window...I saw Tasm there but no option to choose masm.

I'd also like to know...if I build masm obj files outside of C++ Builder (my preference)....how would I best link these in C++ Builder.

Any help much appreciated.
 

Gunther

Hi bobl,

how about showing your code? You'll get better and more precise answers.

Gunther
You have to know the facts before you can distort them.

dedndave

i would think the simplest way is to create an OBJ file from the masm source, then link it with your program
does C++ Builder give you that kind of capability ?

jj2007

Hi Bobl,

Welcome to the forum :icon14:

The standard way of doing this is to assemble the asm source and keep the obj file. Then you just declare the exported functions in your C or C++ code and add the obj file to the linker commandline.

Example:
#include <stdio.h>
#include <stdlib.h>

int MasmProggie(int, int);

int main(int argc, char* argv[])
{
  int i=123; //just for fun
  printf("Arg count=%d\n", argc);
  printf("The product of argct and i: %d\n", MasmProggie(i, argc));
  return 0;
}


Assembler:
include \masm32\include\masm32rt.inc

MasmProggie PROTO C :SDWORD, :SDWORD

.code
MasmProggie proc C x:SDWORD, y:SDWORD
  mov eax, x
  mul y
  ret ; return value already in eax
MasmProggie endp
end

bobl

Gunther
That was fast! and yes that's a fair request...
I don't have my own code at the moment because I'm struggling to get the examples here working
i.e.
http://www.cpp-home.com/tutorials/291_1.htm


; MyCode.asm

.586p
model flat
locals

.DATA

.CODE

PUBLIC C MySubroutine
MySubroutine PROC C Arg1:DWORD, Arg2:DWORD

       fld          Arg1
       fmul       Arg2
       ret

ENDP
END


I'm saying in my form module...

#include myasm.asm
extern "C" float MySubroutine(float Arg1,float Arg2);


and then in my form button routine

float Result = MySubroutine(FirstNumber,SecondNumber);


At first I got some linker fixup error and then the assembler complained about the first line i.e. the comment?
Does that help?

Dave...thank's for the suggestion.
I'd like to do things that way too. I can't believe BDS 2006 won't compile obj files but I'm afraid I don't know how.
Having said that...in searching today I came across a page of some book on google books that said Delphi doesn't like masm asm so I don't know. When I looked at the build configuration for my project...I could see Tasm there but no masm option.

jj2007
Thank you very much for the example code...
At the moment I've only used the IDE's build and run facility which insulates you from the nitty gritty of the linker
and I mostly use Powerbasic which again doesn't really expose you to the linker.
Does all that extern stuff become redundant?
I haven't tried this for ages but do remember getting a lot of help from this forum.

dedndave

Quote#include myasm.asm

i think that's where the problem lies
it won't eat that asm code very well

you may need to put the OBJ in a static LIB
then, create a .h include file and link with the library   :t

i should mention - i am not a C guy, nor am i a C++ Builder guy, either - lol
perhaps some of the other members have more experience with it, like Vortex

bobl

Yes
I don't feel at all confident including asm files.
I read somewhere that you just
create a file.asm
add it to your project using shift/f11
include a .h file that contains the asm procedure's declaration
and the thing builds at push of a button

It's not working for me so either I'm doing something wrong or it's not true.
Although I've tried a few examples today...I have got anything working and am all out of examples hence this post.

>Welcome to the forum :icon14:
Thank you very much!
I'm not new but haven't stopped by for ages although my skill level is as if I'm a newbie!
The last time Dave helped me a lot.
I am very interested in asm but don't get the time I'd like to study it.

>i am not a C guy, nor am i a C++ Builder guy,
That doesn't matter Dave...you're comments are always helpful and always get me there that much quicker.

dedndave

that method probably works if your asm file uses TASM syntax

but, if you want to use MASM syntax, i think you'll have to link an OBJ or LIB

Gunther

Hi Dave,

Quote from: dedndave on April 26, 2013, 05:13:29 AM
that method probably works if your asm file uses TASM syntax

but, if you want to use MASM syntax, i think you'll have to link an OBJ or LIB

TASM uses MASM syntax. The other point would be, if he would use TASM's IDEAL Mode syntax, but that's not the case.

Gunther
You have to know the facts before you can distort them.

qWord

bobl,

you maybe search for an compiler (or IDE) specific forum to get the right tips, even people here happily mix C and C++  :P. Actual I would formulate your question in this way: does your linker support OMF or COFF object files and if so, how to add these to the link process.
MREAL macros - when you need floating point arithmetic while assembling!

Vortex

Hi bobl,

QuoteActual I would formulate your question in this way: does your linker support OMF or COFF object files and if so, how to add these to the link process.

qWord is right. You would like to check Agner Fog's Object file converter :

http://agner.org/optimize/

Gunther

I think that doesn't help our new member not very much.

I've checked your link from post #4. That tutorial isn't complete and doesn't explain very much. I know that Alex (Antariy) has some experiences with Borland's Builder. I've only an old machine in the basement with BC 4.0 installed. My proposal is: try to compile your program at the command line; an assembly language programmer has to master the command line.

Quote from: bobl on April 26, 2013, 04:42:57 AM

extern "C" float MySubroutine(float Arg1,float Arg2);


That source line is okay, because it avoids the name mangling and name decoration which is usual in C++.
Quote from: bobl on April 26, 2013, 04:42:57 AM

float Result = MySubroutine(FirstNumber,SecondNumber);


The function call is also okay. Delete now the the including #include myasm.asm. Try this line at the command line:


tasm /m2/q myasm.asm
 

The m2 switch allows 2 passes and the q switch suppresses OBJ records which are not needed for linking. The result should be myasm.obj.

Compile now your C++ source with bcc32.exe (or whatever EXE the Builder package provides) with the following command line:

bcc32 -c mysource.cpp


The -c switch is, compile, do not link. The result should be a mysource.obj.

Now link all together to the running EXE with the following command line:


tlink /3 mysource.obj myasm.obj, mysource.exe


The /3 switch ensures 32-bit linking.

A last advice: Since TASM is no longer supported, you should check the alternatives. There are a lot available: masm, jWasm, solasm, nasm, yasm etc. I hope that helps a bit.

Gunther
You have to know the facts before you can distort them.

hutch--

The problem is using the old Borland C++ builder, it needs a compatible OMF format object module that can be linked into the main application. Alternately the OMF module needs to be built into a library. I have not looked at TASM for about 15 years so i am not up to date with it but if you insist on using the old Borland builder, you will need to use an old copy of TASM or something that is compatible with it.

bobl

Dave,  Gunther, qWord, Vortex, Hutch
Thank you for a great response.
Your example and suggestions have certainly given me some avenues to explore.
I'm determined to crack this and will post back when I've got something.
In the meantime...thank you all!

BTW
my Builder 2006 comes with Tasm from 1996...patched to 2002.
On the same wiki page it looks like the only Tasm compatible alternative (ideal mode) is Lazy Assembler from 2007.
Both look old.

bobl

I've just found out how to turn the command line on in the IDE...Here's the linker line for an empty vcl project
i.e. just the default blank form

Linker command line
  -aa -Tpe -Gn -v -L"c:\program files\borland\bds\4.0\lib\debug";"c:\program files\borland\bds\4.0\lib";"c:\program files\borland\bds\4.0\lib\obj"
  "c:\program files\borland\bds\4.0\lib\psdk";"c:\program files\borland\bds\4.0\Include\Indy9";"c:\program files\borland\bds\4.0\Lib\Indy9"
  "C:\Documents and Settings\me\My Documents\Borland Studio Projects\bpl" -x -L"C:\Documents and Settings\me\My Documents\Borland Studio Projects"
  -GA"C:\Documents and Settings\me\My Documents\Borland Studio Projects\vfs22.tmp"="C:\Documents and Settings\me\My Documents\Borland Studio
  Projects\Project1.res" -GA"C:\Documents and Settings\me\My Documents\Borland Studio Projects\vfs23.tmp"="C:\Documents and Settings\me\My
  Documents\Borland Studio Projects\Unit1.dfm" c0w32.obj vcl.bpi rtl.bpi vclx.bpi dbrtl.bpi vcldb.bpi adortl.bpi dbxcds.bpi dbexpress.bpi vclib.bpi
  ibxpress.bpi xmlrtl.bpi vclactnband.bpi inet.bpi IntrawebDB_80_100.bpi Intraweb_80_100.bpi vclie.bpi inetdbbde.bpi inetdbxpress.bpi indy.bpi
  bcbsmp.bpi soaprtl.bpi dsnap.bpi bcbie.bpi bdertl.bpi teeui.bpi teedb.bpi tee.bpi vcldbx.bpi memmgr.lib sysinit.obj "C:\Documents and Settings\me\My
  Documents\Borland Studio Projects\Debug_Build\Project1.obj" "C:\Documents and Settings\me\My Documents\Borland Studio
  Projects\Debug_Build\Unit1.obj","C:\Documents and Settings\me\My Documents\Borland Studio Projects\Debug_Build\Project1.exe","C:\Documents and
  Settings\me\My Documents\Borland Studio Projects\Debug_Build\Project1.map",import32.lib cp32mti.lib,, "C:\Documents and Settings\me\My
  Documents\Borland Studio Projects\vfs22.tmp"

At least it's a start.