Open question to software/firmware developers; Assembly.....

StreuB1

Well-Known Member
Joined
Aug 28, 2007
Messages
1,044
Reaction score
1,206
Location
Illinois
So I have recently (a year ago....) taken a class, my first programming class (I am 45 ATM), at community college. It was C++ for Engineers and Scientists and was essentially a 16 week course into C++ where we went from Hello World to writing some relatively simple interactive software to perform calculations and computations for a user. I deeply enjoyed it but haven't messed around with it in a while, though it tickled an itch that I never knew I had. I found out I loved programming. I watch a load of videos on software and whatnot so its something that obviously deeply interests me.

This spring, I plan on taking possibly two classes at once and lately I have been wondering something that I would like some feedback on from the plethora of software dev's that frequent our little corner of the ether.

About half way through my class last year, my boss at the time (a software developer himself) mentioned to me the idea of writing in-line assembly in C++ for certain tasks that can be done more directly and faster as assembly, even though the compiler will do it for you. That doing certain things directly in this way, is a way to guarantee that the end result, is not the interpreted outcome based on the compiler, but the exact outcome that the engineer intends.

This blew my mind, the idea of writing in one language, inside another language. Bear in mind, this was my first foray into software so its no wonder that this was like some sort of odd magic.

So here then is my question. Would be benefit me to take a class in Intel Assembly? I believe it would as the way it was explained to me by my professor, my boss, our former IT director, that learning software from the beginning at a low level teaches you to think and act like a programmer and helps teach you to write robust and efficient code. With that in mind, would it not then make sense to be at least a bit knowledgeable in Assembly?

I really would like some honest real-world thoughts on this and have an open discussion that might not only benefit me, but others as well. We have a lot of wildly intelligent people here and its a waste to not exploit their knowledge and experience.

@Adrian A @VernK @cerving @jderimig @troj @Chad
Please tag other dev's on the forum as well who you believe would have some insight on this


I am a sr electromechanical design engineer so my interests are in microcontrollers and other devices that interact with the outside world, collect data, do things, etc. What exactly, I really don't know! That was one the hardest things I realized when I became able to somewhat write useable code......what do I do with it!?!? That still is a complicated question, but I do have some new ideas that I would like to try out, small things that I can build on. One of the things that interest me are timed events and interrupts because, well, in order to do things that are automated, you need a state machine and for that, you need timing. So understanding that is a good place to begin. Though, thats not directly my question, but I thought it might be relevant in some fashion.

Thank you all in advance!!

Side note, I have a lot of micro's that I have bought over the years with the hopes of tinkering with. Arduinos and clones, STM32 blue and black pill dev boards, PIC micro's, Raspberry Pi Pico (microcontroller, not the computer). Those are the platforms that I have to work with. I have VStudio through work and school and I work in a Windows environment and have zero knowledge of Linux other than knowing what it is.
 
Last edited:

Sooner Boomer

Well-Known Member
Joined
Mar 21, 2011
Messages
4,976
Reaction score
3,077
Assembly is a lot different from high level languages. There are a bazillion different commands in assembly vs a few hundred in higher languages. You get finer granularity of control over a process, but you also need to be aware of how your code will run within the framework of the OS or other top level software. Your job description suggests there might be a few areas where knowledge of assemble would be beneficial. One area is real-time (or near-real-time) data collection. You'll need to dig into the nuts and bolts of signal timing to the hardware, but when you have a decent mastery of that, You can gain complete control of the timing of data collection and command output.

This is one reason I started learning assembly. Things were a bit different then; the processors/controllers were 6502 and 8051.
 

cls

Well-Known Member
Joined
Jan 21, 2009
Messages
2,816
Reaction score
484
Would be good to take the class, because a deep understanding of x86 will serve you well

But, your boss is wrong about mixing assembly in with high level source. That way is non portable, and not maintainable.

Embedded software isolates the code required to be written in assembly in separate sources and modules. That way, different CPU revisions and in fact different CPUs can be supported by the same embedded application.

There is a lot more to portability, such as endianness, timings, interrupts, etc. But there's plenty of prior art for you to study, look around at several different embedded OSes.

you are taking the first steps of a fascinating journey! Enjoy it.
 

