Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   how does assembly code optimise high level code? (http://www.programmingforums.org/showthread.php?t=13260)

hareshkainth May 31st, 2007 4:06 PM

how does assembly code optimise high level code?
 
hi all, first time posting.

i program in c++, vb, java, cocoa (objective -c) < mac only.

ive seen some assembly code and im trying my best to learn some parts (dont get me wrong, i would love to learn it properly, but not sure what books to get or resources i need i.e. software etc).

im interested in this subject, for example, in c, i have a simple loop

for(i=0; i<10; i++)
{
// do something
}

in assembly code, what should i be looking for, in order to optimise such code.

the reason im interested in assembly, is that i would like to become a good all-round software developer, i love high level languages but i feel if i can have some understanding of low level stuff, it would greatly help me to write better code (in high level languages).

i hope ive made this post clear, if i havn't i appologies in advance.

thanks for reading, looking forward to your response. harry.

DaWei May 31st, 2007 4:12 PM

Your compiler will do a better job of optimizing that loop than you will (certainly at this point of your learning). Preoptimization is time wasted. Uninformed optimization (particularly in these days of cache and multiple cores) is time wasted. For that, you need a good profiler. When you optimize, you need to know what NEEDS optimized (where the true bottlenecks are), and how the construction of your cpu affects things.

You're way too early. Learn assembly language inside and out, first. When you can write it when you're wasted and read it in your sleep, you'll have a much greater chance of success.

hareshkainth May 31st, 2007 7:28 PM

i will try to find some basic assembly material first before i attempt any sort of optimising.

thanks DaWei.

DaWei May 31st, 2007 8:22 PM

It's sort of like this: you don't set out to highly tune a race car engine before you've learned to change the oil, or alternator, or something.

lectricpharaoh May 31st, 2007 9:48 PM

Learning assembly can give you an idea of how things work at the machine level, which may help you understand why certain practices are better than others. That said, don't try optimizing your code by rewriting it in assembly unless a) you are an excellent assembly-language programmer, b) you don't mind tying it to a specific architecture, and/or c) your compiler is too brain-dead to perform advanced optimizations (this is not true of mainstream C/C++ compilers these days, which optimize the fuck out of your code if you give them the chance).

If you're thinking of writing an entire program in asm, it's probably a waste of time unless a) it's strictly a learning exercise, or b) you have hard constraints on the size of your program.

Having said all that, I'd like to refer you to this excellent article on code optimization. Read it, bookmark it, and read it again. Some of the more technical stuff is a tad dated, but the principles are as true today as they were when it was written.

Satans_Banjo Jun 9th, 2007 10:53 AM

Assembly is only really ever used for drivers and certain parts of operating systems nowadays. Your average C compiler could produce machine code just as well as a competent assembly language programmer

DaWei Jun 9th, 2007 11:20 AM

Assembly language is also used in a lot of embedded systems, although resources available these days allow more high-level programming (such as C) than previously. Of course, non-desktop/laptop systems only amount to 90% of the market.

physicist Jun 15th, 2007 1:23 AM

I was considering learning ASM as well; i said screw it because C++ compilers are so good these days and very fast CPU's are dirt cheap, i mean dirt cheap LOL. so idk, imo there is little to gain. but i am uninformed about ASM and probably wrong.


All times are GMT -5. The time now is 2:31 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC