flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > When to and when not to intermix C/C++ and ASM done in FASM?

Author
Thread Post new topic Reply to topic
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist
When is it more appropriate to intermix ASM and C/C++? I write for size and for speed but in today's C/C++ world it optimizes pretty darn well (way better than it did 25 years ago when C had yet to be standardized and ANSI C was all the rage) and that makes me question when to use ASM over the built in GCC/Mingw/MSVC compiled ways.

What are your thoughts on this matter?
Post 13 Oct 2010, 15:29
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17492
Location: In your JS exploiting you and your system
revolution
My thoughts are:

Use ASM for everything. Not for optimisation, but for sanity. The optimisation part is just a free bonus.

Well you did ask for my thoughts. Probably not helpful to you though, hehe Twisted Evil
Post 13 Oct 2010, 15:52
View user's profile Send private message Visit poster's website Reply with quote
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist
Not what I was looking for, and while I do agree on principle alone lets not forget how easy it is to do something in C++ over doing the same thing in ASM (especially in a team environment).

Also, I doubt Windows was done in 100% ASM so calling one of their routines is basically intermixing as it is.

Now, having been a 6502/6510/68k ASM programmer for 8 years I can attest to the sanity as OOP befuddles me greatly (I still, to this day, have a hard time with pointers etc... because * or -> or *(*x) is meaningless to me in ASM when I can just (xxxx) or XXXX (in X86 the parens are brackets but the same meaning)).

So, my question remains.
Post 13 Oct 2010, 19:39
View user's profile Send private message Send e-mail Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
When to use assembly? Depends. Non-exhaustive list of possible reasons:

1) when you have to: OS bootstraps, or targeting really low-end embedded devices, or utilizing very machine-specific instructions (like hardware virtualization support).

2) if there's a reason to: the bulk of your code might be in a HLL, but you have a really speed-sensitive part (verified through profiling) that seems like a good candidate for an assembly version.

3) if you feel like it: the hobbyist reason. If you really like assembly, don't care whether it's possible to Get The Job Done Faster(TM), and have nobody dictating the rules - go for it.

Keep in mind that you don't have to resort to assembly to utilize instruction sets like MMX or SSE, as the major C/C++ compilers support intrinsic functions for these. I personally prefer assembly (using fasm, yasm or nasm is actually more portable than C++ intrinsics, as those aren't standardized between compilers), but intrinsics can be useful while prototyping as you don't have to worry about register allocation.

DarkAlchemist wrote:

Now, having been a 6502/6510/68k ASM programmer for 8 years I can attest to the sanity as OOP befuddles me greatly (I still, to this day, have a hard time with pointers etc... because * or -> or *(*x) is meaningless to me in ASM when I can just (xxxx) or XXXX (in X86 the parens are brackets but the same meaning)).
Dereferencing is dereferencing, regardless of which token(s) you use to represent it. Perhaps what you really have trouble with is strong typing? Smile
Post 14 Oct 2010, 02:35
View user's profile Send private message Visit poster's website Reply with quote
lemask



Joined: 04 Oct 2010
Posts: 19
lemask
@revolution: So you use assembly really for everything? Also for some quickie-jobs (i.e. renaming a bunch of files) which could be done faster with a simple script?
Post 14 Oct 2010, 06:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17492
Location: In your JS exploiting you and your system
revolution
lemask wrote:
@revolution: So you use assembly really for everything?
Yes.
lemask wrote:
Also for some quickie-jobs (i.e. renaming a bunch of files) which could be done faster with a simple script?
Yes. I have a small proggy that can bulk rename using command line wildcards (and generally do smart stuff with filenames). But that is not really programming when renaming stuff, that is just convenience.

I don't buy the talk about HLLs being easier to program with. Assembly is just as easy, but perhaps just not as familiar with some people. I'm not saying HLLs should never be used, just that I never need to use them. There are times where portability is desired. As the CPU markets settle and mature we have kind of come to two main CPU architectures, ARM and x86. Now that ARM CPUs are starting to become as powerful as the x86 counterparts, things like Linux benefit greatly from being written in HLL. But since I don't write general purpose OSes then I am not interested in that situation and I don't need portability in that way.


Last edited by revolution on 14 Oct 2010, 15:23; edited 1 time in total
Post 14 Oct 2010, 06:50
View user's profile Send private message Visit poster's website Reply with quote
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist
I am not sure strong typing is my problem, per se', but I sure love the flexibility I had doing ASM. I despised C before it became certified and settled on C++ but I feel like I am in a box because I feel more comfortable getting at my data without a huge mangled piece of code. I always griped that I should be able to specify XYZ address and do with it as I please when I please, as I did in ASM, so you might be right but my head is just never going to accept *(*int xyx)->blah type of nonsense. I suppose my downfall was running on systems where code always loaded into the same chunk of memory always so I didn't need (back then there were no macros or other stuff for ASM (those throw me and look like the bastard child of an HLL and ASM)) to find that type of stuff they do in C/C++ land. I tried writing in C/C++ like I did in ASM and it puked. So, all I could do is clinch my fists and shout loudly.

To this day I write logic and it works fine but let it manipulate addresses and I have to run to Google to see how to do it and spend way too much time, each time, trying to get it right.

Anyway, and I know this is a foreign concept with today's programmers but I count cycles (harder to do with multicore though) and I count bytes. So, when I whip out the debugger and see all of that horrible prologue and epilogue for each function I honestly think a subtle tick in my face starts to happen and I get a little sick, lol.
Post 14 Oct 2010, 07:47
View user's profile Send private message Send e-mail Reply with quote
lemask



Joined: 04 Oct 2010
Posts: 19
lemask
It too was and still is my ideal to write everything in assembly. But i often fall back to scripting, because that is where i come from.
Post 14 Oct 2010, 08:02
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
DarkAlchemist: if you constantly need to manipulate addresses leading to horrible typecasts, then either you're working against the language rather than with it - if you want to use a language effectively, you have to follow it's idioms. Of course it could be that for whatever you're doing, C++ simply isn't the right language - right tool for the job, and all that.

Personally I don't see how "person->slaveHandler->firstName", which is normal style pointer dereferencing is horrible - and it's shorter than all the temporary loads you need in assembly code. I also find it reads pretty OK - "->" being "points to" Smile
Post 14 Oct 2010, 12:08
View user's profile Send private message Visit poster's website Reply with quote
DarkAlchemist



Joined: 08 Oct 2010
Posts: 108
DarkAlchemist
* or -> is simple enough and I can live with that but every other way to get at what it is you need is foreign to me and not something my mind accepts (even after a decade of programming in C/C++).

Lets take this for example
Code:
((CLASS*)this->GetParent())->ARRAY[byteinarray];    
For me that is just darn ugly and working against the language, or not, in ASM (I have seen the ASM via a debugger) it is so much simpler and better looking to me.

Anyway, this is not about a hate or a love of any language, nor do I wish for this thread to devolve into it, but I only mentioned that for me I much prefer ASM over C/C++ only I can get something done quicker in C/C++ AND others can take the code then run with it easier in a team environment.
Post 14 Oct 2010, 15:13
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.