neil_w

OpenRocketeer
TRF Supporter
Joined
Jul 14, 2015
Messages
14,738
Reaction score
8,394
Location
Northern NJ
If you're going to dive into assembly language then I would steer clear of x86 assembler. ARM would be a much better instruction set to learn: it's more representative of what you're going to find in pretty much all embedded processors, and embedded processors are where you're most likely to use assembly language (if at all). x86 assembly is really different, and mostly a relic at this point.

As a high-schooler I took a class in IBM 360 assembler (punched cards! overnight batch jobs!) because I was taking every computer class I could (not much available back then). While it certainly made for a challenging and interesting semester, it was interesting mostly in a purely academic way, with little or no application to the real world. I view x86 assembler in the same way today (analogy is not perfect but maybe good enough).
 

troj

Wielder Of the Skillet Of Harsh Discipline, Potent
Joined
Jan 19, 2009
Messages
14,647
Reaction score
605
The idea of inline assembly in another language is something that has existed for decades, and it's something that has its place in the world, but isn't used very often. Where it would be most applicable is in an embedded controller where you need specific timing, or very specific behavior from the code which is hard to obtain from the compiler. Another example would be certain deep bits of a debugger, where it needs to interact with the processor in a very specific way.

Very much exceptions.

As for whether or not to learn assembly.... I'd say "It depends". Do you want to learn assembly, or have a specific reason to? Your boss' viewpoint that learning assembly "teaches you to think like a programmer" is incredibly dated. Assembly language is no longer included, by default, in many Comp Sci curriculum. It was there when I got my degree in the 80s, but no longer is.

If you want to "think like a programmer," a better advantage is to know how a *compiler* works. I can tell you that in my experience, understanding some basics of compiler behavior has been more useful to me than knowing a multiple variations of assembly.

Assembly also isn't portable. As an example, I know (but am super rusty on) Z-80, 6502, 8086 and 68000 (plus two educational virtual processors). Learning assembly for one processor doesn't provide a great amount understanding of another processor.

This is why systems like Arduino use C, but you select the target processor. That allows the compiler to emit code for the specific CPU in that particular controller.

In short, learn assembly because you want to learn it, unless you have a specific need for it. Learning it isn't going to provide you tremendous value, unless you have a need. I suspect your IT Director is 50+, as his views are a bit dated.
 

cerving

Owner, Eggtimer Rocketry
TRF Sponsor
TRF Supporter
Joined
Feb 3, 2012
Messages
5,462
Reaction score
3,543
I've always viewed C and it's variants as a kind of semi-portable high-level pre-assembler... they make you do more low-level grunt work than a higher-level language, but a lot less than assembly. Unless you're doing a very small and/or highly time-sensitive routine in an embedded processor, or writing a compiler, nobody uses assembly directly anymore, certainly not on a general purpose processor. Modern processors are fast enough that the loss of execution speed due to compiler code doing a lot more moves and branches than assembly code is way offset by the ease of developing the code in the first place.
 

Alan R

Well-Known Member
TRF Supporter
Joined
Oct 11, 2018
Messages
764
Reaction score
608
Location
Oregon
I'm with @troj on this one. +/- 1990 I had to take assembly for x86 (only 4 registers back then) and then switched schools and had to take it again for IBM 360.
We had to write a compiler in assembly for the 360 class. BXLE !
The reason for mixing assembly in line with the C code was mostly related to processor speed. If you needed something done fast, do it in assembly. 486's ran at 20Mhz. No longer the case when CPU's are running at multi-Ghz's.
Assembly teaches you how a computer works, fer sher. But not much used except in special cases now. My brother wrote assembly code for avionics modules, because size and speed were important.
As for your class choices, it's one of those bits of programmer accepted knowledge that you'll probably never write a compiler, but you're going to write parsers every week.
 

Chad

Well-Known Member
Joined
Jul 23, 2018
Messages
414
Reaction score
249
Location
Dallas
If it's something you want to learn then go for it. However, like others have mentioned, I would suggest finding an ARM assembler class if you can because then you can apply that knowledge to most of your microcontrollers. When i was diving into the AltusMetrum source code i believe they did some assembler that setup clocks and then jumped to the memory location of their "main" to start executing the AltOS logic. Their source code is pretty dense since they basically made an embedded operating system but it's still interesting to read.

