1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

hardware is still coded with machine/assembly language for efficiency, speed, etc.

Discussion in 'General Electronics Chat' started by PG1995, Mar 25, 2012.

Thread Status:
Not open for further replies.
  1. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    C++ is a badly designed (small) extension to C. C also has many design flaws mainly because the language was designed by compiler writers (very experiensed asm coders).
    Every good C programmer knows roughly what their compiler produces when they write a line of C-code and they know how to avoid major performance issues.

    That kind of thing is not learned because of using asm or any other language.. You learn that by knowing your processor, and C language does not hide any hardware.
    I always divide by eight like this:
    adc_value >>= 3;

    If I need to write 0xFF to memory location 0x45, I can say;
    *((char*)0x45) = 0xFF;

    Ugly, yes, but very common thing with microcontroller. I rarely see C programmers that know how to address direct memory locations, or know what the above code does.

    And with C i can write something like this and get more efficient code than most asm coders do:

    int sum = 0;
    for(i=0;i++;i<100)
    {
    sum += value_table;
    }

    If I have enought memory (as I usually do with modern microcontrollers), I can tell my compiler to unroll the loop.. who asm compiler bothers to do that kind of optimization (by hand)?
     
    Last edited: Mar 28, 2012
  2. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    Hi MrT,

    It's just that Asm makes you more aware of what you are doing at a lower level.
    It's very hard to know what kind of code a C compiler is going to produce. You can look at the source code for some compilers but i dont know too many people who want to take the time to do that. I know experience programmers who rely on disassembly to see what the code has produced. But it's also a matter of habit. Using a ten ohm resistor and doing a division might be the first thought by habit without thinking about the lower level way of doing it. It's not that it cant be done. Heck, with many compilers you can declare an Asm section of code and using the rules for that compiler pass arguments to and from that code.
     
  3. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,681
    Likes:
    13
    Thank you very much, everyone. I have been reading every post

    Regards
    PG
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US

    PG1995, although I have nothing to add to anyone that has posted previously, I think I can suggest a line of investigation that would drastically help point out what can be done when software is truly optimized, just look up the DemoScene.

    Search YouTube for Demoscene, although you'll find some bad videos you will run across some absolutely incredible demos that have won at competition in the past, and if you look harder you can actually download many of the demo's that will truly blow your mind when run native.

    Take a look at the code space restrictions and winners of some recent competitions, it will blow your mind as to what can be done given limited code space. Mind you it takes a lot of time and some real genius to do this much with this little.

    I've attached a zip file of the 4th place finisher from last year, it runs on a windows based machine not sure the requirements other than that it's the first demo I was able to get a coded form for. The realitime piece is astonishing compared to the video, but your PC better be well cleaned and the heatsink past on your video card and CPU redone within the last two years, any demo of this type would be able to substitute as a burn in test.
     
    Last edited: Mar 29, 2012
  6. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    !!!_WARNING_!!!!

    I was not kidding, that kwl_fermion demo towards the end thermally overloaded my machine into a hard reset. I knew I was due for a physical tune up but this is the kicker, after my machine has finished rebooting I'll go into a straight shutdown and break out the vacuum cleaner, solvent, and thermal past and re-seat my graphics card if I can, and the CPU definitly.

    Normally run software, even the highest of the high end will not test your computer any better than the best demosceners.
    I'm upset, I was very much enjoying the demo!
     
    Last edited: Mar 29, 2012
  7. Ubergeek63

    Ubergeek63 Well-Known Member

    Joined:
    Apr 16, 2008
    Messages:
    1,886
    Likes:
    37
    Actually...I do.

    However, most good assemblers do the code, analyze it and determine what is worth the bother.
     
  8. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Absolutely true! Welcome to Finland for Assembly: http://www.assembly.org/
     
  9. OlPhart

    OlPhart Member

    Joined:
    Feb 22, 2011
    Messages:
    331
    Likes:
    8
    Location:
    SW Michigan (USA)
    While I RARELY pick variance with...

    Howdy, the one who posted :

    "Ugly, yes, but very common thing with microcontroller. I rarely see C programmers that know how to address direct memory locations, or know what the above code does."

    I'll agree with that, but generalizations are .....

    "And with C i can write something like this and get more efficient code than most asm coders do:" Yogi: you Better Get a narrower generalization... if I'm only Not "most" asm coders.

    There's not a Ghost in Hell your complied code will come even close to a "well crafted" asm build... (30+yrs doing). Sorry for the umbridge, rash generalizations really twist my wick. <<<)))
     
    • Like Like x 1
  10. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    I reseated my chip/heatsink after a good cleaning.
     
  11. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,681
    Likes:
    13
    So, you have ruined your computer just to enjoy the demo. I have downloaded the file you attached. It has an executable file. Do you want me to run that file? I won't run it on my own computer because right now I'm short on money and won't be able to buy a new one! :) But I have ample of computer to mess up with at school. Rather I would be happy to run it there if it can really mess up the computer. Right now, I'm using a rather slow internet connection, so I will watch Demoscene videos when I get back home. Thank you.

    Regards
    PG
     
  12. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    Ruined? No as I said I'd noticed some system instability previously and this was just the proof that my machine needed cleaning. You should have seen the 'sweater' I pulled off the heat sink grill, and the heat sink paste was pretty crusty, I generally vacuum the machine out once a year and reseat the heatsink every two years on my computers.

    Yes, you have to run the program, I virus scanned it and vouch for it, it was an okay demo, I'm kind of glad you made this thread because it's been years since I caught up on the demoscene, the visuals and music in these is top notch and it is absolutely amazing some of the fluid dynamic effects they can do nowdays and more to the point how little code is actually required.

    There are some 64k demo's that allow you to use DirectX API that you would never believe in a million years could actually be only 64k, they use procedural texture generation and some hardcore assembly fine tuning.

    The warning is just that it will run your process at it's absolute peak level, mine sounded like it was going to take off because the fan turned all the way up =)
     
  13. PG1995

    PG1995 Active Member

    Joined:
    Apr 18, 2011
    Messages:
    1,681
    Likes:
    13
    Thanks a lot for the reply, Sceadwian.

    There is no need to vouch for anything because the first I saw it I downloaded it because I know you and can trust you! :)

    It's not running here. Please have a look on the attachment. Thanks.

    Regards
    PG
     
  14. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    Pg1995, you need to have a modern machine, basically anything MADE during the +/-2 years that was considered industry standard or better in hardware.

    Get on a decent machine and check out this winner, it weighs in at the 64k scale and blows the mind.

    On my machine for the fltatz's demo I have to render it at 640x480, there are video's however that show the hi def version. Keep in mind this is a 62 kilo BYTE executable that does THIS.
     
  15. Dean Huster

    Dean Huster Well-Known Member

    Joined:
    Feb 1, 2003
    Messages:
    1,203
    Likes:
    29
    Location:
    Harviell MO USA
    I've skipped over most of this just to enter my thoughts on the original post.

    I was always taught that for programmers, "clean, tight code" was the goal and was their pride. Efficiency and speed.

    If you think that a modern OS is written in microcode (assembler or machine code), you're wrong. That's why computer speed, RAM size and HDD sizes have gotten to where they are. It takes all that space and all that speed to run that sloppy code fast enough to be acceptable. If an OS was written in machine code from the outset, it would probably run as fast on a 12MHz machine as the lead weight that we have now runs on a 1GHz machine.
     
    • Like Like x 1
  16. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    It would also delay new software releases and major upgrades by more than the lifetime of the hardware speed increases.... As the speeds level out and Moores law fails, software optimization will become more important. It already had to a lessser degree from the migration towards cell phone and tablet style apps, as opposed to common bloatware that takes up entire DVDs.
     
  17. WTP Pepper

    WTP Pepper Active Member

    Joined:
    Jan 24, 2012
    Messages:
    648
    Likes:
    41
    Location:
    UK
    I disagree. I take it you are talking about embedded graphic types in documents as an example. If you have tight embedded routines in assembler then you can do anything. A high level language just makes life easier for a "script kiddie". A really good programmer can take such and embed in anything.

    Windows is a very powerful OS, but has sadly made life too easy for bad programmers as I previously stated. Many years ago I wrote a routine for speech recognition using Markov models in C. It took about 3 seconds to determine what was said under MSVC1.5. When re-coded in asm it was almost instantaneous. That was on a i386 running at 25MHz.
     
  18. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    I agree with WTP Pepper completely, higher level programming languages are only required for complex problems if the person that's programming it has a simple mind (relatively speaking) I don't mean to say that there are a lot of 'simple minded' programmers out there but what someone with a high IQ and solid management skills can do with assembly is absolutely incredible. Just as further example in the Demoscene, try looking up the 64k competition entries, that's 65536 byte limit entries. You'd never believe you could do so much with so little code, then again it's partially cheating as it utilizes Windows API's.
     
  19. nsaspook

    nsaspook Well-Known Member

    Joined:
    Mar 24, 2010
    Messages:
    1,141
    Likes:
    219
    Location:
    Fairview, Or
    Like I said before the problem with low level machine level languages is not computational complexity, it's data complexity. Of course a CPU bound demo will be faster in hand optimized assembler but the absolute speed of a function is not the real problem on a system where the interactions of data and hardware can be much more complex than the instruction set of the processor. The Linux OS is a good example, I doubt that Linus Torvalds is 'simple minded' programmer.
     
    • Like Like x 1
  20. Sceadwian

    Sceadwian Banned

    Joined:
    Oct 27, 2006
    Messages:
    14,047
    Likes:
    141
    Location:
    Rochester, US
    I'm not sure how this applies to what I was saying at all, you're comparing hand optimized ASM code designed for a specific purpose to a general purpose operating system, there is no relevant comparison to be had they have nothing to do with each other. You somehow managed to distort what I said into some personal slight against Linus Torvald which is so far from my intent I take offense at even the suggestion what I've said previously could even be possible related to your statements!

    Any code Linus Torvald wrote can still be improved by recoding it in ASM for the specific platform. This is the entire point of open source software, GCC fully supports inline assembly. No one uses it because it's easy and faster to just stack more and more code on top of more and more code on top of more and more code over and over and over again until the operating system is what it has become today.

    The only modern reboots to the OS so far have been IOS, Android, and Microsoft is starting to edge in slowly. They achieved this via a complete reset of the entire system. Going to be a rough next 10 years for software developers.
     
    Last edited: Mar 31, 2012
  21. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Ok. Now I'm very interested to hear what is the most complex thing you (asm coders) have programmed? Mostly in terms of data structures and algorithms, DSP, communication protocols, file system...
     
    Last edited: Apr 1, 2012
Thread Status:
Not open for further replies.

Share This Page