Archived

This topic is now archived and is closed to further replies.

Crosseyed

Eww assembly is ugly...

Recommended Posts

Yes, it is very ugly indeed, but i am being forced to learn it. Though now i am begining to enjoy it(just a little). Its kinda like turning a game''s difficulty up to hard after you beat it already on medium(c++). Anyways, now that i know assembly and its supposed to good for optimisation I want to know what everybody else uses it for?? What should i be replacing in my c++ projects with inline assembly, any suggestions.

Share this post


Link to post
Share on other sites
quote:
Original post by Crosseyed
its supposed to good for optimisation

Well, yes and no. Knowing assembly is not the same as knowing how to optimize assembly. And most compilers are smart enough to do as good a job as or better than you could.

quote:
What should i be replacing in my c++ projects with inline assembly, any suggestions.

Nothing, until you profile your code. Then you can identify which functions are taking up all your time, and do stuff with those. But you will realize much more benefit from logical optimization than from code optimization.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
Don''t optimise early.

90% of your program''s execution time is spent in 10% of the code. When you''ve finished writing pretty much everything, you should profile your stuff, think how to optimise the slow code at an algorithm level first, and only as a last resort rewrite it in assembly.


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites
i find profiling fascinating.

all these functions rise to the top as i manipulate the data to exclude stuff i''m not interested in optimising at the moment. i get a feel for where the program is spending most of it''s time or how long it''s spending in specific places or how long it takes to get from a to b or how many times it calls structors (making sure they match). then i try out using a different algorithm or a standard list rather than a hand rolled one (this is legacy code i''m working on).

you can still optimise a lot in c++ before having to eventually pull out the asm. only then take a look at the code generated in areas you have evidence there is a problem. there''s a good chance you can get adequate improvements by reorganising your c++ first and then you can tweak the assembly.

Share this post


Link to post
Share on other sites
Assembly language is cleaner and simpler than C++; by nature, asm has to be very simple. C++''s power lies not in simplicity, but in organization.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
I find x86 assembly to be incredibly ugly when compared to the lovely consistency and flexibility of MIPS/SPARC assembly, particularly when you have access to (and who doesn''t) a macro processor.

There''s very rarely a need to write assembly anymore. Programmer comprehensibility is far more valuable than compiler specificity. In fact, I would only write assembly on a platform that lacks a decent C or C++ compiler, or when implementing a compiler myself.

Share this post


Link to post
Share on other sites
quote:
Original post by Useless Hacker
Personally, I find C++ to be more ugly than assembler.

[edited by - Useless Hacker on October 1, 2002 6:30:26 AM]


damn right. asm has only 3 types of instruction: math, data movement and logical jumps. it that''s too DIFFICULT for some people, i think we have a case of habit more than that either language is easier.

one thing to bear in mind: compilers push and pop all registers you use in inline code so it only makes sense to write a significant portion of a function in pure assembly. i heard microsoft deliberately sabotages inline assembly to make its own compiler look good .

to tell the truth, assembly is vastly superior to most langiages for one reason: it is EXPLICIT and UNAMBIGUOUS. people argue its dangerous becuase theres no way to tell if a number is a fraction or pointer so its easy to get confused with no typing. that isn''t being ambiguous, that''s being literal.

bad assembly is ugly. amuter optimisation is ugly. simplicity is beautiful.

********


A Problem Worthy of Attack
Proves It''s Worth by Fighting Back

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Assembly is only for people with too much time on their hand. I profile and optimize my code on the c++ level.

Share this post


Link to post
Share on other sites
Assembler may be ugly, but IMO its a lot more fun. When I still programmed for DOS a few years ago and I started learning assembly I made all kinds of stupid little programs but had a lot more fun doing so than making 'real' programs in C/C++. For some reason 'Hello World' in assembler feels like more of an acomplishment =-). When I got my TI-92+, I learned the assembly for its 68k processor and made a few small games and a library of functions to use with it and it was a LOT more fun that using the unreasonably slow ti-basic that the built-in program editor is for. Shortly after, a C compiler came out that produced calculator program files, and I tried using it but I found it to be a lot less enjoyable and not much easier. Later on I even made an assembler that understood a few basic instructions and produced DOS .com files =-) Never finished it, but it was enough to make a small program. IIRC, it supported interrupt calls, moving constants to a register, and the various jumps to labels. All the opcodes I got using debug.com. It taking so long to get the opcodes was the main reason I never finished it, it got boring fast.

I've been thinking about getting back into assembler, but I'm not very motivated and seeing all these new macros for things like calling procedures, defining prototyes etc makes me think it wouldnt be nearly as fun if I used all those, which I probably would just because I'm lazy.
"The Requested Information Is Unknown Or Classified" -Anonymous

[edited by - Extrarius on October 2, 2002 11:37:13 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by walkingcarcass
damn right. asm has only 3 types of instruction: math, data movement and logical jumps. it that''s too DIFFICULT for some people, i think we have a case of habit more than that either language is easier.

Rubbish. Intentionality and overall program comprehensiblity in assembly are low. Low comprehensiblity and intentionality reduce programmer productivity. Which is the most important quantity. Don''t make your fetish for punishment () into a rationale for sub-optimal practice...

quote:

to tell the truth, assembly is vastly superior to most langiages for one reason: it is EXPLICIT and UNAMBIGUOUS. people argue its dangerous becuase theres no way to tell if a number is a fraction or pointer so its easy to get confused with no typing. that isn''t being ambiguous, that''s being literal.

Assembly is only unambiguous to the assembler. To the programmer, there''s sometimes no telling what a snippet of code does without context. Not so with high(er)-level languages, which is exactly why we created them: to get real work done faster.

Share this post


Link to post
Share on other sites
quote:
Original post by Extrarius
Assembler may be ugly, but IMO its a lot more fun. When I still programmed for DOS a few years ago and I started learning assembly I made all kinds of stupid little programs but had a lot more fun doing so than making ''real'' programs in C/C++. For some reason ''Hello World'' in assembler feels like more of an acomplishment =-).

