News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

C++ in ASM

Started by AeroASM, May 20, 2005, 07:43:15 AM

Previous topic - Next topic

AeroASM

When I needed to write C code, I learnt ASM instead, because it is more interesting and you can still do everything you need to.

Now, I will soon have a project that requires me to write C++. However, I do not want to learn it and do not have an IDE or compiler.

Writing C code in ASM is possible. How can I write C++ code in ASM?

EDIT: I don't mean inline. I mean, make a module in ASM with objects and methods etc that are compatible with other modules written in C++

hutch--

I can't see that one happening in a hurry, the sheer compexity of the overhead will knock you over. If you have a strong enough stomach, suspend the sensible stuff you have learnt and see if you can master enough of this puke to get the app up and running. You can then cheat and write the guts of it in C or perhaps in MASM modules if you cannot stomach much more of it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jibz

Puke? Guts? My, my, such language! :green.

You can have some luck writing modules in asm if you target only a single compiler and know exactly what rules it uses for stuff like the 'this' pointer and name decoration. It might be a better choice to write the asm modules as C callable, and then use them from a C++ wrapper though.

Either way you will not get the benefits of stuff like templates this way of course :U.

Vortex

Hi Aero,

Which C++ compiler are you going to use?

AeroASM

I would prefer not to use any C++ compiler at all, and just write C++ compatible code in ASM, but as hutch said the overhead will probably kill me.

hutch--

I did not connect the idea properly, (sick in the stomach at the prospect  :bg )  but the idea is basically that C++ as against C is a lot more complicated under the hood so you are better off to learn its basics than try and emulate it in asm. Look at it on the bright side, it should get your REAL C up to scratch in a hurry.   :toothy
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

QvasiModo

Hi Aero,

there is a paper by Agner Fog regarding calling conventions on different compilers, you'll find it useful. And don't worry too much about the "complexity", it ain't so bad really... :wink

AeroASM

You mean that object modules are specific to each compiler? Scrap this. What is the best free compiler around? I know two compilers: the VC++ toolkit one and GCC.

Tedd

It depends how "C++"-ified you want to be :bdg If you just want to use objects with simple inheritence and virtual functions then it's not so difficult.
Compatibility between compilers is next to none :P

If you have to write in C++, I presume it will be so that someone can later access/read/understand/modify the code. Which means you will probably have to do actual (urgh, dirty dirty!!) C++.
There are numerous C++ compilers, many of which are 'free' - it's just a case of whichever suits you best. Searchy :wink
No snowflake in an avalanche feels responsible.

Vortex

Hi Aero,

Talking about C++ compilers, have a look also at the free Digital Mars C/C++ compiler package.

QvasiModo

You could instead write a C compatible library. Then do some wrapper classes for C++ using inlined methods. That would work for all C++ compilers.

AeroASM

[uote author=QvasiModo link=topic=1693.msg13133#msg13133 date=1116618085]
You could instead write a C compatible library. Then do some wrapper classes for C++ using inlined methods. That would work for all C++ compilers.
Quote
Argh! Total jargon!

I have decided that I may as well learn C and then C++, if I want to be respected as a decent programmer. My learning experience with programming as been quite good I think: starting with VB to learn the basics of programming, then jumping into ASM to learn how the computer works, and now when I learn C I can apply both low level optimisation techniques and high level programming style.

So, back to my question, which free C/C++ compiler is the best? Also, if I use a C++ compiler to compile C code, will it be more bloated than if I used an ordinary C compiler?

Vortex

Hi Aero,

Good C++ compilers : MS VC++ Toolkit 2003 and Digital Mars. ( Probably also GCC which I never tried )
C compilers             : PellesC and the other same C/C++ compilers.

Homer

Check out ATC and ObjAsm32 oopasm implementations, both are C++ compatible sets of masm macros :)
Bah @ you guys :)

QvasiModo

Quote from: AeroASM on May 20, 2005, 07:56:04 PM
[uote author=QvasiModo link=topic=1693.msg13133#msg13133 date=1116618085]
You could instead write a C compatible library. Then do some wrapper classes for C++ using inlined methods. That would work for all C++ compilers.
Quote
Argh! Total jargon!
Sorry, I'll elaborate a bit here... this was my suggestion:

Write an ordinary .lib or .dll library in ASM, or you always had. This library will be compatible with C as MASM uses the same calling conventions.

Then write a C++ class that does nothing but call the ASM functions. The "methods" (functions) for that class should be "inlined" (a C++ mechanism that works in a similar way as a MASM macro). This gives the C++ look and feel to your ASM library, but adds no overhead.

In any case you'll find it convenient to learn the basics of C and C++ to write a good library for those languages... even if you implement it in assembly, one day you'll have to write the .h files! :wink

Good luck in your project! :U