版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
ChapterTwo
DataNumberingandCharacterEncodingSysteminMicrocomputer
计算机中的数制和编码
(3)Thursday,January12,2023
12.3信息的编码2.3.1二进制编码的十进制数(BCD编码)
BinaryCodedDecimalsequenceofnybblesrepresentingdigits0-9ofthenumberThursday,January12,2023
2Thursday,January12,2023
3
4位二进制数码有16种组合(00001111),原则上可任选其中的10个来分别代表十进制中09这10个数字。但为了便于记忆,最常用的是8421BCD码,这种编码从00001111这16种组合中选择前10个即00001001来分别代表十进制数码09,8、4、2、1分别是这种编码从高位到低位每位的权值。BCD码有两种形式,即压缩型BCD码和非压缩型BCD码。Thursday,January12,2023
4
1.压缩型BCD码压缩型BCD码用一个字节表示两位十进制数。例如,10000110B表示十进制数86。
2.非压缩型BCD码非压缩型BCD码用一个字节表示一位十进制数。高4位总是0000,低4位用00001001中的一种组合来表示09中的某一个十进制数。Thursday,January12,2023
5表2.28421BCD码部分编码表十进制数压缩型BCD码非压缩型BCD码12391011192021000000010000001000000011000010010001000000010001000110010010000000100001000000010000001000000011
0000100100000001000000000000000100000001
000000010000100100000010000000000000001000000001Thursday,January12,2023
6需要说明的是,虽然BCD码可以简化人机联系,但它比纯二进制编码效率低,对同一个给定的十进制数,用BCD码表示时需要的位数比用纯二进制码多,而且用BCD码进行运算所花的时间也要更多,计算过程更复杂,因为BCD码是将每个十进制数用一组4位二进制数来表示,若将这种BCD码送计算机进行运算,由于计算机总是将数当作二进制数来运算,所以结果可能出错,因此需要对计算结果进行必要的修正,才能使结果为正确的BCD码形式。详见本小节例2.17。
Thursday,January12,2023
7例2.15
十进制数与BCD数相互转换。①将十进制数69.81转换为压缩型BCD数:
69.81=(01101001.10000001)BCD②将BCD数10001001.01101001转换为十进制数:
(10001001.01101001)BCD=89.69Thursday,January12,2023
8例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]补]补=11101010B
x=-126+125+024+123+022+121+020=-106BCD码: [x]BCD=10010110B
x=96Thursday,January12,2023
9例2.17(BCD码运算时的修正问题)用BCD码求38+49。解
0011100038的BCD码+)0100100149的BCD码
1000000181的BCD码计算结果10000001是81的BCD数,而正确结果应为87的BCD数10000111,因此结果是错误的。其原因是,十进制数相加应该是“逢十进一”,而计算机按二进制数运算,每4位为一组,低4位向高4位进位与十六进制数低位向高位进位的情况相当,是“逢十六进一”,所以当相加结果超过9时将比正确结果少6,因此结果出错。解决办法是对二进制加法运算结果采用“加6修正”,从而将二进制加法运算的结果修正为BCD码加法运算结果。Thursday,January12,2023
10
BCD数相加时,对二进制加法运算结果修正的规则如下:
①如果两个对应位BCD数相加的结果向高位无进位,且结果小于或等于9,则该位不需要修正;若得到的结果大于9而小于16,则该位需要加6修正。②如果两个对应位BCD数相加的结果向高位有进位(结果大于或等于16),则该位需要进行加6修正。因此,两个BCD数进行运算时,首先按二进制数进行运算,然后必须用相应的调整指令进行调整,从而得到正确的BCD码结果。有关BCD运算结果的调整指令将在第4章“80x86指令系统”中介绍。Thursday,January12,2023
112.4数的定点与浮点表示法2.4.1定点表示所谓定点表示法,是指小数点在数中的位置是固定的。原理上讲,小数点的位置固定在哪一位都是可以的,但通常将数据表示成纯小数或纯整数形式,如图2.1所示。图2.1定点数的两种表示方法(a)纯小数形式;(b)纯整数形式Thursday,January12,2023
12设用一个n+1位字来表示一个数x,其中一位表示符号位(0表示正,1表示负),其他n位为数值位。对于纯小数表示法,所能表示的数x(原码表示,下同)的范围为:-(1-2-n)≤x≤1-2-n
(2.4.1)
它能表示的数的最大绝对值为1-2-n,最小绝对值为2-n。对于纯整数表示法,所能表示的数x的范围为:-(2n-1)≤x≤2n
-1(2.4.2)它能表示的数的最大绝对值为2n-1,最小绝对值为1。Thursday,January12,2023
132.4.2浮点表示所谓浮点表示法,就是小数点在数中的位置是浮动的。任意一个二进制数x总可以写成如下形式:
(2.4.3)其中,d称为尾数,是二进制纯小数,指明数的全部有效数字,前面的符号称为数符,表示数的符号,该位为0,表明该浮点数为正,该位为1,表明该浮点数为负;p称为阶码,它前面的符号称为阶符,阶码为正时,用0表示,阶码为负时,用1表示。阶符阶码(p)数符尾数(d)1位m位1位n位Thursday,January12,2023
14可以看出,将尾数d的小数点向右(阶码p为正时)或向左(阶码p为负时)移动p位,即可得到该浮点数表示的数值x。阶码p指明小数点的位置,小数点随着阶码的大小和正负而浮动,因此把这种数称为浮点数。设阶码的位数为m位,尾数的位数为n位,则该浮点数表示的数值范围为:(2.4.4)
在字长相同的情况下,浮点数能表示的数值范围比定点数大得多,且精度高,但浮点运算规则复杂。Thursday,January12,2023
15SummaryMostmoderncomputersystemsusethebinarynumberingsystemtorepresentvalues.Sincebinaryvaluesaresomewhatunwieldy,we’lloftenusethehexadecimalrepresentationinourassemblyprograms.Asinglehexadecimaldigitconsumesfourbinarydigits(bits),andwecallagroupoffourbitsanibble.The80x86worksbestwithgroupsofbitswhichareeight,16,or32bitslong.Wecallobjectsofthesesizesbytes,words,anddoublewords,respectively.Inordertotalkaboutspecificbitswithinanibble,byte,word,doubleword,orotherstructure,we’llnumberthebitsstartingatzero(fortheleastsignificantbit)onupton-1(wherenisthenumberofbitsintheobject)Thursday,January12,2023
16SummaryTherearemanyoperationswecanperformonbinaryvaluesincludingnormalarithmetic(+,-,*,and/)andthelogicaloperations(AND,OR,XOR,NOT,ShiftLeft,ShiftRight,RotateLeft,andRotateRight).LogicalAND,OR,XOR,andNOTaretypicallydefinedforsinglebitoperations.Wecanextendthesetonbitsbyperformingbitwiseoperations.Theshiftsandrotatesarealwaysdefinedforafixedlengthstringofbits.Therearetwotypesofintegervalueswhichwecanrepresentwithbinarystringsonthe80x86:unsignedintegersandsignedintegers.The80x86representsunsignedintegersusingthestandardbinaryformat.Itrepresentssignedintegersusingthetwo’scomplementformat.Thursday,January12,2023
17SummaryCharacterdataisprobablythemostcommondatatypeencounteredbesidesintegervalues.TheIBMPCandcompatiblesuseavariantoftheASCIIcharacterset–theextendedIBM/ASCIIcharacterset.Thefirst128ofthesecharactersarethestandardASCIIcharacters,128arespecialcharacterscreatedbyIBMforinternationallanguages,mathematics,andlinedrawing.SincetheuseoftheASCIIcharactersetissocommoninmodernprograms,familiaritywiththischaractersetisessential.Thursday,January12,2023
18Questions
1)Convertthefollowingdecimalvaluestobinary: a)128 b)4096 c)256 d)65536 e)254 f)8882)Convertthefollowingbinaryvaluestodecimal: a)10011001
b)10011101 c)11000011 d)00001001 e)11111110Thursday,January12,2023
19Questions
3)Convertthebinaryvaluesinproblem2tohexadecimal.4)Convertthefollowinghexadecimalvaluestobinary: a)0ABCDb)1024c)0DEADd)0ADDe)0BEEFPerformthefollowinghexcomputations(leavetheresultinhex):5)1234+98766)0FFF-0F347)100-18)0FFE-19)Whatistheimportanceofanibble?10)Howmanyhexadecimaldigitsin: a)abyteb)awordc)adoublewordThursday,January12,2023
20Questions
11)Howmanybitsina: a)nibbleb)bytec)wordd)doubleword12)Whichbit(number)istheH.O.bitina: a)nibbleb)bytec)wordd)doubleword13)Whatcharacterdoweuseasasuffixforhexadecimalnumbers?Binarynumbers?Decimal numbers?14)Assuminga16-bittwo’scomplementformat,determinewhichofthevaluesinquestion4arepositiveandwhicharenegative.15)Signextendallofthevaluesinquestiontwotosixteenbits.Provideyouranswerinhex.Thursday,January12,2023
21Questions16)PerformthebitwiseANDoperationonthefollowingpairsofhexadecimalvalues.Presentyouranswerinhex.(Hint:converthexvaluestobinary,dotheoperation,thenconvertbacktohex). a)0FF00,0FF0 b)0F00F,1234 c)4321,1234 d)2341,3241 e)0FFFF,0EDCB17)PerformthelogicalORoperationontheabovepairsofnumbers.18)PerformthelogicalXORoperationontheabovepairsofnumbers.19)PerformthelogicalNOToperationonallthevaluesinquestionfour.Assumeallvaluesare16bits.Thursday,January12,2023
22Questions20)Performthetwo’scomplementoperationonallthevaluesinquestionfour.Assume16bitvalues.21)Signextendthefollowinghexadecimalvaluesfromeighttosixteenbits.Presentyouranswerinhex. a)FFb)82c)12d)56e)98 f)BFg)0Fh)78i)7Fj)F7 22)Signcontractthefollowingvaluesfromsixteenbitstoeightbits.Ifyoucannotperformtheoperation,explainwhy. a)FF00b)FF12c)FFF0d)12e)80 f)FFFFg)FF88h)FF7Fi)7Fj)223)Signextendthe16-bitvaluesinquestion22to32bits.24)Assumingthevaluesinquestion22are16-bitvalues,performtheleftshiftoperationonthem.25)Assumingthevaluesinquestion22are16-bitvalues,performtherightshiftoperationonthem.Thursday,January12,2023
23Questions26)Assumingthevaluesinquestion22are16-bitvalues,performtherotateleftoperationonthem.27)Assumingthevaluesinquestion22are16-bitvalues,performtherotaterightoperationonthem.28)Convertthefollowingdatestothepackedformatdescribedinthischapter(see“BitFieldsandPackedData”onpage28).Presentyourvaluesasa16-bithexnumber. a)1/1/92b)2/4/56c)6/19/60d)6/16/86e)1/1/9929)Describehowtousetheshiftandlogicaloperationstoextractthedayfieldfromthe packeddaterecordinquestion28.Thatis,windupwitha16-bitintegervalueintherange0..31.30)Supposeyouhaveavalueintherange0..9.ExplainhowyoucouldconvertittoanASCIIcharacterusingthebasiclogicaloperations.Thursday,January12,2023
24本章作业1.Convertthefollowingdecimalvaluestobinary:a)128b)4096c)256d)655362.Convertthefollowingbinaryvaluestodecimal:a)10011001b)100111013.Convertthefollowinghexadecimalvaluestobinary:a)0ABCDb)10244.Performthefollowinghexcomputations(leavetheresultinhex):
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 林场服务方案范本
- 消防器械调试方案范本
- 家庭农场筹建方案范本
- 求购二手房水电施工方案
- 危旧大棚改造方案范本
- 成本考核管理方案范本
- 小区草坪管理方案范本
- 脊柱侧凸术后康复管理
- 大会精神学习
- 初级药师基础知识(药物分析)模拟试卷1(共543题)
- 2026上海人保财险校园招聘笔试历年常考点试题专练附带答案详解
- (二模)苏北七市2026届高三第二次调研测试生物试卷(含答案)
- 2026云南昆明巫家坝建设发展有限责任公司校园招聘15人备考题库【a卷】附答案详解
- 2025年华峰重庆氨纶笔试刷完稳过的真题及解析答案
- 2026年渭南职业技术学院单招职业适应性测试题库含答案详细解析
- 医疗法律法规培训课件
- 科大讯飞深度研究报告
- 河道闸门应急预案(3篇)
- 2026年中医内科临床诊疗指南-尘肺病
- 数据采集流程标准化管理细则
- 2025年江苏卫生健康职业学院单招职业适应性测试题库带答案解析
评论
0/150
提交评论