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

Gunther

Hi bobl,

Quote from: bobl on April 26, 2013, 04:50:06 PM
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.

that's the point. We've since 2002 a lot of development of the available instruction sets, which the TASM don't know. You could, of course, hack in the new instructions via DB; it'll work, but it's very awkward. On the other hand, there are productive C and C++ compilers around (VC, gcc), which will that simple sources translate uncomplaining. You should think about that point and change the used tools.

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

bobl

>it needs a compatible OMF format object module
I had to try and used the first example here i.e.
http://masm32.com/board/index.php?topic=1273.0
making it an obj file...and then including the obj into a vcl project using shift/F11.
As Hutch predicted I got...

[Linker Error] Error: 'C:\MY_DELPHI\MY_CBUILDER2006\PROJ3\MYASM.OBJ' contains invalid OMF record, type 0x4c (possibly COFF)


>We've since 2002 a lot of development of the available instruction sets
I don't doubt it and hadn't appreciated BCB's "out-of-dateness" re asm until yesterday.
Given it's from 2005...perhaps I should've have.

Thanks for the suggestions Gunther

Jibz

Like Vortex suggested, Agner's objconv is an excellent tool to get OMF files from COFF :t.
"A problem, properly stated, is a problem on it's way to being solved" -Buckminster Fuller
"Multithreading is just one damn thing after, before, or simultaneous with another" -Andrei Alexandrescu

bobl

getting warmer...
my tasm_bat.bat file to produce myasm.obj

@cls
@echo off
@echo ok tasm-ing...
cd C:\my_delphi\my_cbuilder2006\proj3
SET MY_PATH=C:\Program Files\Borland\BDS\4.0\Bin\
"%MY_PATH%\tasm32" /m2/q myasm.asm
cd \


produced the following output and an myasm.obj

ok tasm-ing...
Turbo Assembler  Version 5.3  Copyright (c) 1988, 2000 Inprise Corporation

Assembling file:   myasm.asm
Error messages:    None
Warning messages:  None
Passes:            1

[C:\]


I did a shift/F11 and "added" myasm.obj to the project
After adding it but before trying to use it...in Dave's terms...the linker seemed to "eat" it ok.
However I'm now getting this error

[Linker Error] Error: Unresolved external '_MySubroutine' referenced from C:\MY_DELPHI\MY_CBUILDER2006\PROJ3\DEBUG_BUILD\UNIT1.OBJ

after adding lines to the vcl code below to use the asm function.
Any ideas 'cos it's certainly looking more promising than it did.

#include "Unit1.h"
//#include "myasm.obj"       <<=============not sure about this
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

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

void __fastcall TForm1::Button1Click(TObject *Sender)
{
float Result = MySubroutine(1,2);
ShowMessage(FloatToStr(Result));
}



The above was posted without seeing this...
>Like Vortex suggested, Agner's objconv is an excellent tool to get OMF files from COFF
Jibz, Vortex I missed that completely. Thank you very much both for suggesting it and drawing it to my attention.
I don't like the idea of being confined to Tasm and that looks like a lifeline.

bobl

I'm just looking at objconv now but suspect I'll have the same problem as I'm having at the moment
i.e. some kind of declaration omission.

bobl

Here's the assembler program

; 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


Here's my assembling batch file

@cls
@echo off
@echo ok tasm-ing...
cd C:\my_delphi\my_cbuilder2006\proj3
SET MY_PATH=C:\Program Files\Borland\BDS\4.0\Bin\
"%MY_PATH%\tasm32" /m2/q myasm.asm
cd \



Here's the calling code in unit1.cpp

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

void __fastcall TForm1::Button1Click(TObject *Sender)
{
        float res = 4;
res = MySubroutine(1,2);
ShowMessage(FloatToStr(res));
}


Here's the linker "line" after I've added myasm.obj using shift/F11
You can see on the last-but-one line that myasm.OBJ is in there like a 'goodun'

