CPU如何从RAM访问应用程序和数据 [英] How are applications and data accessed by the CPU from RAM

查看:189
本文介绍了CPU如何从RAM访问应用程序和数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将应用程序加载到RAM中并打开文件(因此文件的数据也存储在RAM中)之后,我很难理解CPU如何从RAM中访问应用程序和数据.

I am having a bit of trouble understanding how applications and data are accessed by the CPU from RAM after the application has been loaded into RAM and a file opened (thus data for the file also stored in RAM).

据我了解,当程序计数器滴答或在中断后执行任务时,CPU只是从RAM中获取指令.然后如何访问应用程序和数据.是不是它仍然并且仅获得指令(例如,将文件加载到要在应用程序中打开的硬盘驱动器上)并处理由应用程序发出的所有请求,这些请求随后作为指令存储在RAM中(例如保存一个文件).还是与打开的文件相关的应用程序和数据(例如)仅保留在RAM中,而根本不被CPU访问.

By my understanding, a CPU just gets instructions from RAM as the program counter ticks or carries out tasks after an interrupt. How then does it access the application and data. Is it that it doesn't and still just gets instructions (for example to load a file on the hard drive to be opened in the application) and processes any requests made by the application which are stored in RAM as instructions thereafter (like saving a file). Or does the application and data relating to an opened file (for example) just stay in RAM and not get accessed by the CPU at all.

类似地,在阅读文章后,它表示操作系统的副本存储在RAM中.然后,CPU可以访问操作系统. (我认为CPU只是处理来自RAM的指令).然后,它如何与操作系统通信,以及如何从RAM中的OS副本或硬盘驱动器中的OS发送中断给CPU.

Similarly, after reading an article, it said that a copy of the operating system is stored in RAM. The CPU can then access the operating system. (I thought the CPU just worked with instructions from RAM). How does it then communicate with the operating system and how are interrupts sent to the CPU, from the copy of the OS in RAM or from the OS in the hard drive.

很抱歉,这真的令人困惑,很多我听不懂.

Sorry if this is really confusing, alot i didn't understand.

推荐答案

问题的根源:计算机硬件与计算机软件之间缺乏清晰的区分.

Root of your question: Lack of clear differentiation between Computer's Hardware and Computer's Software.

我也不要求拥有关于计算机硬件和软件的天才知识和完整知识,并且只要到达答案中的任何位置,都不会超出我的领域(即软件).

I am making no claim to have genius and complete knowledge about Computer hardware and software either, and will not go beyond my domain (which is software) if I reach the boundary anywhere in the answer.

为使我们清楚地了解它们并了解它们的性质,请允许我声明如下:

Just so that we are clear about both of them and that we understand their nature, let me state as follows:

  • 硬件:它包括CPU,RAM,磁盘,寄存器,图形卡,网卡,Memory BUS以及您可以触摸并称为计算机"的所有内容.是身体.
  • 软件::它包括操作系统,程序,CPU指令,编译器,编程语言以及几乎所有与计算机无形有关的内容.这是灵魂.
  • 固件:基本代码对于硬件的工作至关重要.它存储在硬件本身安装的只读存储器中.该软件对硬件至关重要,因此被认为是在硬件和软件中间,因此被称为固件.
  • Hardware: It includes CPU, RAM, Disk, Register, Graphics Card, Network Card, Memory BUS and everything that you can touch and call to be the 'Computer'. It is the body.
  • Software: It includes Operating System, Program, CPU instruction, Compiler, Programming Language and almost everything intangible about the computer. It is the soul.
  • Firmware: It is that basic code which is absolutely essential for hardware's working. This is stored on a Read Only Memory installed in the hardware itself. This piece of software is vital for hardware therefore is considered in the mid of hardware and software and hence called Firmware.

从说计算机启动并运行并正确执行我们的指令之时起,我们就开始进行理解.但是那时您会说-我是怎么到达这里的?所以我会提到有关计算机启动的几点.

We will start with understanding from the time when we say that the computer is up and running and is properly executing our instructions. But at that time you will say - How did I reach here? So I will mention a few points about the startup of the computer.

...最原始的 基本输入输出系统 (因此称为 BIOS )(硬写在计算机硬件上)开始执行.这写在只读存储器上,这将启动使机器独立运行的过程.并将软件(操作系统)从一个硬件(磁盘)加载到另一硬件(RAM和CPU寄存器)中,从而使该软件与硬件一起正常工作.

...the most primitive and basic input output system (therefore called BIOS), which is hard written on the computer hardware begins execution. This is written on Read Only Memory and this starts the process to get the machine to stand on its own. And it loads the software (Operating System) from one piece of hardware (disks) into another piece of hardware (RAM and CPU registers) enabling the software to work properly with hardware.

现在身体和灵魂在一起,个人(机器)可以工作了.

Now the body and soul are together and the individual (machine) can work.

直到现在,操作系统已经在RAM和CPU中. (如果不确定,请阅读When the power button is pressed.)让我们逐段处理您的问题-

Until now, OS is already in RAM and CPU. (Read When the power button is pressed if you doubt it.) Let's handle your question paragraph by paragraph now -

我在理解应用程序和数据的方式时遇到了一些麻烦 加载应用程序后,CPU从RAM对其进行访问 进入RAM并打开一个文件(因此该文件的数据也存储在 RAM).

I am having a bit of trouble understanding how applications and data are accessed by the CPU from RAM after the application has been loaded into RAM and a file opened (thus data for the file also stored in RAM).

--------

说明如下:

--------

