Learn some assembly

A place for Ogre users to discuss non-Ogre subjects with friends from the community.
jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Re: Learn some assembly

Post by jjp »

jacmoe wrote:
nikki wrote:Some times you can also inline some assembly into your C++ for quick hax. :roll:
I trust my optimising compiler more than I trust hand-written inline assembly. :wink:
Though there are cases where even modern compilers don't "get" how to produce the most efficient code. But apart from the fact that this rarely matters at all I guess most of the time it is wiser then to modify the C/C++ code to make optimization easier for the compiler, instead of coding in assembly.
Enough is never enough.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 538

Re: Learn some assembly

Post by Kojack »

Assembly can do things c++ can't. Try calling an interrupt or reading the cpu clock counter without using assembly at some point.

Compilers are better than humans at generating assembly 99% of the time, but there are still cases where you can take advantage of assembly. Especially with special cpu features like SSE, 3dNow, or non x86 platforms like ARM. When compiling for an OMAP3530, will gcc optimise your code to use the Cortex A8 core combined with the NEON simd coprocessor and TMS320C64x+ dsp core to achieve the best floating point maths performance? Nope, you'll have to do it by hand.


Take at look at the following Ogre files: asm_math.h, OgreOptimisedUtil.cpp, OgrePlatformInformation.cpp, OgreSIMDHelper.h
They all contain inline assembly. I'm sure it's not there just for fun.

Oh man, C64, Amiga & Co, I just this week talked with a friend about how much it sucked the Amiga universe stopped thanks to Commodores brilliant mis-management back then and from that point on everyone was stuck in the 10 years behind in time Microsoft universe with 16 lousy colours and no multitasking at all
Thanks to them choosing Cambridge University's Tripos as the basis for the Amiga operating system, Amigas were fully preemptive multitasking and multithreaded 6 years before linux, 10 years before microsoft and 14 years before apple. :)
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36
Contact:

Re: Learn some assembly

Post by Nauk »

nikki wrote:You gotta just be clever then. ;)

Anyway, I was stressing more on the learning and fun aspects.
Assembly coding makes you feel like a real man :) beats growing a beard by far and to make another silly statement I think the claim that compilers make the better assembly code is a conspirative mass-excuse to have a legit reason to avoid learning and having to work with it. Back to serious, compilers will probably write the better assembly compared to a starter, but you can look and learn their weak-points and try to improve them and I have read several articles now where semi-experienced assembly coders, lets say 2 years + coding experience claim that their code runs myriads faster than optimized C++ and I don't think they are making it up just to get attention or because it is fun lieing.

Another one for the fun aspect, are their any good assembly IDEs? I have been looking at a couple and they either been upsetting my antivirus software or were at a very incomplete stage.

/Offtopic-rant:
Kojack wrote:
Oh man, C64, Amiga & Co, I just this week talked with a friend about how much it sucked the Amiga universe stopped thanks to Commodores brilliant mis-management back then and from that point on everyone was stuck in the 10 years behind in time Microsoft universe with 16 lousy colours and no multitasking at all
Thanks to them choosing Cambridge University's Tripos as the basis for the Amiga operating system, Amigas were fully preemptive multitasking and multithreaded 6 years before linux, 10 years before microsoft and 14 years before apple. :)
Remember the Amiga API and the 4 big reference manuals? I did quite a lot C coding back then (around 1986), and it was pleasant and easy to work with it the functionality seemed logical, reasonable and foremost inspiring. When I looked 10 years later first time at Microsofts WinAPI the first thought was "Are you kidding me, well now I at least know why there is so much rubbish and bad quality out there" - WinAPI is as inspiring as doing a tax-declaration. Still puzzles me how they ever got to become the dominating power - well not really, it's a lot about backyard marketing and the never to underestimate brilliance of the human flock, or like an old joke says "Eat shit - millions of flies can't be wrong" - without that Hitler, Bush and Windows would have never happened.
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: Learn some assembly

Post by nikki »