I don't know if you'd ever put a semester's worth of assembler to good use though unless that was your day job. Granted, it does give you another level down the stack of how a computer works but how far down that rabbit hole do you want to go? Beneath assembler is microcode i guess and then the CPU architecture itself and then you're down to the circuits that make up digital logic.

Instead of going down you may find it interesting to go up a level. If you take a higher level language class like Java you'll recognize a lot of the concepts in C++ but taught using different terms and from a different angle. Same goes for something like C#. Tooling is also pretty interesting, if a compiler compiles your source code to a binary then what was used to compile the source code for the compiler itself?
 

jderimig

Sponsor
TRF Sponsor
Joined
Jan 23, 2009
Messages
4,898
Reaction score
2,746
In my opinion a course in assembly is an excellent way to learn how CPU's work inside and moves your understanding much closer to the machine, where as high level programming languages abstract that knowledge away from you. So I agree with your professor on that.

But....there is potentially several other things you can learn that would make you a better and more effective programmer depending on what your target is. And you probably don't have the resources and time to learn them all in a course setting. So the question is what other course options are there and then we can rank the value of assembly coding against the other choices.
 

VernK

Member/Vendor
TRF Sponsor
TRF Supporter
Joined
Oct 1, 2014
Messages
201
Reaction score
226
Location
Boise, Idaho
I agree with what has already been said and I am not sure I have much to add. I did a lot of assembly language programming back in the old 8-bit Z80 and 8051 days. However, with modern compilers I don't see any reason these days to learn assembly language coding unless you are designing the CPU inside a microcontroller. A number of years ago, I looked at some of the assembly language being produced by a good optimizing compiler. I was very impressed. The code was dense and efficient. There were all sorts of little tricks being used that I probably never would have thought of on my own. Including re-ordering instructions to take advantage of the decoding pipeline and pre-fetch operations used it modern microcontrollers. It convinced me there was probably no need for me to ever worry about assembly language programming again. And I never have. There is zero assembly language code in the Kate products.

It seems to me, a general overview of assembly language concepts and a general understanding of what it does and how it works from a hardware point of view is good. However, rather than go into great depth on it, I think a better use of your time would be to learn a higher level language such as Python because it complements C and C++ so nicely. For one thing, Python can be handy for implementing test beds that are used to test and exercise the target hardware your C and C++ code is running on. Furthermore, I think learning to use a good version control system such subversion or GIT is also more important than learning assembly language.
 

blackwing94

Well-Known Member
Joined
Jan 5, 2016
Messages
204
Reaction score
144
I loved programming. I hated assembly language. I worked in TI 980, IBM 360. Once I moved up to higher level languages (I guess that would be Fortran 77), I never looked back. Ended my career writing Perl and PHP. I was a happy camper.

If you work in assembly, do you still have to learn vi? :)
 

Dan Griffing

Well-Known Member
TRF Supporter
Joined
Aug 5, 2020
Messages
468
Reaction score
318
Location
Belgrade, MT
So I have recently (a year ago....) taken a class, my first programming class (I am 45 ATM), at community college. It was C++ for Engineers and Scientists and was essentially a 16 week course into C++ where we went from Hello World to writing some relatively simple interactive software to perform calculations and computations for a user. I deeply enjoyed it but haven't messed around with it in a while, though it tickled an itch that I never knew I had. I found out I loved programming. I watch a load of videos on software and whatnot so its something that obviously deeply interests me.

This spring, I plan on taking possibly two classes at once and lately I have been wondering something that I would like some feedback on from the plethora of software dev's that frequent our little corner of the ether.

About half way through my class last year, my boss at the time (a software developer himself) mentioned to me the idea of writing in-line assembly in C++ for certain tasks that can be done more directly and faster as assembly, even though the compiler will do it for you. That doing certain things directly in this way, is a way to guarantee that the end result, is not the interpreted outcome based on the compiler, but the exact outcome that the engineer intends.

This blew my mind, the idea of writing in one language, inside another language. Bear in mind, this was my first foray into software so its no wonder that this was like some sort of odd magic.