The explanation is as follows:

  1. 这里的确切问题是您认为访问数据的是CPU和RAM. CPU和RAM只是执行单元.
  2. 是通过CPU和RAM(硬件)访问数据的OS(软件).它是在OS领域中执行应用程序的地方.
  1. The exact issue here is your thinking that it is CPU and RAM that access the data. CPU and RAM are only executing units.
  2. It is OS (software) that accesses the data by means of CPU and RAM (hardware). It is in the realm of OS where applications are executed.
  1. 这就是为什么您可以在相同的硬件上安装Linux和Windows,但是不能在Linux中执行.exe文件的原因,因为OS由执行而不是由RAM/CPU执行.

  • 此外,CPU与RAM和磁盘如何物理交互以引入数据,执行数据,将其保存回等,这在硬件领域中.那将需要作出解释,其中涉及逻辑门(AND,OR,NOT ...),二极管,电路以及电子工程师可以解释的许多其他事情.

  • 第二段

    据我了解,CPU只是从RAM获取指令,因为 程序计数器在中断后滴答或执行任务.如何 然后访问应用程序和数据.是不是 并且仍然只是获得说明(例如,将文件加载到 硬盘驱动器在应用程序中打开)并处理任何 由应用程序发出的请求存储为RAM 此后的说明(例如保存文件).

    By my understanding, a CPU just gets instructions from RAM as the program counter ticks or carries out tasks after an interrupt. How then does it access the application and data. Is it that it doesn't and still just gets instructions (for example to load a file on the hard drive to be opened in the application) and processes any requests made by the application which are stored in RAM as instructions thereafter (like saving a file).

    --------

    您已经猜到了-CPU没有得到指令,操作系统则通过CPU来获得指令.同样,只是大脑不直接指示手和腿移动,而是利用神经进行交互的方式,CPU不会告诉磁盘提供/获取数据. CPU仅与RAM和寄存器配合使用.多个硬件单元协同工作,为数据和指令的传输提供了路径.涉及的硬件的重要部分是:

    --------

    As you have guessed it - CPU doesn't get instructions, Operating System does it through CPU. Also, just the way brain doesn't directly instruct the hands and legs to move and instead uses nerves for interaction, the CPU doesn't tell the disks to give/take the data. CPU works with RAM and registers only. Multiple units of hardware work in conjunction to provide a path for data and instruction to travel. The important pieces of involved hardware are:

    1. 处理器(CPU和内置在CPU中的寄存器)
    2. 缓存
    3. 内存(RAM)
    4. 磁盘
    5. 磁带

    我喜欢这个答案.该图像不仅列出了硬件部件,而且还说明了这些部件在执行速度上的巨大差异.

    I like the image provided in this answer. This image not only lists the hardware pieces but also illustrates the mammoth difference in the execution speed of these pieces.

    让我们继续...

    同样,在阅读了一篇文章之后,它说 操作系统存储在RAM中.然后,CPU可以访问 操作系统. (我以为CPU只是与指令一起工作 从RAM).然后如何与操作系统进行通讯,以及 如何从RAM中的OS副本将中断发送到CPU或 从硬盘驱动器中的操作系统中获取.

    Similarly, after reading an article, it said that a copy of the operating system is stored in RAM. The CPU can then access the operating system. (I thought the CPU just worked with instructions from RAM). How does it then communicate with the operating system and how are interrupts sent to the CPU, from the copy of the OS in RAM or from the OS in the hard drive.

    --------

    到现在,您已经知道操作系统确实存在于RAM和CPU寄存器中.那就是它的住所.那就是从那里告诉CPU如何工作的.如果操作系统足够小(或者寄存器和缓存足够大),则操作系统的寿命甚至会更接近CPU.

    --------

    By now you already know that indeed OS is present in RAM and CPU registers. That is where it lives. That is from where it tells the CPU how to work. If OS would be small enough (or if Registers and Caches would be big enough), the OS would live even closer to CPU.

    • CPU无法与OS通信.不可以老板控制的是工人.操作系统就是那个老板.
    • CPU无法访问操作系统. CPU是身体,OS是灵魂.灵魂告诉身体该怎么做.身体无法进入灵魂.
    • CPU无法与RAM中的指令一起使用.它仅执行操作系统给出的指令(可能位于RAM中).因此,即使有指令将某些操作系统模块加载到RAM中,发出该指令的也不是RAM/CPU,而是操作系统本身.
    • 中断 有两种类型-硬件和软件-您的查询是关于软件中断的.由于操作系统的执行部分在RAM中,因此可以简单地说,中断是从驻留在RAM中的OS发送到CPU的.
    • The CPU does not communicate with the OS. It can't. It is the worker that is controlled by a boss. OS is that boss.
    • CPU cannot access Operating System. CPU is the body, OS is the soul. Soul tells the body what to do. Body cannot access soul.
    • CPU doesn't work with instructions from RAM. It merely executes the instructions given by the Operating System (which may be living in RAM). So even when there is an instruction to load some module of OS into the RAM, it is not RAM/CPU but OS itself that issues that instruction.
    • Interrupts are of two types - Hardware and Software - and your query is about the software interrupts. Since the executive part of OS is in the RAM, in simple words we can say that interrupts are sent to CPU from OS living in RAM.

    硬件和软件之间缺乏区分是造成混乱的根本原因.在 Coursera

    The lack of distinction between hardware and software is the basic cause of your confusions. Take some course about Operating Systems on Coursera or Academic Earth for deeper understanding.

    在我的答案中发现错误的人.

    • 可以随意编辑答案,或者告诉我一些琐碎的事情.
    • 如果更大,请告诉我,我很高兴知道更多.
    • 另外,请阅读我的答案的第二段.

    这篇关于CPU如何从RAM访问应用程序和数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