Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 90|回复: 0

计算机的制作(七)-拆掉软件和硬件之间的墙

[复制链接]

1万

主题

1万

帖子

5万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
58026
发表于 2020-10-20 11:41:13 | 显示全部楼层 |阅读模式

                    

                    

                    
                    
                    <p><strong style="font-size: 20px;white-space: normal;"><img class="" data-ratio="0.42710120068610635" src="http://mmbiz.qpic.cn/mmbiz_jpg/LKgI6UN8ElafygecA4sIudtYiaWboKoIWIwFaec2qHuNFznNFwxJsFcgelgficzvZibFnwWZcVict9QGBiasmaPbVDQ/640?wx_fmt=jpeg" data-type="jpeg" data-w="583"  /></strong></p><p><strong style="font-size: 20px;white-space: normal;"><strong style="white-space: normal;"><span style="font-size: 20px;"><strong>本节内容的基础请参考</strong></span></strong></strong><strong><span style="color: rgb(255, 76, 0);">计算机的制作(六)-基于Z80处理器制作微型计算机</span></strong></p><p><br  /></p><p><span style="font-size: 20px;"><strong>一、什么是机器语言?</strong></span></p><p><strong><span style="color: rgb(0, 209, 0);">机器语言</span></strong><span style="color: rgb(0, 209, 0);">:由二进制构成的程序,CPU可以直接对其解释、执行。</span></p><p><span style="color: rgb(0, 209, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: rgb(255, 76, 0);">每种CPU有其相对应的机器语言。</span></p><p><br  /></p><p><span style="color: rgb(0, 209, 0);">使用汇编语言、C语言、Java、BASIC等编程语言编写的程序,也都需要先转换成机器语言才能被执行。</span></p><p><br  /></p><p><span style="color: rgb(0, 209, 0);">这个转换过程一般是由相应的软件和硬件共同来完成。</span></p><p><span style="color: rgb(0, 209, 0);">但是,这个过程是如何实现的呢?</span></p><p><span style="color: rgb(0, 209, 0);">下文将介绍这个过程。</span></p><p><br  /></p><p><span style="color: rgb(0, 209, 0);text-decoration: underline;">我们硬件使用的是Z80微处理器,软件使用汇编语言编写。</span></p><p><br  /></p><p><br  /></p><p><strong><span style="font-size: 20px;">二、从程序员的角度看硬件</span></strong></p><p><span style="color: rgb(120, 172, 254);"><strong>程序员只要了解以下7点:</strong></span></p><p><span style="color: rgb(120, 172, 254);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CPU的种类</span></p><p><span style="color: rgb(120, 172, 254);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;时钟信号的频率</span></p><p><span style="color: rgb(120, 172, 254);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 内存地址空间</span></p><p><span style="color: rgb(120, 172, 254);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 内存中每个地址中可以存储多少比特的信息</span></p><p><span style="color: rgb(120, 172, 254);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I/O芯片中的I/O种类<br  /></span></p><p><span style="color: rgb(120, 172, 254);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I/O芯片中的地址空间</span></p><p><span style="color: rgb(120, 172, 254);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I/O芯片连接着哪些周边设备</span></p><p style="text-align: center;"><img class="" data-ratio="0.6702786377708978" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElZ07Q2FTpwtE89w9P5icres2icJkZtmxnL026bM5dicKJd9qmbeB2mmUnszodgjiahmQvbJa9BXBFjWdQ/640?wx_fmt=png" data-type="png" data-w="646" style=""  /></p><p><span style="color: rgb(120, 172, 254);"></span><br  /></p><p><strong><span style="font-size: 20px;">三、机器语言和汇编语言</span></strong></p><p><span style="color: rgb(0, 209, 0);">下表中的地址对应的程序就是机器语言,该段程序功能是把由指拨开关输入的数据输入CPU,然后CPU再把这些数据原封不动地输出到LED。即可以通过拨动指拨开关控制LED的亮灭。</span></p><p><img class="" data-ratio="1.2803347280334727" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElafygecA4sIudtYiaWboKoIW9tcKODvDTAP2ibVAWNdCV6iaqnufO9yu4wT4fibV6JMAHDuW7tkzRrscA/640?wx_fmt=png" data-type="png" data-w="239" style="height: 300px;white-space: normal;width: 236px;"  /></p><p><img class="" data-ratio="0.9531914893617022" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElafygecA4sIudtYiaWboKoIWLxjhv47AiblUUGjJoWZOAklHEDHFSS7Vnrnjf7N7hCshgKxDiccbWALg/640?wx_fmt=png" data-type="png" data-w="235" style="white-space: normal;"  /></p><p><br  /></p><p><span style="color: rgb(0, 209, 0);">对于人来说,根本看不懂这些0和1要表达什么意思!</span></p><p><strong><span style="color: rgb(0, 209, 0);">于是就有人发明了一种编程方法:</span></strong></p><p><span style="color: rgb(0, 209, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 1、根据表示指令功能的英语单词起一个相似的昵称;</span></p><p><span style="color: rgb(0, 209, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 2、并将这个昵称赋予给0和1的组合。</span></p><p><span style="color: rgb(0, 209, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这种类似英文单词的昵称称为“助记符”</span></p><p><span style="color: rgb(0, 209, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使用“助记符”的编程语言叫做“汇编语言”</span></p><p><span style="color: rgb(0, 209, 0);"><br  /></span></p><p><span style="color: rgb(0, 209, 0);">无论使用机器语言还是编程语言,所实现的功能都是一样的,</span></p><p><span style="color: rgb(0, 209, 0);">区别只在于程序是数字表示,还是用助记符表示。</span></p><p><span style="color: rgb(0, 209, 0);"><br  /></span></p><p><span style="color: rgb(0, 209, 0);">这样如果理解了编程语言,也就理解了机器语言,</span></p><p><span style="color: rgb(0, 209, 0);">更进一步也就理解了计算机的原始硬件工作过程。</span></p><p><span style="color: rgb(0, 209, 0);"><br  /></span></p><p><span style="color: rgb(0, 209, 0);">上表中的机器语言程序可以转换成下表所示的汇编语言程序。</span></p><p><img class="" data-ratio="0.6568627450980392" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElZ07Q2FTpwtE89w9P5icres2pxfrlibh9ZA7fdTTR4qcyHPnVkQ4oD9twgF46ibtsB2pO6ZdcKp2IvGA/640?wx_fmt=png" data-type="png" data-w="408"  /><br  /></p><p><span style="color: rgb(0, 209, 0);"></span></p><p style="white-space: normal;"><span style="color: rgb(0, 209, 0);">标签作用是:为该行对应的内存地址起一个名字,便于快速操作该内存地址。</span></p><p><span style="color: rgb(0, 209, 0);">操作码作用是:表示“做什么”的指令。</span></p><p><span style="color: rgb(0, 209, 0);">操作数作用是:指令执行的对象。</span></p><p><span style="color: rgb(0, 209, 0);"><br  /></span></p><p><span style="color: rgb(0, 0, 0);font-size: 20px;"><strong>四、汇编语言与机器语言对应过程</strong></span></p><p><span style="color: rgb(120, 172, 254);">用汇编语言编写的程序是不能直接运行的,必须先转换成机器语言。</span></p><p><span style="color: rgb(120, 172, 254);">机器语言是唯一一种CPU能直接理解的编程语言。</span></p><p><br  /></p><p><span style="color: rgb(120, 172, 254);">1条汇编语言的指令对应由1个或多个字节所构成的机器语言。</span></p><p><span style="color: rgb(120, 172, 254);">如下表所示,1条汇编语言的指令对应由2个或3个字节所构成的机器语言。</span></p><p style="text-align: center;"><img class="" data-ratio="0.41770186335403725" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElZ07Q2FTpwtE89w9P5icres2xZhkPficCTINlHicNVpn7AhR3Nibakt20loZlA1iczb7hkKm2Ppbvgo0iaQ/640?wx_fmt=png" data-type="png" data-w="644" style=""  /></p><p><span style="color: rgb(120, 172, 254);">1、如上表所示,一旦重置CPU,00000000就会被自动存储到PC寄存器中。</span></p><p><span style="color: rgb(120, 172, 254);">2、重置CPU后,CPU会从00000000号地址读出指令00111110,</span></p><p><span style="color: rgb(120, 172, 254);">判断出这是一条由2个字节构成的指令,</span></p><p><span style="color: rgb(120, 172, 254);">于是接下来会从下一个00000001号地址读出数据11001111,</span></p><p><span style="color: rgb(120, 172, 254);">把这两个字节的数据汇集到一起解释、执行。</span></p><p><span style="color: rgb(120, 172, 254);">执行的指令是把数值207写入到寄存器A,</span></p><p><span style="color: rgb(120, 172, 254);">用汇编语言表示就是LD A, 207</span></p><p><span style="color: rgb(120, 172, 254);">3、由于刚从内存中读出了一条2字节的指令,所以PC寄存器的值增加2。</span></p><p><span style="color: rgb(120, 172, 254);">4、接下来,通过反复进行“读取指令”、“解释、执行指令”、“更新PC寄存器的值”这3个操作,程序就运行起来了。</span></p><p><span style="color: rgb(120, 172, 254);">5、一旦执行完最后一行的JP LOOP所对应的机器语言,PC寄存器的值就会被设为标签LOOP对应的地址00010000,这样就可以循环执行同样的操作。</span></p><p><span style="color: rgb(120, 172, 254);"><br  /></span></p><p><span style="font-size: 20px;color: rgb(0, 0, 0);"><strong>五、汇编语言转换为机器语言</strong></span></p><p><span style="color: rgb(0, 209, 0);">在CPU的资料中,明确写有可以使用的助记符,以及助记符转换成机器语言后的数值。</span></p><p><span style="color: rgb(0, 209, 0);">只要查看这些资料,就可以把汇编语言编写的程序手工转换成机器语言的程序。</span></p><p><span style="color: rgb(0, 209, 0);">进行手工汇编时,要一行一行地把用汇编语言编写的程序转换成机器语言。</span></p><p><br  /></p><p><span style="color: rgb(0, 209, 0);">如下表所示,列出了汇编语言中必要指令的助记符、助记符所对应的机器语言,以及执行这些机器语言所需的时钟周期。</span></p><p style="text-align: center;"><img class="" data-ratio="0.22913256955810146" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElZ07Q2FTpwtE89w9P5icres27RXic9qCbpjGojFDvqBDiaTMvE8MK3ScVviabE12QiaetPT4uE1m2zIg8A/640?wx_fmt=png" data-type="png" data-w="611" style=""  /></p><p><span style="color: rgb(120, 172, 254);font-size: 20px;"></span></p><p style="text-align: left;"><br  /></p><p style="text-align: left;"><span style="color: rgb(0, 209, 0);">通过查询Z80 CPU芯片的资料,将汇编语言转换成了如下表所对应的机器语言:</span></p><p style="text-align: left;"><img class="" data-ratio="0.15265486725663716" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElZ07Q2FTpwtE89w9P5icres29GVZmJKquaJdmgFYer2qUIZXGHbM4rFfnONI2FicnibgCdIYje0CicB8g/640?wx_fmt=png" data-type="png" data-w="452" style="width: 356px;height: 54px;"  /></p><p style="text-align: left;"><span style="color: rgb(0, 209, 0);"></span></p><p style="text-align: left;"><img class="" data-ratio="0.078125" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElZ07Q2FTpwtE89w9P5icres2FmdDKUhpY6E9lC9SoXS64qeTpLAC0qmzzBlibellGHgDTU1Bq6Ep9rg/640?wx_fmt=png" data-type="png" data-w="448" style="width: 356px;height: 28px;"  /></p><p style="text-align: left;"><img class="" data-ratio="0.45964125560538116" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElZ07Q2FTpwtE89w9P5icres2rqIicbOkzN7tPyzEmbMtkf8zUJyz3kdfSYazGTVn9D1NAFGVk6secUw/640?wx_fmt=png" data-type="png" data-w="446" style="width: 355px;height: 163px;"  /></p><p style="text-align: left;"><img class="" data-ratio="0.16179775280898875" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElZ07Q2FTpwtE89w9P5icres2Hibh9ZD8KzX7aj3wMofCbwCZqeW4qK7EsULsppMTtniadH2gMcMHGpKA/640?wx_fmt=png" data-type="png" data-w="445" style="width: 356px;height: 58px;"  /></p><p style="text-align: left;"><img class="" data-ratio="0.08022388059701492" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_png/LKgI6UN8ElZ07Q2FTpwtE89w9P5icres2N146kICicAa4d3uD7CH1EdCSOhqRLuLWHBV3qcibUgmQpb12Hh4fibdDw/640?wx_fmt=png" data-type="png" data-w="536" style="width: 429px;height: 35px;"  /></p><p style="white-space: normal;"><span style="color: rgb(0, 209, 0);"><br  /></span></p><p><span style="font-size: 20px;"><strong>六、结论</strong></span></p><p style="white-space: normal;"><span style="color: rgb(120, 172, 254);">使用汇编语言、C语言、Java、BASIC等编程语言编写的程序,也都需要先转换成机器语言才能被执行。</span></p><p style="white-space: normal;"><span style="color: rgb(120, 172, 254);">这个转换过程一般是由相应的软件和硬件共同来完成的。</span></p><p style="white-space: normal;"><span style="color: rgb(120, 172, 254);">1、这里的软件可以使人能看懂程序,</span></p><p style="white-space: normal;"><span style="color: rgb(120, 172, 254);">2、然后将编程语言编译转换成二进制机器语言,即通过查表的方式将编程语言程序一行一行地转换成对应表的二进制语言程序。</span></p><p style="white-space: normal;"><span style="color: rgb(120, 172, 254);">3、最后就用特制硬件电路将机器语言程序下载到内存中。</span></p><p style="white-space: normal;"><span style="color: rgb(120, 172, 254);">4、CPU从内存中<span style="color: rgb(120, 172, 254);">反复进行“读取指令”、“解释、执行指令”、“更新PC寄存器的值”这3个操作,程序就运行起来了,硬件也开始工作了。</span></span></p><p style="white-space: normal;"><span style="color: rgb(120, 172, 254);">这样,就实现了软硬件的连接。</span></p><hr style="font-size: 16px;white-space: normal;max-width: 100%;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"  /><hr style="font-size: 16px;white-space: normal;max-width: 100%;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"  /><hr style="font-size: 16px;white-space: normal;max-width: 100%;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"  /><hr style="font-size: 16px;white-space: normal;max-width: 100%;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"  /><hr style="font-size: 16px;white-space: normal;max-width: 100%;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"  /><hr style="font-size: 16px;white-space: normal;max-width: 100%;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"  /><hr style="font-size: 16px;white-space: normal;max-width: 100%;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"  /><hr style="font-size: 16px;white-space: normal;max-width: 100%;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"  /><hr style="font-size: 16px;white-space: normal;max-width: 100%;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"  /><hr style="font-size: 16px;white-space: normal;max-width: 100%;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"  /><p style="font-size: 16px;white-space: normal;max-width: 100%;min-height: 1em;color: rgb(62, 62, 62);background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 25.6px;color: rgb(0, 128, 255);box-sizing: border-box !important;word-wrap: break-word !important;">请扫描下面二维码,关注该微信公众号,获取更多</span><span style="max-width: 100%;line-height: 25.6px;color: rgb(255, 41, 65);box-sizing: border-box !important;word-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;">生物医学工程</strong>专业及<strong style="max-width: 100%;box-sizing: border-box !important;word-wrap: break-word !important;">医工</strong><span style="max-width: 100%;line-height: 25.6px;color: rgb(0, 128, 255);">学习笔记</span></span><span style="max-width: 100%;color: rgb(0, 0, 0);box-sizing: border-box !important;word-wrap: break-word !important;"></span></p><p style="font-size: 16px;white-space: normal;max-width: 100%;min-height: 1em;color: rgb(62, 62, 62);line-height: 25.6px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"><span style="max-width: 100%;line-height: 25.6px;color: rgb(255, 41, 65);box-sizing: border-box !important;word-wrap: break-word !important;"></span></p><p style="font-size: 16px;white-space: normal;max-width: 100%;min-height: 1em;color: rgb(62, 62, 62);line-height: 25.6px;text-align: center;background-color: rgb(255, 255, 255);box-sizing: border-box !important;word-wrap: break-word !important;"><img class="" data-ratio="1" data-s="300,640" src="http://mmbiz.qpic.cn/mmbiz_jpg/LKgI6UN8ElZnh0jXF3PjbBz7BBPnYH7wbDgfc3E2r7REMuN2lQqfuVM38HZO8Zx0rN0OLKywrjoH3P7QqDY44Q/640?wx_fmt=jpeg" data-type="jpeg" data-w="430" width="auto" style="box-sizing: border-box !important;word-wrap: break-word !important;visibility: visible !important;width: auto !important;"  /></p><p style="white-space: normal;"><span style="color: rgb(255, 41, 65);font-size: 16px;background-color: rgb(255, 255, 255);">笔记内容来自《计算机是怎么跑起来的》</span></p><p><br  /></p>
               
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Comsenz Inc. ( 浙ICP备17000336号-1 )

GMT+8, 2025-3-11 04:12 , Processed in 0.123035 second(s), 33 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表