So here then is my question. Would be benefit me to take a class in Intel Assembly? I believe it would as the way it was explained to me by my professor, my boss, our former IT director, that learning software from the beginning at a low level teaches you to think and act like a programmer and helps teach you to write robust and efficient code. With that in mind, would it not then make sense to be at least a bit knowledgeable in Assembly?

I really would like some honest real-world thoughts on this and have an open discussion that might not only benefit me, but others as well. We have a lot of wildly intelligent people here and its a waste to not exploit their knowledge and experience.

@Adrian A @VernK @cerving @jderimig @troj @Chad
Please tag other dev's on the forum as well who you believe would have some insight on this


I am a sr electromechanical design engineer so my interests are in microcontrollers and other devices that interact with the outside world, collect data, do things, etc. What exactly, I really don't know! That was one the hardest things I realized when I became able to somewhat write useable code......what do I do with it!?!? That still is a complicated question, but I do have some new ideas that I would like to try out, small things that I can build on. One of the things that interest me are timed events and interrupts because, well, in order to do things that are automated, you need a state machine and for that, you need timing. So understanding that is a good place to begin. Though, thats not directly my question, but I thought it might be relevant in some fashion.

Thank you all in advance!!

Side note, I have a lot of micro's that I have bought over the years with the hopes of tinkering with. Arduinos and clones, STM32 blue and black pill dev boards, PIC micro's, Raspberry Pi Pico (microcontroller, not the computer). Those are the platforms that I have to work with. I have VStudio through work and school and I work in a Windows environment and have zero knowledge of Linux other than knowing what it is.
I spent the last two decades of my engineering career writing firmware for scientific and engineering applications. Although I had years of experience with C++, I prefer C as a universal language for getting close to the silicon.

But for the most part, (and with the exception of mathematical and data handling algorithms), the portability of firmware is not that important, because firmware is highly specific to the hardware and application. (And what I found indispensable for the mathematical and data handling algorithms was Numerical Recipes in C.)

Unavoidably, moving from one processor to another is a really big deal. But there’s no way around this because of the drastic changes in architecture. This is one of the reasons why companies pick an architecture that they can use for a number of years before changing.

What I used inline assemblers for was when I was doing specific things with hardware interface registers and needed it to be done without the C compiler changing something. But this code was used quite rarely, and it was clearly identified and in no danger of messing things up while being ported from one project to another.
 

jmasterj

Low and slow
TRF Supporter
Joined
Aug 16, 2021
Messages
1,100
Reaction score
843
Location
Maryland
I've been a software dev for over 10 years, and I wouldn't recommend an assembly class either. If you want to understand what's going on at a lower level, I would consider a Computer Organization or Operating Systems class. At minimum, those will help you figure out where you want to learn more.
 

WoShuGui

Well-Known Member
TRF Supporter
Joined
Apr 22, 2013
Messages
532
Reaction score
101
Aside from gaining a better understanding of or needing to write code based on exactly how the hardware actually works, there is little reason to learn assembly these days. Assembly used to be a way to save code space for memory limited applications. C++ compilers are now much better at generating compact machine code so memory space is rarely a good reason to use assembly any more.
 

Dan Griffing

Well-Known Member
TRF Supporter
Joined
Aug 5, 2020
Messages
468
Reaction score
318
Location
Belgrade, MT
Aside from gaining a better understanding of or needing to write code based on exactly how the hardware actually works, there is little reason to learn assembly these days. Assembly used to be a way to save code space for memory limited applications. C++ compilers are now much better at generating compact machine code so memory space is rarely a good reason to use assembly any more.
As I recall from my last experience with it almost a decade ago, the inline C "assembler" was quite generic, and extremely limited, primarily toggling hardware register bits in the electrical interface connected to the processor and either getting or putting data bytes into those interface hardware registers from the processor registers that interfaced directly with C. At most, I had to write a dozen lines of code to perform each task. I spent years programming in assembler in the late 70's and by comparison, doing this limited amount of assembly code didn't require anything but the scantest understanding in assembly language or the architecture of the processor. As I recall, I looked at the underlying code generated by the compiler for the simplest of procedures to learn what assembly code was required.
 
Last edited:
Top