![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2007
Posts: 2
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: May 2007
Posts: 2
Rep Power: 0
![]() |
i will try to find some basic assembly material first before i attempt any sort of optimising.
thanks DaWei. |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 929
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Oct 2006
Posts: 15
Rep Power: 0
![]() |
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
|
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Oct 2006
Posts: 146
Rep Power: 2
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |