为什么需要寄存器(为什么不只使用内存)? [英] Why are registers needed (why not only use memory)?

查看:83
本文介绍了为什么需要寄存器(为什么不只使用内存)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习汇编(我曾使用过 之前).

I am just starting to learn Assembly (I have worked with c++ before).

我想知道为什么除了使用内存还需要使用寄存器,为什么不直接使用内存?

I am wondering why do we need to use registers in addition to using memory, why not just use memory?

我想最明显的原因是在寄存器中进行计算比在内存中进行计算要快得多.但这是唯一的原因吗?

I guess the most obvious reason is that doing calculations in a register is much faster than doing calculations in memory. But is this the only reason?

推荐答案

因为 RAM 很慢.很慢.

寄存器位于内部 CPU,紧邻ALU,因此信号几乎可以立即传输.它们也是最快的内存类型,但它们占用大量空间,因此我们只能拥有有限数量的内存.增加寄存器数量增加

Because RAM is slow. Very slow.

Registers are placed inside the CPU, right next to the ALU so signals can travel almost instantly. They're also the fastest memory type but they take significant space so we can have only a limited number of them. Increasing the number of registers increases

  • 芯片尺寸
  • 信号传播所需的距离
  • 在线程之间切换时保存上下文
  • 指令编码中的位数

阅读如果寄存器如此之快,为什么我们没有更多的寄存器?

更常用的数据将被放置在缓存中,以便更快地访问.过去缓存非常昂贵,因此它们是可选部件,可以单独购买并插入 CPU 外部的插座中.如今,它们通常与 CPU 位于同一个芯片中.高速缓存由 SRAM 单元构成,SRAM 单元比寄存器单元小,但速度可能是其数十或数百倍.

More commonly used data will be placed in caches for faster accessing. In the past caches are very expensive so they're an optional part and can be purchased separately and plug into a socket outside the CPU. Nowadays they're often in the same die with the CPUs. Caches are constructed from SRAM cells which are smaller than register cells but maybe tens or hundreds of times slower.

主存储器将由 DRAM 制成,每个单元只需要一个晶体管,但比寄存器慢数千倍,因此我们不能在高性能系统中只使用 DRAM.然而,一些嵌入式系统确实使用了寄存器文件,所以寄存器也是主存

Main memory will be made from DRAM which needs only one transistor per cell but are thousands of times slower than registers, hence we can't work with only DRAM in a high-performance system. However some embedded system do make use of register file so registers are also main memory

更多信息:我们可以拥有一台只有寄存器作为内存的计算机吗?

这篇关于为什么需要寄存器(为什么不只使用内存)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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