已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter11BitOperation Inordertosavememoryspace severalstatussignsareusuallyputtogetherintoonebyte orbit Clanguageisdesignedforstudyingsystemsoftware soitoffersbitoperationwhichseparatestatussignfromsignbytememory Bitoperationisthatwedoitinbinary 11 1numberexpressedincomputer11 2bitoperation11 3bitsegment 11 1NumberExpressedinComputer 1 BitandByteMemoryincomputersystemisconstitutedofmanynamedbyteunits Onebyteismadeupofeightbits andthevalueis0or1ofeverybit Thebitintherightsideiscalled thelowestbit anditsnumberis0 Thebitintheleftsideiscalled thehighestbit andsetthenumbertoeachbitfromthelowesttohighestinorder Diagram11 1isthenumberofeachbitinonebyte Fig11 1Thenumberofeachbitinonebyte2 DigitExpressedbyInitialCodeDigitexpressedbyinitialcodeisthatusingthehighestbitasasignbit 0referstopositivenumber 1referstonegativenumber theotherbitsrepresenttothemselves absolutevalue expressedinbinary Inordertosimpledescription weuseonebytetoexpressoneintegralinthisclass Forexample theinitialcodeof 9is00001001 signbit0referstopositivenumbertheinitialcodeof 9is10001001 signbit0referstonegativenumber3 DigitExpressedbyOppositeCodedigitexpressedbyoppositecodeincludestwocircumstances 1 oppositecodeofpositivenumber thesameastheinitialcode Forexample theoppositecodeof 9is00001001 2 oppositecodeofnegativenumber signbitis1 otherbitsisoppositetotheirabsolutevalue 1turnsto0 0turnsto1 Forexample theoppositecodeof 9is becauseitisanegativenumber signbitis1 othersevenbitsistheoppositeofitsabsolutevaluethattheinitialof 9 sotheoppositeof 9is11110110 4 DigitExpressedbyComplementCodeDigitexpressedbycomplementcodealsoincludestwocircumstances 1 thecomplementcodeofpositivenumber thesameastheinitialcode Forexample thecomplementcodeof 9is0001001 2 thecomplementofnegativenumber signbitis1 otherbitsisoppositetotheirabsolutevalue sinitialcode thenadd1 Forexample thecomplementcodeof 9is becauseitisanegativenumber signbitis1 othersevenbitsistheoppositeofitsabsolutevaluethattheinitialof 9 sotheoppositecodeof 9is11110110 Thenitadds1 Sothecomplementof 9is11110111 Ifweknowthecomplementcodeofanumber therearetwocircumstancesabouttheinitialcode 1 ifthecomplementcode ssignbitis 0 itisapositivenumber socomplementcodeisjustitsinitialcode 2 ifthecomplementcode ssignbitis 1 itisanegativenumber sotheoperationofobservinganinitialcodecanbe signbitisnotchanged otherbitsisoppositetotheirabsolutevalue sinitialcode Thenitadds1 Forexample itisgivenacomplementcodethatis11111001 soitsinitialcodeis10000111 7 becauseitssignbitis 1 itisanegativenumber thesignbitneedn tchanged itisstill 1 othersevenbitsistheoppositeof1111001 soitis0000110now thenitadds1 Itis10000111 5 NumberExpressedinComputer ComplementCodeIncomputesystem digitsareallexpressincomplementcode thereasonisthat wecandowithsignbitandotherbitstogether Alsominuscanbedoneasplusdone Besides whentwonumberswhichareexpressedincomplementcodedoplusoperation ifthereisaentertothehighestbit theenterbitisabandoned 11 2BitOperation 11 2 1BitOperationandItsOperationSigns1 Andeachbitinorder 1 formate x y 2 rule onlywhencorrespondbitis1 itisa Otherwiseitis0 Forexample 3 9 1 0011 1001 0001 1 3 mainusage take orsave somebitofanumber otherbitsare0 2 Oreachbitinorder 1 formate x y 2 rule onlywhencorrespondbitis0 itis0 Otherwiseitis1 Forexample 3 9 11 0011 1001 1011 11 3 mainusage setsomebitto1ofanumber otherbitsisnotchanged 3 XOReachbit 1 formate x y 2 rule whencorrespondbitisthesame itis0 whenitisdifferent itis1 3 9 10 3 Mainusage makesomebittoconvert ifitis1 itwillbeturnedto0 ifitis0 itwillbeturnedto1 otherbitsareallnotchanged 4 Converteachbit 1 formate x 2 rule converteachbitisthatifitis1 itwillbeturnedto0 elseitwillbeturnedto1 inIBM PCcompute 0 0 xffff 9 0 xfff6 3 Mainusage makeanumberindirectly soitstrengthstransplantofprograms 5 Movelefteachbit 1 formate x anumber 2 rule makeeachbitmoveleft thelowestbitsetto0 thehighestbitisoverflow 5 2 20 6 Moverighteachbit 1 formate x anumber 2 rule makeeachbitmoveright thelowestbitwhichismovedoutwillbeabandoned thehighestbit 1 Tounsignednumbersandsignedpositivenumbers itwillbeset0 2 Ifitisasignednegativenumber itisdecidedbythesystemwhichyouareusing set0iscalled logicleftmovement set1iscalled arithmeticrightmovement Forexample 20 2 5 instructions 1 x yand bitnumber andsoon areallintorchar Exceptforconvertingeachbitissingleoperationsign othersaretwooperationsign 2 whenitisdoneintheoperation theoperatorsxandyareallmustfirstconvertedtobinary thenexecutetheoperation Forexample 5 2 5 10100 00101 3 wayofmakinguseof operation1 makeupaninteger thisnumberwillbesetto1whereyouwanttotake orsave orsetto1 otherbitsareallsetto0 2 doandeachbitororeachbitorXOReachbitoperation 4 wayofmakinguseofconvertingeachbitoperation1 do 0 indirectlymakeanumberwhereeachbitis1 2 accordingtowhatyouneed domovingleftormovingrightoperationtomakeanumberwhatyouwish Forexample directlymakeanumberwhereeachbitis1 InIBM PCcomputeitis0 xffff twobytes butinVAX 11 780 itis0 xffffffff fourbytes Ifweuse 0tomakeanumber systemcansuititauto Thedetailoftheapplication pleasereferto example11 1 11 2 2Example 11 1 Inputanintegertovariablenum outputaHexnumbermakedupby8 11bits generalprogress 1 movevariablenumrightbyeightbits andmovethebitswhereitisfrom8to11tothelowfourbits 2 makeupanintegralwheretherelowfourbitsareall1 otherbitsareall0 3 dotheoperationandtonum filenameoftheexamplecode AL11 1 C functionoftheprogram outputanintegralwhichismadeupoffromeightbitstoelevenbits main intnum mask printf Inputaintegernumber scanf d Theresultoftheprogram Inputaintegernumber 1000 result 0 x3Instructionstotheprogram 0 4 Converteachbitabout0 thenitsbitisall1 aftermovingleftbyfourbits itslowfourbitsareall0 otherbitsareall1 thenXOReachbit thelowfourbitsareall1 otherbitsareall0 Thisintegeriswhatwewant example11 2 inputanintegerfromkeyboardandisgiventovariablenum thenoutputitbybit filenameoftheexamplecode AL11 2 C functionoftheprogram outputanintegerbybit include stdio h main intnum mask i printf Inputaintegernumber scanf d Theresultoftheprogram Inputaintegernumber 1000 1000 0000 0011 1110 1000B11 2 3instruction1 ComplexendowoperationExceptforconvertingeachbit otherfivebitoperationscanbeusedwithendowtomakeupofacomplexendowoperation 2 theoperationtothedataswithdifferentlengths alignaccordingthelowbit thehighestbitofshortdataissetaccordingtothehighestbit 1 totheunsignednumberandsignedpositivenumber isset0 2 toasignednegativenumber isset1 11 3bitsegmentintroduction Sometimeswhenwesaveaninformationdon tneedabyte onlyneeda orseveral bits Ifwestillusethisstructuretype itwillwastespaceofmemory Inordertoresolvethisproblem Clanguageimportsabitsegmenttype 1 theconceptanddefinitionofbitsegmentBitsegmentstructuretypeisaspecialstructuretype Itsmembersareallexpressedinbinaryabouttheirlength anditsmembersarecalledsegments Forexample thestatusregisterofCPUisdefinedbysegmenttypeasfollowing structstatus unsignedsign 1 signmark unsignedzero 1 zeromark unsignedcarry 1 carryingbitmark unsignedparity 1 oddoreven overflowmark unsignedhalf carry 1 halfcarryingbitmark unsignednegative 1 minusmark flags Obviously itoccupiesfivebitslessthanitisinastructuretype needssixbits forthestatusregisterofCPUwhichisinbitsegmenttype onlyneedsonebyte 2 instrutions 1 Forbitsegmenttypeisastructuretype thedefinitionofbitsegmenttypeandbitsegmentvariableisthesameasthatofstructuretypeandstructurevariable 2 Whenyouendowavaluetobitsegment youshouldbecarefulaboutthescopeofitsvalue 0 2n 1 3
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年江西省瑞昌市高二生物下册期末考试测试卷及答案(夺冠)
- 2026年吉林省公主岭市高二生物下册期末考试考试卷及答案(新)
- 2026年贵州省兴义市高二生物下册期末考试模拟卷(轻巧夺冠)附答案
- 2026年辽宁省新民市高二生物下册期末考试检测卷附参考答案(研优卷)
- 2026年山东省荣成市高二生物下册期末考试模拟卷及答案(有一套)
- 2025年江苏省兴化市高二生物下册期末考试模拟卷完整版附答案
- 2026年辽宁省新民市高二生物下册期末考试检测卷含答案【预热题】
- 2025年浙江省江山市高二生物下册期末考试模拟卷及参考答案(培优A卷)
- 2026年幼儿园一等奖社会公开课
- 2026年幼儿园懂礼貌的好孩子宣讲
- 样板示范工程管理制度
- 家电卖场卫生管理制度
- 施工项目机械租赁服务方案
- 海外出国劳务合同8篇
- 陶瓷基复合材料制备-深度研究
- 大数据与人工智能营销(南昌大学)知到智慧树章节答案
- 中考英语688高频词大纲词频表
- 大话机器人智慧树知到期末考试答案章节答案2024年青海大学
- 食品保藏探秘智慧树知到期末考试答案章节答案2024年中国海洋大学
- 商务英语专业四级
- 充棉机安全操作规程模版
评论
0/150
提交评论