32/64位操作系统中一个WORD分别包含多少位?

发布于 2024-10-22 02:22:08 字数 60 浏览 4 评论 0原文

有人有明确的答案吗?

有人说在 32 位操作系统上一个 WORD 意味着 16 位,对吗?

Anyone has a definite answer?

Someone says that on 32 bit OS a WORD means 16bit,true?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

£噩梦荏苒 2024-10-29 02:22:08

“词”的概念有多种含义。问题中包含 3 个含义。

  • CPU 架构上下文中的通用术语“处理器字”
  • 软件/操作系统的“位大小”与硬件的“位大小”
  • 全大写术语 WORD,表示 16 位值- 这是 Windows“Win32”C 语言 API 的一部分

在描述 Win32 WORD 类型定义时,也会出现:

  • “Word”、“Doubleword”的 Intel/AMD 指令集概念和“四字”

CPU 架构上下文中的通用术语“处理器字”

在常见/通用用法中,“处理器字”是指处理器寄存器的大小。它还可以指 CPU 指令的大小或指针的大小(具体取决于具体的 CPU 架构)。在简单的情况下,32 位处理器将具有 32 位“字”大小(和指针大小)。 64 位处理器将具有 64 位“字”大小(和指针大小)。

一篇关于这个“处理器词”概念的维基百科文章,其中详细介绍了所有通用术语该术语的使用,以及几种当前和历史 CPU 架构的大小。

软件/操作系统的“位大小”与硬件的“位大小”

为了运行“64 位”软件,需要“64 位”CPU 和“64 位”操作系统。这可能是显而易见的。

“64位软件”使用64位指令(例如,将64位数字相加,或者同时将64位数据从处理器寄存器复制到RAM)。它还可以使用 64 位指针大小。这意味着它不再只能使用最多 4 GB 的 RAM(如“32 位软件”),而是理论上可以使用约 170 亿 GB 的 RAM(16 Exabytes)。

“64 位”x64/x86 CPU 也可以运行“32 位”(甚至“16 位”)软件。它可以做到这一点,无需对代码进行任何更改,也无需重建软件。这是因为所有旧的 CPU 指令仍然存在于新的 CPU 上,并且它们是向后兼容的。

这些概念与“处理器字”的通用概念并不严格相同,但密切相关。

注意:当您谈论较旧且更专业的处理器(尤其是较旧的视频游戏系统)时,这个概念开始变得稍微复杂一些,但问题并不是真正关于这些,所以我不会详细介绍。这些往往被称为“64 位”或“8 位”系统,但事实比这要复杂一些。请参阅我上面链接的“处理器词”wiki 文章,或有关特定处理器的文章有问题的系统。

问题的特定上下文 - WORD,全部大写

问题中的大小写和具体大小(在 32 位操作系统上,WORD 为 16 位)意味着与通用术语“处理器字”。

在传统的Windows编程(Win32 API)中,定义了一个名为WORD的宏,其大小为16位。当处理器为 16 位时,这是有意义的。但是,即使您为 32 位或 64 位目标编译包含此宏的代码,它仍然是 16 位。 Win32 API 中的 DWORD 为 32 位,QWORD 为 64 位。

这是因为 Microsoft 在其 Win32 API 中确实非常努力地支持向后兼容性,而无需对代码进行任何更改。大多数情况下,您可以编译 Windows 95 时代的 Win32 示例而无需进行任何更改,并且它们今天仍将以完全相同的方式工作。

微软很可能从英特尔(也可能是 AMD)文档中继承了这种命名方案。

Intel/AMD 指令集“字”、“双字”等概念

在 Intel 文档中,“字”(Win32 WORD) 是 16 位。 “双字”(Win32 DWORD)是 32 位。 “四字”(Win32 QWORD)是 64 位。相关的汇编指令名称也反映了这种命名方案(例如,MMX Add Packed Integers PADD 指令:PADDWPADDDPADDQ)。

对于一些示例,您可以查看这篇关于 x86 指令集的维基百科文章,或者英特尔软件开发手册

这种命名方案对于“处理器字”的一般概念来说不一定有意义,因为这些概念仅涉及寄存器的一部分。然而,它们在为 x86 程序创建稳定的编程接口方面确实有意义。这是您可以在“64 位”操作系统之上使用“32 位”(和 16 位)程序的一个重要原因。

The concept of a "word" has several meanings. There's 3 meanings embedded in the question.

  • The generic term "processor word", in context of CPU architectures
  • The "bit size" of software/OS, vs the "bit size" of hardware
  • The all-caps term WORD, meaning a 16 bit value - This is a part of the Windows "Win32" C language API

When describing the Win32 WORD type definition, this also comes up:

  • The Intel/AMD instruction set concept of a "Word", "Doubleword", and "Quadword"

The generic term "processor word", in context of CPU architectures

In common/generic usage, a "processor word" refers to the size of a processor register. It can also refer to the size of CPU instruction, or the size of a pointer (depending on which exact CPU architecture). In simple cases, a 32 bit processor will have a 32 bit "word" size (and pointer size). A 64 bit processor will have a 64 bit "word" size (and pointer size).

There is a wikipedia article on this "processor word" concept, which details all the generic uses of the term, and the sizes for several current and historical CPU architectures.