Nauk wrote:Another one for the fun aspect, are their any good assembly IDEs? I have been looking at a couple and they either been upsetting my antivirus software or were at a very incomplete stage.
I'm just using gvim, bash, fasm/nasm and ld (under Linux), and it's fine. ;)
jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Re: Learn some assembly

Post by jjp »

Nauk wrote:I have read several articles now where semi-experienced assembly coders, lets say 2 years + coding experience claim that their code runs myriads faster than optimized C++ and I don't think they are making it up just to get attention or because it is fun lieing.
I doubt that "myriads faster" is not a strong exaggeration most of the time. And: with the time spent on doing micro-optimizations in assembly they probably could have thought of algorithmic improvements at a higher level.. with more gains but without the drawbacks caused by doing stuff in assembly. If I know my algorithm operates at the lower bound of what can be achieved in terms of complexity, no optimizations at a higher level seem possible any more, I need the speed and the algorithm performs worse than it could/should - then I would take a look at assembly. Otherwise I consider it a waste of time (talking about the context of using assembly for performance reasons).
Enough is never enough.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 538

Re: Learn some assembly

Post by Kojack »

Remember the Amiga API and the 4 big reference manuals?
Here's volume 1 from my Shelf Of Mystery.
Image
All the books were useful, but the first volume covered most of the stuff you need. (My friend over the road had the others, I just had the first book)
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: Learn some assembly

Post by nikki »

Kojack wrote:
Remember the Amiga API and the 4 big reference manuals?
Here's volume 1 from my Shelf Of Mystery.
Image
All the books were useful, but the first volume covered most of the stuff you need. (My friend over the road had the others, I just had the first book)
The lighting in that image doesn't seem right. :?
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36
Contact:

Re: Learn some assembly

Post by Nauk »

Kojack wrote:
Remember the Amiga API and the 4 big reference manuals?
Here's volume 1 from my Shelf Of Mystery.
Image
All the books were useful, but the first volume covered most of the stuff you need. (My friend over the road had the others, I just had the first book)
I wish I would have kept all the old stuff /envy :D - I still have an old roll of thermo paper with the c-source of my text-editor printed out, that's all that is left.
nikki wrote:
Nauk wrote:Another one for the fun aspect, are their any good assembly IDEs? I have been looking at a couple and they either been upsetting my antivirus software or were at a very incomplete stage.
I'm just using gvim, bash, fasm/nasm and ld (under Linux), and it's fine. ;)
I was hoping for a little more comfort, anyway here is a site I bookmarked that I found helpful to get into it, also has some further reference links:
http://www.drpaulcarter.com/pcasm/index.php
and here another one to a pretty useful cheat-sheet translated into several languages:
http://www.jegerlehner.ch/intel/
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36
Contact:

Re: Learn some assembly

Post by Nauk »

doubt that "myriads faster" is not a strong exaggeration most of the time.
I was using that wording to underline a point, but yes it was clearly exaggerated :) - I have no actual comparisons but still what makes me wonder is, that it is usually people that take the time to work themselves up to a proficient level start claiming that, I mean there must be a grain of truth behind it? What would be interesting to see is some real hard fact benchmarks on the subject, like this and that algorithm in hand-optimized assembly vs optimized C, C++, D, etc.
jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Re: Learn some assembly

Post by jjp »

Nauk wrote:what makes me wonder is, that it is usually people that take the time to work themselves up to a proficient level start claiming that, I mean there must be a grain of truth behind it?
I'd say they have to find some sort of justification for themselves putting a lot of time into learning assembly ;)
Enough is never enough.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Learn some assembly

Post by jacmoe »

/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36
Contact:

Re: Learn some assembly

Post by Nauk »

