注意:本文经过原作者授权转译,转载请标明出处
原文地址:http://mrjester.hapisan.com/04_MC68/Sect01Part02/Index.html
条件允许建议阅读原文,网上非中文资料还是较多,当作锻炼英文岂不美哉
翻译若有不足之处欢迎批评指正
译文:
"如果有什么榨干了你,它一定是硬件" ---- 未知作者
简介
到目前为止,你应该对数据和不同的数据长度有了一定的基本概念,这里我们将康康数据到底存储在什么地方,以及它们是怎么被存储的
使用"偏移量" 来访问数据
计算机使用一种特殊的访问数据的方式,通过编址
(addressing)
偏移量 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
00000000 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000010 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000020 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000030 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
... |
上面这个表格是数据存储的一个例子,除了第一列和第一行之外的那些00
就是数据
(data) (即你的内存),第一列和第一行的粗体数字就是偏移量
计算机会使用偏移量
来作为地址
(address),来定位内存中的它想要读取或者写入的某个字节
。比如在下面这张表中,你会发现除了有一个例外,其他内存中的字节
都是00
:
偏移量 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
00000000 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000010 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000020 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | F2 | 00 | 00 | 00 | 00 |
00000030 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
... |
在B
这一列的00000020
行处的字节
是F2
,如果一台计算机想要读取这个字节
,它将会用0000002B
来作为寻找所用的偏移量
,很简单吧?
那么让我们再康康更多的例子,比如下面这个在偏移量
00000013
的位置:
偏移量 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
00000000 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000010 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000020 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000030 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
... |
如你所见在上面的表格里我们把00000010
行的3
列高亮了,以后所操作的偏移量
我们都会高亮显示,现在让我们尝试把字
20 4F
写到0000000A
的位置:
偏移量 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
00000000 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 20 | 4F | 00 | 00 | 00 | 00 |
00000010 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000020 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000030 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
... |
你会发现,字
20 4F
被分开了,20
被放到了0000000A
处,而4F
则被放到了0000000B
处
如果我们尝试从下面的内存的00000034
处读取一个长字
:
偏移量 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
00000000 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000010 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000020 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
00000030 | 00 | 00 | 00 | 00 | F3 | 44 | F5 | 39 | C2 | 00 | 00 | 00 | 00 | 00 | 00 | 00 |
... |
可以看到字节
F3
,44
,F5
和39
被高亮了,读取到的长字
就是F3 44 F5 39
,所以计算机不只是读取了00000034
处的字节
,它连着00000035
,00000036
和00000037
都读取了,然后把它们拼在一起组成了一个长字
之后我们会更加详细和深入的讨论内存相关的话题,希望到现在为止你已经有了一些基本的认识
目录
上一篇:[转译][马基 杰斯特(MarkeyJester) 摩托罗拉68000 入门教程] 壹 - 基础介绍 | 1. 计算机内存
下一篇:[转译][马基 杰斯特(MarkeyJester) 摩托罗拉68000 入门教程] 壹 - 基础介绍 | 3. 指令集
[转译][马基 杰斯特(MarkeyJester) 摩托罗拉68000 入门教程] 壹 - 基础介绍 | 2. 内存存储