"Bit size" of software/OS vs the "bit size" of hardware

A "64 bit" CPU and a "64 bit" OS are necessary in order to run "64 bit" software. This much is probably obvious.

"64 bit software" uses 64 bit instructions (e.g. adding 64 bit numbers together, or copying 64 bits of data from a processor register to RAM at the same time). It also can use a 64 bit pointer size. This means that instead of only being able to use a maximum of 4 Gigabytes of RAM (like "32 bit software"), it can theoretically use about 17 Billion Gigabytes of RAM (16 Exabytes).

A "64 bit" x64/x86 CPU can also run "32 bit" (or even "16 bit") software. It can do this without any changes to the code, and without having to rebuild the software. This is because all the old CPU instructions still exist on new CPUs, and they are backwards compatible.

These concepts aren't strictly the same as the generic concept of a "processor word", but are closely related.

Note: This concept starts getting slightly more complicated when you talk about older and more specialized processors (especially older video game systems), but the question wasn't really about those so I won't go into detail. Those tend to be talked about as "64 bit" or "8 bit" systems, but the truth is a bit more complicated than that. See the "processor word" wiki article I linked above, or an article about the specific system in question.

The question's specific context - WORD, in all-caps

The capitalization and the specific sizes in the question (16 bit for WORD, on a 32 bit OS) imply something different than the generic term "processor word".

In legacy Windows programming (the Win32 API), there is a macro defined called WORD, the size of which is 16 bits. This made sense when processors were 16 bit. However, even when you compile code that contains this macro for a 32 bit or 64 bit target, it will still be 16 bits. A DWORD in the Win32 API is 32 bits, and a QWORD is 64 bits.

This is because Microsoft really tries very hard in their Win32 API to support backwards compatibility without having to do any changes to code. For the most part you can compile the Win32 samples from the Windows 95 era without changes, and they'll still work exactly the same way today.

Microsoft very likely inherited this naming scheme from Intel (and possibly AMD) documentation.

The Intel/AMD instruction set concept of a "Word", "Doubleword", etc

In Intel docs, a "Word" (Win32 WORD) is 16 bits. A "Doubleword" (Win32 DWORD) is 32 bits. A "Quadword" (Win32 QWORD) is 64 bits. The related assembly instruction names also reflect this naming scheme (e.g. MMX Add Packed Integers PADD instructions: PADDW, PADDD, PADDQ).

For some examples, you can check this wikipedia article on the x86 instruction set, or the Intel software development manuals.

This naming scheme doesn't necessarily make sense in terms of the general concept of a "processor word", since these concepts only address a part of a register. However they do make sense in terms of creating a stable programming interface for x86 programs. This is a big part of why you can use "32 bit" (and 16 bit) programs on top of a "64 bit" OS.

冰雪之触 2024-10-29 02:22:08

没有明确的答案。

传统上,术语“字”是指处理器寄存器和主数据路径的大小。根据该定义,“单词”在 32 位系统上为 32 位,在 64 位系统上为 64 位。

然而,当处理器系列扩展以添加更广泛的寄存器/操作模式时,这些处理器的制造商和用户有时继续使用“字”来指代原始处理器的字大小。当软件从一个处理器系列移植到另一个处理器系列时,也会发生同样的情况。

Intel x86 文档使用术语“字”1 来指代 16 位数量。这种用法渗透到最初为 x86 开发的软件环境中,例如 Windows API 和 Borland 风格的 pascal。

另一方面,arm 文档使用术语“字”² 来指代 32 位数量。

1 请参阅 https 中的第 4.1 节://software.intel.com/sites/default/files/management/a4/60/253665-sdm-vol-1.pdf

² 请参阅 https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf

There is no definitive answer.

Traditionally the term "word" refers to the size of the processor's registers and main data path. By that definition a "word" would be 32 bit on your 32-bit system and 64-bit on your 64-bit system.

However when processor families were extended to add wider registers/operating modes the manufacturers and users of those processors sometimes continued to use "word" to refer to the word size of the original processor. The same can happen when software is ported from one processor family to another.

Intel x86 documentation uses the term "word"¹ to refer to a 16 bit quantity. This usage bleeds over into software environments that were originally developed for x86 such as the windows API and Borland-style pascal.

On the other hand arm documentation uses the term "word"² to refer to a 32-bit quantity.

¹ see section 4.1 in https://software.intel.com/sites/default/files/managed/a4/60/253665-sdm-vol-1.pdf

² see section A1.4 in https://static.docs.arm.com/ddi0487/db/DDI0487D_b_armv8_arm.pdf

柏拉图鍀咏恒 2024-10-29 02:22:08

一个字是 16 位的大小,双字(双字)是编程中使用的 32 位字大小的两倍,但是......

操作系统中的名称字是操作系统旁边显示的数字,所以如果它说 64 位一在这种情况下,字(storege的地址)是64位的,

所以这取决于你从编程或操作系统编号的角度来看它

One Word is the size of 16 bit DWord(double word) is double the size of word that is 32 bit when used in programing but...

The name Word in OS is the number shown nexto the OS so if it's saying 64 bit one word (adres for storege) is 64 bit's in this case

So it depends from what angle your looking at it from programing or the OS number

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文