jjp wrote:
Nauk wrote:what makes me wonder is, that it is usually people that take the time to work themselves up to a proficient level start claiming that, I mean there must be a grain of truth behind it?
I'd say they have to find some sort of justification for themselves putting a lot of time into learning assembly ;)
Haha, or that :) - Ok lets roll it up from the other end: Looking at the last 2 decades, I sometimes have the impression which of course might be a very subjective one and wrong, but some things still take as long as they did years ago, apps should have a lightning fast response time by now, still there are many cases normal desktop apps lag, feel slow, or look at compile times: I still can have a cup of coffee for a full recompile. Sure many things are faster and machines are much more powerful, especially graphics hardware, still I don't get rid of the impression APIs get more and more bloated, slow, resources being wasted and the actual speed of software didn't rise in direct proportion to the increase of hardware power we had during that time. So if compilers are really producing that good code even taking into account a setback for "bad" c++ code, then that should not be the case, or is that argument flawed?
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Learn some assembly

Post by jacmoe »

If you dig assembly, why not use an OS written in assembly? :)
MenuetOS
Eh, Hardcore-Nikki?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Learn some assembly

Post by jacmoe »

Yes, I found it! :)
Easy Code Cat
The joy of assembly programming and RAD, all at the same time. :wink:

Good ASM page:
http://www.jorgon.freeserve.co.uk/
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36
Contact:

Re: Learn some assembly

Post by Nauk »

Those are some seriously cool links & finds Jacmoe, you sure are an overabundance when it comes to digging out usefullness from all different corners of the net. :)
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 538

Re: Learn some assembly

Post by Kojack »

The lighting in that image doesn't seem right.
It's a book sitting on my black recliner lounge chair, almost at midnight, in a badly lit room with a fluorescent light directly overhead, photographed with a telephoto zoom lens and flash on my canon dslr. :)
I don't like using the flash, but I didn't think it was worth getting the tripod out to photo a book which is off topic. :)
Without the flash the exposure time was about 2 seconds, even with image stabilising I can't hold it that steady.

Anyway...
:)
I sometimes have the impression which of course might be a very subjective one and wrong, but some things still take as long as they did years ago, apps should have a lightning fast response time by now, still there are many cases normal desktop apps lag, feel slow
You're not the only one. :)

I believe that with each version software should be made to work faster and better on the same hardware. In version 2 of something you find the bottlenecks, have had time to research new algorithms, learnt new optimising tricks, etc. Like how games on a console years after release are much more technically advanced than when the console is brand new, because the coders learn to take advantage of what they have better. But Windows doesn't go like that. Instead of optimising what's there, they just add more on top, requiring better hardware to keep the old stuff going.
Assembly won't help, it's the operating system that causes most of it. Although maybe windows should be written in assembly... :)
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: Learn some assembly

Post by nikki »

jacmoe wrote:If you dig assembly, why not use an OS written in assembly? :)
MenuetOS
Eh, Hardcore-Nikki?
O rly? I'd already seen that a month back. You're late. :roll:

Nauk, I read the 'PC Assembly' Paul Carter book. Was pretty good.
jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Re: Learn some assembly

Post by jjp »

Kojack wrote:Assembly won't help, it's the operating system that causes most of it.
Are you being serious? Of course there is a lot of room for better operating systems but it is not the case that operating systems would slow down applications in a significant way.
Kojack wrote:Although maybe windows should be written in assembly... :)
Here I really hope you are not being serious ;)
Nauk wrote:Haha, or that :) - Ok lets roll it up from the other end: Looking at the last 2 decades, I sometimes have the impression which of course might be a very subjective one and wrong, but some things still take as long as they did years ago, apps should have a lightning fast response time by now, still there are many cases normal desktop apps lag, feel slow, or look at compile times: I still can have a cup of coffee for a full recompile.
Hard disks haven't gotten much faster. That is one major point where bad responsiveness originates from. C++ compile times are high because C++ compilers are that good at optimizing. Take a C++ compiler from 10 years ago and it will run super fast in comparison. But the code produced will be a lot worse. And C++ isn't exactly a language designed for fast compilation times. Work with C# (for example) and you won't be having any forced breaks due to recompilation ;)

Also, you're not really getting the whole picture here. If you'd compare equally complex software from today and from 10 years ago you might as well note some differences in terms of reliability and security, for example.
Enough is never enough.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 538

