版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of MicrocomputersChapter TwoChapter TwoData Numbering and Character Encoding Data Numbering and Character Encoding System in Microcomputer System in Microcomputer 计算机中的数制和编码计算机中的数制和编码3 3Chapter Two Data Numbering &
2、amp; Character Encoding System in MicrocomputerPrinciples of Microcomputers2.3 信信 息息 的的 编编 码码 Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of MicrocomputersChapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers
3、 4位二进制数码有16种组合(00001111),原那么上可任选其中的10个来分别代表十进制中09这10个数字。但为了便于记忆,最常用的是8421 BCD码,这种编码从00001111这16种组合中选择前10个即00001001来分别代表十进制数码09,8、4、2、1分别是这种编码从高位到低位每位的权值。BCD码有两种方式,即紧缩型BCD码和非紧缩型BCD码。 Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of MicrocomputersChapter Two Dat
4、a Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers表表2.2 8421 BCD 码部分编码表码部分编码表 十进制数紧缩型BCD码非紧缩型BCD码12391011192021000000010000001000000011000010010001000000010001000110010010000000100001000000010000001000000011 0000100100000001 0000000000000001 00000001 00000001 00
5、00100100000010 0000000000000010 00000001Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers 需求阐明的是,虽然BCD码可以简化人机联络,但它比纯二进制编码效率低,对同一个给定的十进制数,用BCD码表示时需求的位数比用纯二进制码多,而且用BCD码进展运算所花的时间也要更多,计算过程更复杂,由于BCD码是将每个十进制数用一组4位二进制数来表示,假设将这种BCD码送计算机进展运算,由于计算机总是将数当作二进
6、制数来运算,所以结果能够出错,因此需求对计算结果进展必要的修正,才干使结果为正确的BCD码方式。详见本小节例2.17。 Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers例2.15 十进制数与BCD数相互转换。 将十进制数69.81转换为紧缩型BCD数: 69.81=(0110 1001.1000 0001)BCD 将BCD数1000 1001.0110 1001转换为十进制数:(1000 1001.0110 1001)BCD=89.69
7、Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers 例2.16 设有变量x等于10010110B,当该变量分别为无符号数、原码、补码、紧缩型BCD码时,试分别计算变量x所代表的数值大小。解 无符号数:x=10010110B=127+026+025+124+023+122+121+020=150原码:x原=10010110B x= -026+025+124+023+122+121+020= -22补码:x补=10010110B x原=x补补=
8、11101010B x= -126+125+024+123+022+121+020= -106 BCD码:xBCD=10010110B x=96Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers 例2.17 (BCD码运算时的修正问题)用BCD码求38+49。 解 0011 1000 38的BCD码+) 0100 1001 49的BCD码 1000 0001 81的BCD码 计算结果1000 0001是81的BCD数,而正确结果应为87的B
9、CD数1000 0111,因此结果是错误的。其缘由是,十进制数相加应该是“逢十进一,而计算机按二进制数运算,每4位为一组,低4位向高4位进位与十六进制数低位向高位进位的情况相当,是“逢十六进一,所以当相加结果超越9时将比正确结果少6,因此结果出错。处理方法是对二进制加法运算结果采用“加6修正,从而将二进制加法运算的结果修正为BCD码加法运算结果。Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers BCD数相加时,对二进制加法运算结果修正的规
10、那么如下: 假设两个对应位BCD数相加的结果向高位无进位,且结果小于或等于9,那么该位不需求修正;假设得到的结果大于9而小于16,那么该位需求加6修正。 假设两个对应位BCD数相加的结果向高位有进位(结果大于或等于16),那么该位需求进展加6修正。 因此,两个BCD数进展运算时,首先按二进制数进展运算,然后必需用相应的调整指令进展调整,从而得到正确的BCD码结果。有关BCD运算结果的调整指令将在第4章“80 x86指令系统中引见。 Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrincip
11、les of Microcomputers2.4 数的定点与浮点表示法数的定点与浮点表示法 符号位数值位小数点(a)符号位数值位小数点(b)图2.1 定点数的两种表示方法(a) 纯小数方式;(b) 纯整数方式 Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers 设用一个n+1位字来表示一个数x,其中一位表示符号位(0表示正,1表示负),其他n位为数值位。对于纯小数表示法,所能表示的数x (原码表示,下同)的范围为:-(1-2-n)x1-2-
12、n (2.4.1) 它能表示的数的最大绝对值为1-2-n,最小绝对值为2-n。 对于纯整数表示法,所能表示的数x的范围为:-(2n-1)x2n -1 (2.4.2)它能表示的数的最大绝对值为2n-1,最小绝对值为1。 Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers2.4.2 浮点表示浮点表示 所谓浮点表示法,就是小数点在数中的位置是浮动的。所谓浮点表示法,就是小数点在数中的位置是浮动的。 恣意一个二进制数恣意一个二进制数x总可以写成如下
13、方式:总可以写成如下方式: (2.4.3)其中,其中,d称为尾数,是二进制纯小数,指明数的全部有效数字,前称为尾数,是二进制纯小数,指明数的全部有效数字,前面的符号称为数符,表示数的符号,该位为面的符号称为数符,表示数的符号,该位为0,阐明该浮点数为正,阐明该浮点数为正,该位为该位为1,阐明该浮点数为负;,阐明该浮点数为负;p称为阶码,它前面的符号称为阶符,称为阶码,它前面的符号称为阶符,阶码为正时,用阶码为正时,用0表示,阶码为负时,用表示,阶码为负时,用1表示。表示。 阶符阶码(p)数符尾数d1 位m位1位n位Chapter Two Data Numbering & Charact
14、er Encoding System in MicrocomputerPrinciples of Microcomputers 可以看出,将尾数d的小数点向右(阶码p为正时)或向左(阶码p为负时)挪动p位,即可得到该浮点数表示的数值x。阶码p指明小数点的位置,小数点随着阶码的大小和正负而浮动,因此把这种数称为浮点数。 设阶码的位数为m位,尾数的位数为n位,那么该浮点数表示的数值范围为:(2.4.4) 在字长一样的情况下,浮点数能表示的数值范围比定点数大得多,且精度高,但浮点运算规那么复杂。)12()12(2)21 (|22mmnnxChapter Two Data Numbering &
15、; Character Encoding System in MicrocomputerPrinciples of MicrocomputersSummarySummary Most modern computer systems use the binary numbering system to represent values. Since binary values are somewhat unwieldy, well often use the hexadecimal representation in our assembly programs.A single hexadeci
16、mal digit consumes four binary digits (bits), and we call a group of four bits a nibble. The 80 x86 works best with groups of bits which are eight, 16, or 32 bits long. We call objects of these sizes bytes, words, and double words, respectively. In order to talk about specific bits within a nibble,
17、byte, word, double word, or other structure, well number the bits starting at zero (for the least significant bit) on up to n-1(where n is the number of bits in the object)Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of MicrocomputersSummarySummary There are
18、many operations we can perform on binary values including normal arithmetic (+, -, *, and /) and the logical operations (AND, OR, XOR, NOT, Shift Left, Shift Right, Rotate Left, and Rotate Right). Logical AND, OR, XOR, and NOT are typically defined for single bit operations. We can extend these to n
19、 bits by performing bitwise operations. The shifts and rotates are always defined for a fixed length string of bits. There are two types of integer values which we can represent with binary strings on the 80 x86: unsigned integers and signed integers. The 80 x86 represents unsigned integers using th
20、e standard binary format. It represents signed integers using the twos complement format. Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of MicrocomputersSummarySummary Character data is probably the most common data type encountered besides integer values. The
21、 IBM PC and compatibles use a variant of the ASCII character set the extended IBM/ASCII character set. The first 128 of these characters are the standard ASCII characters, 128 are special characters created by IBM for international languages, mathematics, and line drawing. Since the use of the ASCII
22、 character set is so common in modern programs, familiarity with this character set is essential.Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers Questions Questions1) Convert the following decimal values to binary:a) 128 b) 4096c) 256 d) 65536
23、e) 254 f) 8882) Convert the following binary values to decimal:a) 1001 1001 b) 1001 1101c) 1100 0011d) 0000 1001 e)1111 1110Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of MicrocomputersQuestionsQuestions3) Convert the binary values in problem 2 to hexadecima
24、l.4) Convert the following hexadecimal values to binary:a) 0ABCD b) 1024 c) 0DEAD d) 0ADD e) 0BEEFPerform the following hex computations (leave the result in hex):5) 1234 +98766) 0FFF - 0F347) 100 - 18) 0FFE - 19) What is the importance of a nibble?10) How many hexadecimal digits in:a) a byte b) a w
25、ord c) a double wordChapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of MicrocomputersQuestionsQuestions11) How many bits in a:a) nibble b) byte c) word d) double word12) Which bit (number) is the H.O. bit in a:a) nibble b) byte c) word d) double word13) What cha
26、racter do we use as a suffix for hexadecimal numbers? Binary numbers? Decimalnumbers?14) Assuming a 16-bit twos complement format, determine which of the values in question 4 are positive and which are negative.15) Sign extend all of the values in question two to sixteen bits. Provide your answer in
27、 hex.Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of MicrocomputersQuestionsQuestions16) Perform the bitwise AND operation on the following pairs of hexadecimal values. Present your answer in hex. (Hint: convert hex values to binary, do the operation, then co
28、nvert back to hex).a) 0FF00, 0FF0 b) 0F00F, 1234 c) 4321, 1234 d) 2341, 3241 e) 0FFFF, 0EDCB17) Perform the logical OR operation on the above pairs of numbers.18) Perform the logical XOR operation on the above pairs of numbers.19) Perform the logical NOT operation on all the values in question four.
29、 Assume all values are 16 bits.Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of MicrocomputersQuestionsQuestions20) Perform the twos complement operation on all the values in question four. Assume 16 bit values.21) Sign extend the following hexadecimal values
30、from eight to sixteen bits. Present your answer in hex.a) FF b) 82 c) 12 d) 56 e) 98f) BF g) 0F h) 78 i) 7F j) F722) Sign contract the following values from sixteen bits to eight bits. If you cannot perform the operation, explain why.a) FF00 b) FF12 c) FFF0 d) 12 e) 80f) FFFF g) FF88 h) FF7F i) 7F j
31、) 223) Sign extend the 16-bit values in question 22 to 32 bits.24) Assuming the values in question 22 are 16-bit values, perform the left shift operation on them.25) Assuming the values in question 22 are 16-bit values, perform the right shift operation on them.Chapter Two Data Numbering & Chara
32、cter Encoding System in MicrocomputerPrinciples of MicrocomputersQuestionsQuestions26) Assuming the values in question 22 are 16-bit values, perform the rotate left operation on them.27) Assuming the values in question 22 are 16-bit values, perform the rotate right operation on them.28) Convert the
33、following dates to the packed format described in this chapter (see “Bit Fields and Packed Data on page 28). Present your values as a 16-bit hex number.a) 1/1/92 b) 2/4/56 c) 6/19/60 d) 6/16/86 e) 1/1/9929) Describe how to use the shift and logical operations to extract the day field from thepacked
34、date record in question 28. That is, wind up with a 16-bit integer value in the range 0.31.30) Suppose you have a value in the range 0.9. Explain how you could convert it to an ASCII character using the basic logical operations.Chapter Two Data Numbering & Character Encoding System in MicrocomputerPrinciples of Microcomputers本章作业本章作业1. Convert the following decimal values to binary: a) 128 b) 4096 c) 256 d) 655362. Convert the following binary values to decimal: a) 1001 1001 b) 1001 11013. Convert the following hexadecimal values to binary: a) 0ABC
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 铁通考试题及答案
- 变电站直流系统故障应急预案演练脚本
- 酿酒厂发酵工艺操作规范
- 电器公司产品研发准则
- 供应链战略合作合同
- 幽门螺杆菌治疗现状
- 中医学基础:六腑
- 湿疹的预防和治疗
- 人教部编版五年级语文上册期中考试卷()
- 第一单元测试卷2026-2027学年统编版八年级下册历史
- 测绘安全生产指南讲解
- 2026年乡村全科执业助理医师试题及答案
- 6 - 12月龄宝宝辅食培训【课件文档】
- 2025年厦门大学生命科学学院工程系列专业技术中初级职务人员招聘备考题库及答案详解一套
- 2026年党的廉政知识测试题及答案
- 2026年及未来5年市场数据中国财务公司行业市场发展数据监测及投资潜力预测报告
- 企业与高校双聘协议书
- 腕表鉴定课件
- 悬臂式挡土墙施工技术交底方案
- TBCRHA-连续性肾脏替代治疗局部枸橼酸抗凝护理规范
- 2024-2025学年高中数学 第3章 数系的扩充与复数的引入 3.1 数系的扩充和复数的概念 3.1.2 复数的几何意义(教师用书)说课稿 新人教A版选修2-2
评论
0/150
提交评论