Dude, those weren''t "real programs" you made in C/C++. Try writing a recursive descent parser in assembly. Sure, you can, but it''s neither the best idea nor the most efficient.

I enjoy assembly (on MIPS/SPARC where you have 32 general purpose registers, more or less, and no restrictions on functionality - like which register is the "accumulator" or "counter") as much as the next guy. But I only use it (with a view to productivity) when it''s reasonable to do so. I''m voicing my opinions here because we have many impressionable people who come here to learn and absorb, and I don''t want them being indoctrinated with a felse idea that using assembly makes you a "real programmer."

Share this post


Link to post
Share on other sites
I write in assembly. Then again, that''s for a DSP. The C compiler for our chip isn''t good enough for what we need to do with it (yet).

re: when to switch to assembly for optimization..
There are three rules of optimization:
1) Don''t optimize.
2) Don''t optimize yet.
3) Don''t optimize unless a profiler specifically tells you to do so.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Assembly is only for people with too much time on their hand. I profile and optimize my code on the c++ level.




Oh, I would love to have seen you write my senior project in C++ when I was in college. There are times when assembly is your only option. My senior project was an obstacle avoidance robot run by a Motorola HC12 development board built on the frame of a RC Humvee. I had 768 bytes of space to work with. Guess how much space my assembly code took up? Yep! all 768 bytes. And yes, I know there''s a C compiler out there. We couldn''t use it because it made the code way too large. Sure, there are expansion boards for that development board. It would have given us another 4k of space to work with. The only problem is it would have taken up one of our seven 8 bit I/O ports so that wasn''t an option either. Heck, we even used the Analog to Digital converter because we needed another I/O port!

Try not to make all-knowing, generalized assumptions like that, especially when you don''t know what you''re talking about. Assembly programming is an extremely useful skill to have, even if one rarely uses it.


Looking for an honest video game publisher? Visit www.gamethoughts.com

Share this post


Link to post
Share on other sites
quote:
Original post by Crosseyed
Yes, it is very ugly indeed, but i am being forced to learn it. Though now i am begining to enjoy it(just a little). Its kinda like turning a game''s difficulty up to hard after you beat it already on medium(c++). Anyways, now that i know assembly and its supposed to good for optimisation I want to know what everybody else uses it for?? What should i be replacing in my c++ projects with inline assembly, any suggestions.


Actually, if you learn how to code it properly, you will find that the code looks good. Using assembly is an ART, don''t get me wrong, coding in any language is an art but when it comes to assembly, figuring the number of cycles that a certain function will use( in optimization ) is key( and that is the art behind assembly ).




[Cyberdrek | the last true sorcerer | Spirit Mage - mutedfaith.com]

Share this post


Link to post
Share on other sites
quote:
Original post by Cyberdrek
Actually, if you learn how to code it properly, you will find that the code looks good. Using assembly is an ART, don''t get me wrong, coding in any language is an art but when it comes to assembly, figuring the number of cycles that a certain function will use( in optimization ) is key( and that is the art behind assembly ).



Yeah, because modern processors don''t use OOE and so are completely predictable.

Uh huh.

Share this post


Link to post
Share on other sites
quote:
Original post by DrPizza

Yeah, because modern processors don't use OOE and so are completely predictable.

Uh huh.



Well, many assemblers come with documentation listing the # of processor cycles each opcode uses in all the different cases it can be used (like "mov mem, reg" uses a different # of cycles than "mov reg, reg") and I think that's what he was talking about

[edited by - Ronin Magus on October 2, 2002 11:09:48 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Ronin Magus
Well, many assemblers come with documentation listing the # of processor cycles each opcode uses in all the different cases it can be used (like "mov mem, reg" uses a different # of cycles than "mov reg, reg") and I think that''s what he was talking about



Yeah, because modern processors don''t use OOE and so are completely predictable.

Share this post


Link to post
Share on other sites
theres a time for everything, and everything will have it''s time. sometimes you simply have to grit your teeth and be a better code generator than your compiler. this skill hase been getting less important with the ridiculous processing power weve got used to. todays commercial apps (including games) have inefficiencies that would have been heresy little more than a decade ago.

but our chips are reaching a plateau. we can only make the track so much thinner until it becomes impractical to solve the sensitive environment problems in running a curcuit relying on a conductive strip only a few atoms across. i predict no-holds-barred optimal programming will make a comeback in the next few years and that means assembly, people.

repent for the end is at hand.

bottom lines are: its a vital skill to have; and code in any language is only ugly if badly written

PS someone at the end of the last page was blathering on about context-free code snippets being hard to follow. how much context does PrintError() or BuildViewMatrix() need to have?

********


A Problem Worthy of Attack
Proves It''s Worth by Fighting Back

Share this post


Link to post
Share on other sites
quote:
Original post by DrPizza
[quote]its a vital skill to have

No it isn''t.


well, yes it is:D

you like watching divx, listening to mp3 and/or playing quake3 at the same time? if you encode mp3 on my pc with simple c/c++ code, then it eats up that much of the cpu, you can forget playing q3 at the same time. if it is sweet sse optimized, it takes 5% of the cpu.. doesn''t care about those..
divx is nearly not playable anymore on my pc (p3 500mhz), but i couldn''t even see mpeg movies smooth without sse.

every language is only as good as it can implement the byte-code in the end. and only asm can expose it by 100%.

and as i am for realtime raytracing, i have to sse everywhere:D

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites