Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 31st, 2007, 3:06 PM   #1
hareshkainth
Newbie
 
Join Date: May 2007
Posts: 2
Rep Power: 0 hareshkainth is on a distinguished road
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.
hareshkainth is offline   Reply With Quote
Old May 31st, 2007, 3:12 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 31st, 2007, 6:28 PM   #3
hareshkainth
Newbie
 
Join Date: May 2007
Posts: 2
Rep Power: 0 hareshkainth is on a distinguished road
i will try to find some basic assembly material first before i attempt any sort of optimising.

thanks DaWei.
hareshkainth is offline   Reply With Quote
Old May 31st, 2007, 7:22 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 31st, 2007, 8:48 PM   #5
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 929
Rep Power: 4 lectricpharaoh will become famous soon enough
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.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp
lectricpharaoh is offline   Reply With Quote
Old Jun 9th, 2007, 9:53 AM   #6
Satans_Banjo
Newbie
 
Join Date: Oct 2006
Posts: 15
Rep Power: 0 Satans_Banjo is on a distinguished road
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
Satans_Banjo is offline   Reply With Quote
Old Jun 9th, 2007, 10:20 AM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 15th, 2007, 12:23 AM   #8
physicist
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 146
Rep Power: 2 physicist is on a distinguished road
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.
physicist is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
EXECryptor software protection Jean5 C++ 35 Oct 10th, 2006 7:10 PM
assembly boot code shadyi Assembly 13 Jun 19th, 2006 9:24 AM
do you prefer high level or low level? ShadowAssasin Coder's Corner Lounge 3 Jun 13th, 2006 12:45 PM
High Level Assembly? Gink Assembly 3 Apr 20th, 2005 11:34 AM
Smashing a stack in MIPS assembly code tsgrimey Assembly 2 Feb 27th, 2005 1:06 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:35 PM.

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