简体   繁体   English

机器代码和硬件

[英]Machinecode and hardware

first of all hello to all hope you are good and safe.首先向大家问好,希望你们一切安好。

well i have some questions about machine code and hardware and operating system.好吧,我对机器代码、硬件和操作系统有一些疑问。

1- i was search about how is pure machine code and i find somethings in here and.net but not enough to answer my questions since im new to low level programming language. 1-我在搜索纯机器代码是怎样的,我在这里和.net 找到了一些东西,但不足以回答我的问题,因为我是低级编程语言的新手。 so how to write a pure machine code like open just my computer with 0,1 are machine code have any file extensions like assembly and.exe i wana write code just directly get area in ram and talk with processor and do what i writed for example open my computer or open a text file for example.所以如何编写一个纯机器代码,比如用 0,1 打开我的电脑,机器代码有任何文件扩展名,比如 assembly 和 .exe 我想写代码只是直接在 ram 中获取区域并与处理器交谈并做我写的例如,打开我的电脑或打开一个文本文件。 so i wana know how to do it are pure machine code have a file extension like.exe or.asm所以我想知道怎么做是纯机器代码有一个像.exe或.asm这样的文件扩展名

2- i know each cpu have it owen machine language somethigns is different on them it could not be a way to all cpu's undrestand our machine code. 2-我知道每个 cpu 都有它的机器语言,有些东西在他们身上是不同的,这不可能是所有 cpu 理解我们的机器代码的方法。 also i wana know for example we have 2 cpu both of them are x64 or x32 but 1 of them are windows other is linux are machine code of x64 windows will work also on x64 cpu linux?我还想知道,例如我们有 2 个 cpu,它们都是 x64 或 x32,但其中 1 个是 windows,另一个是 linux 是 x64 的机器代码 windows 是否也适用于 x64 cpu linux?

thank you for give your time to me and read.谢谢你花时间给我阅读。

for now gathering information现在收集信息

An operating system provides the capability to run programs.操作系统提供运行程序的能力。 So, one program, like the desktop or command line shell, can ask the operating system to run another program.因此,一个程序,如桌面或命令行 shell,可以要求操作系统运行另一个程序。

When that happens, the operating system creates an environment to run the program called a process , and then loads a program file from disc into the process, and directs the CPU to begin executing that program file starting at its beginning.当发生这种情况时,操作系统会创建一个环境来运行称为进程的程序,然后将程序文件从磁盘加载到进程中,并指示 CPU 从头开始执行该程序文件。

The operating system has a loader , whose job is to load the disc-based program file into memory of the process.操作系统有一个加载器,它的工作是将基于光盘的程序文件加载到进程的memory中。

The loader knows about certain executable file formats .加载程序知道某些可执行文件格式 Different operating system have different loaders and most likely understand different executable formats.不同的操作系统有不同的加载程序,并且很可能理解不同的可执行格式。

Machine code is contained in these program files, stored on disc using those file formats.机器代码包含在这些程序文件中,并使用这些文件格式存储在磁盘上。 There are other ways to load machine code into memory, though a program file stored on disc loaded by the loader is the most common approach.还有其他方法可以将机器代码加载到 memory 中,但最常用的方法是将程序文件存储在由加载器加载的磁盘上。

Asm, .asm , is a text file, human readable, for storing program code in assembly language . Asm, .asm ,是一种人类可读的文本文件,用于存储汇编语言的程序代码。 To use it, such text file is given as input to a build system, which converts that human readable program code into a program file containing equivalent machine code, for later loading into a process by the operating system.为了使用它,将这样的文本文件作为构建系统的输入提供,该系统将人类可读的程序代码转换为包含等效机器代码的程序文件,以便稍后由操作系统加载到进程中。

Not only do different operating systems support different file formats for program files, they also support different ways to interact with the operating system, which goes to their programming model that is described by an Application Binary Interface aka ABI.不同的操作系统不仅支持不同的程序文件文件格式,它们还支持与操作系统交互的不同方式,这可以通过应用程序二进制接口aka ABI 描述的编程 model 进行。 All programs need to interact with the operating system for basic services like input, output, mouse, keyboard, etc.. Because ABIs differ between operating systems, the machine code in a program written for one operating system won't necessarily run on a different operating system, even if the processor is exactly the same.所有程序都需要与操作系统交互以获得基本服务,如输入、output、鼠标、键盘等。由于操作系统之间的 ABI 不同,为一个操作系统编写的程序中的机器代码不一定会在不同的操作系统上运行操作系统,即使处理器完全相同。

Most disc-based file formats for executable program files contain indicators telling what processor the program will run on, so the same operating system on different processors requires different machine code, and hence usually different executable program files.大多数用于可执行程序文件的基于光盘的文件格式都包含指示程序将在哪个处理器上运行的指示符,因此不同处理器上的相同操作系统需要不同的机器代码,因此通常需要不同的可执行程序文件。 (Some file formats support "fat" binaries meaning that the machine code for several different processors is in one program file.) (一些文件格式支持“fat”二进制文件,这意味着几个不同处理器的机器代码在一个程序文件中。)

Operating systems also have features that allow execution of new machine code within an existing process.操作系统还具有允许在现有进程中执行新机器代码的功能。 That machine code can be generated on the fly as with JTT compilers , or loaded more informally by an application program rather than the operating system loader.该机器代码可以像JTT 编译器一样即时生成,或者由应用程序而不是操作系统加载程序以更非正式的方式加载。 Further, most operating system loaders support dynamically loading additional program file content from executable program files.此外,大多数操作系统加载器支持从可执行程序文件动态地加载额外的程序文件内容。

So, there's lots of ways to get machine code into the memory of a process for execution — support for machine code is one of the fundamental features of operating systems.因此,有很多方法可以将机器码放入进程的 memory 中执行——支持机器码是操作系统的基本特征之一。

Let's also note that no real program is pure machine code — programs use machine code & data together, so all executable file formats store both machine code and data (and metadata).我们还要注意,没有真正的程序是纯机器代码——程序同时使用机器代码和数据,因此所有可执行文件格式都存储机器代码和数据(以及元数据)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM