The relationship between microcontroller instruction set and operating system[Copy link]
1> First, let's discuss the relationship between various single-chip microcomputers and operating systems. Speaking of single-chip microcomputers, the first thing that comes to mind should be the 51 single-chip microcomputer, right? Yes, we also think it's acceptable to call the more advanced AVR a single-chip microcomputer. Then we are more accustomed to calling the more advanced ARM7, 8086, 80386, Core i3, Athlon, etc. CPUs, because that's what we call them when we study computer principles, but according to the definition of single-chip microcomputers, they also belong to single-chip microcomputers. This is not everyone's fault. Chinese education is like this, focusing only on telling you what they are, but not telling you the connection between them. The above-mentioned single-chip microcomputers or chips (if you still feel uncomfortable calling core i3 a single-chip microcomputer) are the same in principle, that is, they are all composed of arithmetic units, controllers, and registers. The difference is that their hardware circuits are implemented differently, the number is different, the power consumption is different, and the computing power is different, but they all provide the same basic skills. OK, finally let the cpu find the organization, then introduce why some microcontrollers need operating systems, and some have nothing to do with operating systems in our learning process. When learning 51/AVR microcontrollers, we first introduce what resources they have - how many registers, how many clocks, etc., and then how to use assembly, C or C and assembly mixed programming. The languages we use here can directly operate hardware resources, so we can decide when to use which register and when to write the register content to the auxiliary memory. When learning ARM microcontrollers, we can equip them with operating systems, such as MicroC/OS, iOS X, Android or other customized Linux operating systems, but sometimes we often do not let it carry an operating system, but directly operate it like using 51 microcontrollers. Core i3 / Athlon microcontroller (or CPU, if you still don't like to use microcontroller to describe such awesome hardware) You have hardly heard of anyone around you developing applications on this microcontroller (if there is, please introduce me to someone). Because the applications developed on this microcontroller have a very awesome name - operating system! Since this microcontroller provides too many resources and can do too much, we need a special program to manage it to avoid repeated development of the same functions. In this way, we can be freed from hardware programming and focus more on application-level development. In a sense, the operating system is just an application, but it is a little special. In general, in this case, it would be better to make an analogy - bicycles and cars. Bicycles are simple, and we are also familiar with its composition and components. If the chain falls off, we can also handle it. This is like a 51 microcontroller, which has few resources and can handle it. In comparison, cars are much more complicated, with deceleration systems, brake systems, electronic systems, air conditioning systems, etc., but we don't need to know how their hardware works. We just need to know which switch to press and which pedal to step on. This is like the operating system on a single-chip microcomputer. It does not require us to know the hardware structure. If we want to realize the function, we can directly call the API provided by the system. When we keep pedaling the pedals with our feet, the bicycle moves forward. We clearly know the operating principle of each component; but if you step on the accelerator and the car starts running, I think most people don't understand which components are involved and the principles of each component. But this does not prevent us from using it, does it? 2> The relationship between cpu and instruction set The cpu relies on instructions to calculate and control the system. Each CPU specifies a series of instruction systems that match its hardware circuits when it is designed, or the hardware design of a certain cpu is actually a hardware implementation of a certain instruction set. The instruction set, also known as the target code (or machine code, which is code that can be run directly on the CPU), can be seen as the functions that the CPU is required to provide to the outside world. The design of a certain CPU must be oriented towards a certain instruction set. Therefore, different CPU architectures also mean that its instruction set is either expanded from the previous instruction set or implements a completely new instruction set. An instruction in the instruction set allows the CPU to complete a series of actions, and the completion of the action indicates the completion of a certain operation. A function may require one or several instructions to implement. For example, the assembly MOV or LD statement may correspond to several CPU instructions. The following introduces the correspondence between several common CPU architectures and instruction sets (the so-called architecture refers to the implementation of hardware circuits): Intel X86 architecture CPU may implement multiple instruction sets x86, x86-64, MMX, SSE, SSE2, SSE3, SSSE3, and the instructions in these instruction sets make the actions completed by the CPU more complicated, so they are also called CISC AMD amd64 architecture CPU is compatible with the x86 instruction set and has also expanded the 3D-Now! instruction set to enhance support for 3D display. ARM ARMv1~ARMv7 architecture CPUs implement the Thumb instruction set and the ARM instruction set. An instruction in these instruction sets makes the actions that the CPU completes relatively simple, so it is also called RISC instruction set. 3> The relationship between instruction set and operating system Here we have to re-mention the two concepts mentioned earlier: instruction set - that is, machine code; operating system - that is, application program First of all, we must know that the father of computer, von Neumann, said that computers can only run on binary. Therefore, whether it is an operating system or an ordinary application, it must eventually be converted into binary code before it can be processed by the CPU. Ordinary applications written in high-level languages must be compiled by a compiler into binary code (instructions) before they can run. Different CPUs implement different instruction sets, so different instruction sets correspond to different compilers. Different compilers will produce different binary codes after the same high-level language program is compiled. This leads to the concepts of "transplantation" and "cross-platform". OK, let's re-think it: CPU architecture-instruction set-compiler-program are closely linked. So you will hear that the Windows operating system can only run on X86 CPUs, not on Power or ARM, because the instruction sets are different, and so there is the "Wintel" alliance. So you can also see that some compilers are provided by hardware manufacturers, such as Intel provides C and C++ compilers, so that the compiled programs can better utilize the performance of the hardware. Then why do you hear that Linux can run on CPUs of different architectures? That's because Linux is open source, so it can be ported to different CPU platforms, and then compiled with the corresponding compiler to get binary code that can run on the CPU. Windows is closed, and the source code cannot be obtained, and MS itself has no plan to port it to other CPU platforms, so of course it can only run on X86. (BTW, X86 is also one of the best CPUs, and Windows has high performance requirements, so MS is of course unwilling to port it)