Linker command line
  -aa -Tpe -Gn -v -L"c:\program files\borland\bds\4.0\lib\debug";C:\my_delphi\my_cbuilder2006\proj3;"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" -j -x -LC:\my_delphi\my_cbuilder2006\proj3
  -GA"C:\my_delphi\my_cbuilder2006\proj3\vfs46.tmp"="C:\my_delphi\my_cbuilder2006\proj3\Project1.res"
  -GA"C:\my_delphi\my_cbuilder2006\proj3\vfs47.tmp"="C:\my_delphi\my_cbuilder2006\proj3\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:\my_delphi\my_cbuilder2006\proj3\Debug_Build\Project1.obj C:\my_delphi\my_cbuilder2006\proj3\Debug_Build\Unit1.obj
  C:\my_delphi\my_cbuilder2006\proj3\myasm.OBJ,C:\my_delphi\my_cbuilder2006\proj3\Debug_Build\Project1.exe,C:\my_delphi\my_cbuilder2006\proj3\Debug_Build\Project1.map,import32.lib
  cp32mti.lib,, C:\my_delphi\my_cbuilder2006\proj3\vfs46.tmp


and it all compiles and runs fine as long as I comment out the line in the calling code...res = MySubroutine(1,2);
Once I comment that in I get error

[Linker Error] Error: Unresolved external '_MySubroutine' referenced from C:\MY_DELPHI\MY_CBUILDER2006\PROJ3\DEBUG_BUILD\UNIT1.OBJ


I'm missing something but don't know what.

dedndave

it seems to have "decorated" the symbol with an underscore
it's probably that way in the OBJ
there are ways to make it not decorate, or you can just call it with the decorated name
extern "C" float _MySubroutine(DWORD Arg1,DWORD Arg2);

void __fastcall TForm1::Button1Click(TObject *Sender)
{
        float res = 4;
res = _MySubroutine(1,2);
ShowMessage(FloatToStr(res));
}


i may have it backwards - lol
it isn't decorating it and it expects it to be

bobl

It was certainly worth a try...I tried it with one and two underscores but get the same error.

japheth

You probably just have to add option -mx when assembling your Myasm.asm with tasm.

jj2007

Don't know whether this is helpful - here is a minimalistic example how to call the sub from C and C++. Works with Pelles C and VC++ 2010 Express...

C++
#include <stdio.h>
#include <tchar.h>

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

int _tmain(int argc, _TCHAR* argv[])
{
   fprintf(stderr, "Res=%f\n", MySubroutine(20.0, 5.0));
   return 0;
}


Masm:
.586p
.model flat

MySubroutine PROTO C Arg1:DWORD, Arg2:DWORD

.CODE

MySubroutine PROC C Arg1:DWORD, Arg2:DWORD

       fld        Arg1
       fmul       Arg2
       ret

MySubroutine ENDP
END


Note that C++ and Masm agree that DOUBLE and REAL4 aka "float" are basically the same, as long as you use fld and fmul instead of fild and fimul :icon_mrgreen:

bobl

Japeth
-mx is spot on. It works great now! That's a real relief. Thank you very much indeed.

jj2007
Double good news...As a result of your prompt re Vortex's advice (that I'd previously missed)
I revisited the first example here 
http://masm32.com/board/index.php?topic=1273.0
i.e. that BCB2006 wouldn't eat in reply 16 and obj_conv'd it with....

@cls
@echo off
@echo ok objconv-ing...
cd C:\my_delphi\my_cbuilder2006\proj3
SET MY_PATH=C:\Documents and Settings\me\My Documents\Downloads\objconv\
"%MY_PATH%\objconv" -fomf -nu mymasm.obj myomfdmasm.obj
cd \

Now the linker does eat it.
I didn't try calling it because I wasn't sure how so your example showing how to call such procedures is just the job.
Again...thank you very much indeed.
What a great forum this is!

Vortex

Hi bobl,

Another option to convert OMF to COFF is to use MS link.exe :

\masm32\bin\link -edit objectfile.obj

objectfile.obj : warning LNK4033: converting object format from OMF to COFF

dedndave


bobl

Vortex, Dave
I'm sure there's safety in numbers re this sort of conversion so...thanks for the alternatives.
They're very much appreciated and give me more chance of being able to use Masm in it's own environment
for development which is my preference.

bobl

jj2007
I just removed the tasm.obj file, replaced it with the objconv'd assembled version of your example above and...
it worked flawlessly. Looks like were "in business". Thank for your help. It's very much appreciated.