Re: Learn some assembly

Post by Kojack »

Forget assembly operating systems, here's a really freaky one: Medos 2 on the Lilith.
Back around 1981 Niklaus Wirth (creator of Algol W, Pascal, Modula, Modula 2, Oberon, Oberon2, Component Pascal, and other things which haunt my nightmares) built a computer called the Lilith. Hmm, everybody made computers named after women back then: the Lilith, the Apple Lisa (named after Steve Jobs' daughter), even the Amiga was first called the Lorraine, but was changed to Amiga which is the spanish word for girlfriend (but it kept female names inside, the custom chips were called Agnes, Denise and Paula) and came alphabetically before Apple and Atari. :)
Anyway, the Lilith was a computer designed to run the new Wirth language Modula 2. The operating system was called Medos 2, and was written in Modula 2 (it had a windowed gui and mouse control, years before Apple released the Lisa or Mac). The cpu was even freakier, the cpu didn't use assembly, it directly ran M-Code, the vm style byte code generated by the Modula 2 compiler. It was also 4 bit and had no registers, it used a 16 word stack instead. It ran at 7MHz.

Now that's an odd computer.

It's also my idea of hell, since at university I was forced to sit through a year of Modula 2 coding, even though I already had a computer engineering associate diploma from a different college and 14 years coding experience. Argh! But the department head was on the Modula 2 international committee, so he forced most subjects to be Modula 2 related, despite being used nowhere in the real world. :(

No! The memories are coming back! Please make them stop!!!!!!!!!!!!!
*loud thud*
.....................
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Re: Learn some assembly

Post by nullsquared »

Nauk wrote: I have read several articles now where semi-experienced assembly coders, lets say 2 years + coding experience claim that their code runs myriads faster than optimized C++ and I don't think they are making it up just to get attention or because it is fun lieing.
My problem is that I'm not seeing any profiled results. If I see something like "C++ version takes 0.0312 milliseconds on average but the assembly version takes 0.0131 milliseconds on average", then that's cool.

But in other cases, people write assembly and tell you it's faster, even though they haven't written an equivalent C/C++ version and profiled it.
User avatar
Karan
Halfling
Posts: 62
Joined: Wed Sep 17, 2008 1:59 pm
Location: Berlin, Germany

Re: Learn some assembly

Post by Karan »

Kojack wrote: Although maybe windows should be written in assembly... :)
About 10% of Windows are written in assembly if I remember that correctly from my operating systems course. Mostly the low-level stuff (HAL etc.)
And VMS was even completely written in assembler.
jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Re: Learn some assembly

Post by jjp »

Kojack wrote:Back around 1981 Niklaus Wirth (creator of Algol W, Pascal, Modula, Modula 2, Oberon, Oberon2, Component Pascal, and other things which haunt my nightmares) built a computer called the Lilith.
Now I am glad that I didn't have the "pleasure" to use any of these - but Algol wasn't all that bad, was it? :)
Enough is never enough.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Learn some assembly

Post by jacmoe »

My first bigger programming project was in Pascal. Not bad. :)
I later became an Object Pascal (Delphi) addict.. I even threw in some assembly, because it was fairly easy to mix assembly and pascal. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: Learn some assembly

Post by syedhs »

Hmm isn't the prime reason C++ compilation is slow even on fast pc because of template? Try compile a plain .C file - it is stupid blindingly fast! :o
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
reptor
Ogre Magi
Posts: 1120
Joined: Wed Nov 15, 2006 7:41 pm
Location: Finland
x 5

Re: Learn some assembly

Post by reptor »

It sounds a bit like some people aren't considering that there are devices for which you need to code in assembly. You can't choose between C/C++ and assembly, the choice is made for you by the hardware designer.

Other programming languages just are not possible to use then.

Assembly programming is very much a very useful skill, you just need to be doing the right job to benefit from it.

When you shoot the assembly programming down as an unnecessary thing, consider that while it may be completely useless to you, that doesn't mean it is useless for everyone.
Post Reply