




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 湖南省长沙市一中马王堆中学2024-2025学年七年级下学期期末考试英语试卷(无答案)
- 倔强的贝多芬课件
- 伦敦眼课件教学课件
- 四川广元天立学校2025-2026学年高三物理第一学期期末教学质量检测模拟试题
- 2025-2026学年云南省保山一中物理高三第一学期期末学业水平测试试题
- 黑龙江驻村管理办法
- 企业物业人员安全培训课件
- 新质生产力的发展观解读
- 加快科技成果转化培育新质生产力
- 统编版 语文 三年级 上册《一个粗瓷大碗 》教学教案
- DB34T∕ 2615-2016 公路沥青路面同步碎石封层施工技术规程
- 公司数字化与信息化管理制度
- 2024年新湘少版三年级上册英语全册教学课件
- 部编四年级道德与法治上册全册教案(含反思)
- 《成人有创机械通气气道内吸引技术操作》标准解读
- 2024年教师招聘考试公共基础知识复习提纲
- 中考英语688高频词大纲词频表
- DL-T-301-2011发电厂水汽中痕量阳离子的测定离子色谱法
- 糖尿病肾脏疾病早期预测与诊断专家共识
- 2024年湖南长沙湘江新区所属事业单位招聘12人历年高频考题难、易错点模拟试题(共500题)附带答案详解
- 《电力系统治安反恐防范要求 第3部分:水力发电企业》
评论
0/150
提交评论