0

I've learned the Assembly programming of the 8086 Intel processor in the college. I'm now trying to revise it.

I've heard that Assembly is required in Automotive Embedded Systems so I want to know which way to learn it is the best? I don't need to waste time as I want to get a job.

Does revising the Assembly of the 8086 really help? Or moving to something like the 32bit x86 Assembly is better?

Thank you.

Gamal Othman
  • 93
  • 10
  • x86 is rarely used in embedded systems. Its main advantage is backwards compatibility, and that *very* high performance implementations of it are available. And to some degree, code density thanks to its variable-length encoding. But that doesn't compensate for the power cost of decoding it efficiently in an embedded CPU. – Peter Cordes Nov 16 '18 at 20:56
  • 1
    there is no general Assembly, every CPU is original, and even for the same CPU there are often several assemblers with slightly different syntax (although the resulting instructions are of course identical, because that's defined by CPU in HW, but various directives, or syntax sugar, may be completely different) – Ped7g Nov 16 '18 at 21:46
  • But I've read in wikipedia and other sites that *Assembly is required for its speed and reliability in systems like automotive embedded systems and aeroplane systems.* As it optimizes the code to the machine level, that is a great thing! Also the using of *code optimizers* to do the job doesn't always work as planned and may result in **errors** or **non-perfect code.** – Gamal Othman Nov 16 '18 at 21:54
  • Once you know asm for one CPU and understand how registers work, and how C compiles to asm, it's not hard to learn asm for a 2nd architecture. – Peter Cordes Nov 16 '18 at 22:01
  • 1
    @PeterCordes : There are a lot of embedded systems especially based on the 80186. There have been many variants of that chip including SoC that spanned a good 20-25 years. Although harder to find now (production has dropped off), a lot of existing embedded devices still use them. Also helped that some of them were mil spec. – Michael Petch Nov 16 '18 at 22:06
  • @MichaelPetch: Interesting. I don't do embedded development, but mostly what I've heard about is ARM and some RISC ISAs like MIPS, and at the lower end mostly PIC or 8051. (With AVR being popular with hobbyists). – Peter Cordes Nov 16 '18 at 22:14
  • 2
    @GamalOthman ; Assembly does not in itself optimise anything - quite the contrary, it does _exactly_ what the programmer asks an the machine instruction level. Whether that is optimal depends entirely on the skill of the programmer in that _specific_ constriction set. On the other hand is you write C code it will be more portable and the compiler _is an expert_ is the target instruction set ad will out do most programmers. The real expert assembly programmers are the ones writing the compiler optimisers, nor wasting their energy hand optimising assembly code. – Clifford Nov 16 '18 at 23:21
  • 1
    @GamalOthman If you have read something "wikipedia and other sites", you should include a link or citation. It is certainly by no means "_required_ for automotive systems", and I suspect is not used for the majority of automotive code. Generally when a compiler optimiser generates incorrect code it is because the input source relies on some undefined behavior. While it is true that the optimizer is the most likely place for a compiler to have bugs because it is the most complex, these are rare and getting any not trivial assembly code correct is hard work and maintaining it harder. – Clifford Nov 16 '18 at 23:31
  • @Clifford This citation is from Wikipedia article **"Assembly Language"** : _There are some situations in which developers might choose to use assembly language: A stand-alone executable of compact size is required that must execute without recourse to the run-time components or libraries associated with a high-level language; this is perhaps the most common situation. For example, firmware for telephones, automobile fuel and ignition systems, air-conditioning control systems, security systems, and sensors._ And this is the link: (https://www.wikiwand.com/en/Assembly_language) – Gamal Othman Nov 17 '18 at 10:52
  • @Clifford I did not mean that programmers should do all the work using Assembly. But what I mean is using it in _specific_ situation in which optimizing the code (taking less memory & improving execution speed) is required. – Gamal Othman Nov 17 '18 at 11:01

1 Answers1

7

Your title asks an entirely different question than the body. Generally you should ask one straightforward question.

No, there is no general assembly syntax - or actually there is, but you probably don't mean that, assembly syntax is generally:

[<label>:] <opcode> <operands> [<comment>]

or similar.

For x86 there are two common syntaxes in fact - Intel and AT&T (with multiple variants of Intel syntax from different assemblers, including totally different directives for lines that aren't instructions), but they and others are more or less of that form.

But what you probably meant is is there a general assembly language instruction set. If that is the case then no there is not. That is not the same thing as syntax. Like a natural language, machine languages have syntax, vocabulary, and semantics - how the words are ordered, what words are available, and what they mean. The point about assembly language is that there is a one-to-one relationship between the assembly mnemonics and the machine-code instruction set. Therefore there are as many assembly languages as there are processor architectures.

Does revising the Assembly of the 8086 really help? Or moving to something like the 32-bit Assembly is better?

16-bit 8086 assembler is seldom used (outside of teaching as in your case), and x86 in general is not generally an automotive device if that is what you are interested in. "32-bit Assembly" is not a thing, unless you are specifically referring to 32-bit x86 assembly.

Learning an assembly language is useful for understanding the fundamentals of how a computer works - that is probably why you were taught an obsolete instruction set, because the aim is not to be able to code in it, but rather to comprehend the fundamental principles. That in turn can result in writing better high-level language code that compiles to smaller, faster machine language code. It can also be useful in debugging high-level code - sometimes you need to step at the instruction level to understand why the compiler-generated code does not do what you expect. But for that you only need to be able to read assembly, not to write it.

Assembly language for large bodies of code that could be implemented in systems level language such as C or C++ is unnecessary and unproductive. Not only is the compiler an expert in the target machine code instruction set, so you don't have to be, but a high-level language is also more likely to be supported by a wide range of tools for testing, validation, static analysis, security analysis, performance analysis and error detection. The code will also be more maintainable, more reusable, and be able to benefit from a wider range of third-party libraries.

Also look at it this way, so you are an expert in PIC assembly for example, but your next job is for an ARM Cortex-M, now you are no longer an expert, and will write far worse code than the compiler will generate, and take far longer doing it. Then you are unemployed.

Over a large code base, a modern optimizing compiler may well do a better job of making efficient asm than a human could or would, outside of a few important loops which you can come back and tune (either by tweaking the C or rewriting that one loop in asm). Inlining and constant-propagation are hard in asm, but compilers are excellent at it. This is especially true for processors that are good compiler targets and that compiler developers have spent a lot of time on, like x86 or ARM.

ecm
  • 2,583
  • 4
  • 21
  • 29
Clifford
  • 88,407
  • 13
  • 85
  • 165
  • Thank you. I'm just a beginner in programming, sorry for the wrong expressions. Now, what I understood is that Assembly would not help me that much in my situation. I'd rather go deep in C and that would be sufficient. Am I right? – Gamal Othman Nov 17 '18 at 11:21
  • 1
    There is also Plan 9's assembly syntax which is mostly relevant if you write assembly for use in Go programs. – fuz Nov 17 '18 at 11:44