Continue to Site

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.

  • 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.

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

Status
Not open for further replies.
A language like C++ is nice because you can do object oriented programming which automatically means better code management.

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.

For a good example, say you have to measure current and a resistor value of 10 ohms isnt too bad of a choice based on the current level. You can stick a 10 ohm 1/2 watt resistor in there and it works fine because you measure the voltage across the resistor with the AD converter on the uC chip, and do the division V/10 and you get your answer to what level the current flow is at the time. Done? Well not really. Knowing Asm you know that you can divide by 8 much faster than you can divide by 10 because dividing by 10 requires a more complicated algorithm whether you write it yourself or not. So knowing a little bit about Asm means you'll probably pick 8 ohms instead of 10 ohms and this allows division by 8 with three register shifts (right shifts) which is very very fast compared to having to do any real division.

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:
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.
 
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:
!!!_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:
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)?
Actually...I do.

However, most good assemblers do the code, analyze it and determine what is worth the bother.
 
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.

Absolutely true! Welcome to Finland for Assembly: https://www.assembly.org/
 
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. <<<)))
 
I reseated my chip/heatsink after a good cleaning.
 
!!!_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!

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
 
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 =)
 
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
 
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.
 
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.
 
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.
 
When the program reach to a complex level, it no longer possible be created by a person‘s mind with assembler language.

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.
 
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.
 
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.

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
Reactions: 3v0
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.

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:
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:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top