已阅读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新疆和田都玉客运有限责任公司面向社会招聘工作人员2人模拟试卷及参考答案详解【能力提升】
- 2026云南轻纺职业学院秋季学期银龄教师招募12人备考题库含答案详解(精练)
- 2026河北石家庄市艺术学校招聘兼职教师16人模拟试卷含答案详解(培优B卷)
- 2026年枣庄山亭区青年见习招募(第五批)模拟试卷【易错题】附答案详解
- 2026浙江宁波东方海纳人力资源服务有限公司招聘1人备考题库【名校卷】附答案详解
- 2026广西北海市合浦县公共就业服务中心招录城镇公益性岗位4人考前冲刺密卷及答案详解【典优】
- 2026广东惠州市惠东县招聘第二批公办学校教师22人模拟试卷附参考答案详解(达标题)
- 2026中共苍溪县委社会工作部招募社会工作服务领域增量政策性岗位服务人员12人模拟试卷带答案详解(基础题)
- 2026浙江绍兴市外服人力资源服务有限公司派驻景区医务人员招聘1人模拟试卷附完整答案详解(名校卷)
- 2026广西玉林市福绵区福保后勤服务管理有限公司招聘业务员1人考前冲刺试卷【夺分金卷】附答案详解
- (新版)FSC产销监管链认证全套管理手册及程序文件(可编辑!)
- 雨污水管道施工验收全流程指南
- 《机车总体及走行部》课件 项目八 任务1 机车检查作业前的准备工作
- 1.1认识社会生活 教案 2025-2026学年统编版道德与法治八年级上册
- TCACM1021.9-2018中药材商品规格等级天麻
- 2025年三力测试试题及答案
- 关键员工培育管理办法
- 口腔耗材管理指南
- 输变电工程多维立体参考价(2025年版)
- PE室外给水管道安装施工组织设计
- 《雅思阅读》课件
评论
0/150
提交评论