📄 4-4.htm
字号:
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta name="Microsoft Theme" content="arcs 001">
<meta http-equiv=Content-Type content="text/html; charset=GB2312">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">
<link rel=File-List href="./4-4.files/filelist.xml">
<link rel=Edit-Time-Data href="./4-4.files/editdata.mso">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>Logical Operation 逻辑操作</title>
<!--[if gte mso 9]><xml>
<o:DocumentProperties>
<o:Author>Dracula</o:Author>
<o:Template>Normal</o:Template>
<o:LastAuthor>Dracula</o:LastAuthor>
<o:Revision>2</o:Revision>
<o:TotalTime>0</o:TotalTime>
<o:Created>2002-06-15T23:18:00Z</o:Created>
<o:LastSaved>2002-06-15T23:18:00Z</o:LastSaved>
<o:Pages>3</o:Pages>
<o:Words>301</o:Words>
<o:Characters>1718</o:Characters>
<o:Company>Tomb</o:Company>
<o:Lines>14</o:Lines>
<o:Paragraphs>3</o:Paragraphs>
<o:CharactersWithSpaces>2109</o:CharactersWithSpaces>
<o:Version>9.2812</o:Version>
</o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:Compatibility>
<w:UseFELayout/>
</w:Compatibility>
</w:WordDocument>
</xml><![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:宋体;
mso-bidi-font-family:"Times New Roman";
color:black;}
h3
{color:black;}
a:link, span.MsoHyperlink
{color:#3399FF;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{color:#666666;
text-decoration:underline;
text-underline:single;}
p
{font-size:12.0pt;
font-family:宋体;
mso-bidi-font-family:"Times New Roman";
color:black;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:42.55pt;
mso-footer-margin:49.6pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1028"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1"/>
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor=white background="..\chapter1\arctile.jpg" lang=ZH-CN
link="#3399ff" vlink="#666666" style='tab-interval:21.0pt' alink="#FF9900">
<div class=Section1>
<h3 align=center style='text-align:center'><span lang=EN-US style='font-size:
24.0pt'>4.4 Logical Operation 逻辑操作</span></h3>
<p align=right style='text-align:right'><span lang=EN-US><a href="chapter4.htm"></a></span><!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_s1026" type="#_x0000_t75" alt=""
href="chapter4.htm" style='position:absolute;left:0;text-align:left;
margin-left:0;margin-top:0;width:45pt;height:33.75pt;z-index:1;
mso-wrap-distance-left:0;mso-wrap-distance-top:0;mso-wrap-distance-right:0;
mso-wrap-distance-bottom:0;mso-position-horizontal:left;
mso-position-horizontal-relative:text;mso-position-vertical-relative:line'
o:allowoverlap="f" o:button="t">
<v:imagedata src="images\BACK.GIF"/>
<w:wrap type="square"/>
</v:shape><![endif]--><![if !vml]><a href="chapter4.htm"><img border=0
width=60 height=45 src="images\BACK.GIF" align=left v:shapes="_x0000_s1026"></a><![endif]><a
href="chapter4.htm"></a><span lang=EN-US>
<a href="4-3.htm"><span style='text-decoration:none;text-underline:none'><img
border=0 width=60 height=45 id="_x0000_i1025" src="images\PREV.GIF"></span></a>
<a href="4-5.htm"><span style='text-decoration:none;text-underline:none'><img
border=0 width=60 height=45 id="_x0000_i1026" src="images\FORW.GIF"></span></a> </span></p>
<p><span style='font-size:13.5pt'>本节问题:</span></p>
<p><span lang=EN-US style='font-size:13.5pt'><img border=0 width=26 height=27
id="_x0000_i1027" src="images\SUB.GIF"><a href="#移位指令:">移位指令</a><a
href="#逻辑AND和OR:"><br>
</a><img border=0 width=26 height=27 id="_x0000_i1028" src="images\SUB.GIF"><a
href="#逻辑AND和OR:">逻辑与或操作</a></span><span lang=EN-US> </span></p>
<p><span style='font-size:13.5pt'>一:<a name="移位指令:">移位指令:</a></span><span
style='mso-bookmark:移位指令:'></span></p>
<p><span lang=EN-US style='font-size:13.5pt'> 尽管开始注重整个words,但是很快在bits
within a word上的操作变得更有用。一个这种例子就是shifts(移位)。这个指令是将整个a word中的bits从右向左移。For example
:</span></p>
<p><span lang=EN-US style='font-size:13.5pt'> if register $16
contained 0000 0000 0000 0000 0000 0000 0000 1101<sub>two</sub>and the
instruction to shift left by 8 was executed ,the new value would look like
this:<br>
0000 0000 0000 0000 0000 1101 0000 0000<sub>two</sub>.</span></p>
<p><span lang=EN-US style='font-size:13.5pt'> MIPS中提供shift
left logical (sll) and shift right logical (srl).要实现刚才上面那个例子中的操作,假设结果存放在寄存器$10中,则:<br>
sll $10 ,$16 ,8 #reg $10 =reg $16 <<8 bits</span></p>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'> 在第3章中,曾经在讲R format时提到shamt filed。 shamt代表shift
amount,被用在移位操作指令之中,所以刚才那个指令的机器语言格式如下:</span></p>
<p><span lang=EN-US style='font-size:13.5pt'>
op <span
style="mso-spacerun: yes"> </span>rs
<span style="mso-spacerun: yes"> </span>rt
<span style="mso-spacerun: yes"> </span>rd
<span style="mso-spacerun: yes"> </span><span style="mso-spacerun:
yes"> </span>shamt <span
style="mso-spacerun: yes"> </span>funct</span><span
lang=EN-US><o:p></o:p></span></p>
<div align=center>
<table border=1 cellspacing=0 cellpadding=0 width="90%" style='width:90.0%;
mso-cellspacing:0cm;mso-padding-alt:0cm 0cm 0cm 0cm' bordercolordark="#CC9966"
bordercolorlight="#FFCC66">
<tr>
<td width="16%" style='width:16.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>0</span></p>
</td>
<td width="16%" style='width:16.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>0</span></p>
</td>
<td width="17%" style='width:17.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>16</span></p>
</td>
<td width="17%" style='width:17.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>10</span></p>
</td>
<td width="17%" style='width:17.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>8</span></p>
</td>
<td width="17%" style='width:17.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>0</span></p>
</td>
</tr>
</table>
</div>
<p><span style='font-size:13.5pt'>二:<a name="逻辑AND和OR:">逻辑<span lang=EN-US>AND和OR:</span></a></span><span
style='mso-bookmark:"逻辑AND和OR\:"'></span></p>
<p><span lang=EN-US style='font-size:13.5pt'> 另一个有用的操作指令是AND和OR,
AND是当两个操作数的相应的位同为1时,结果中的相应位置1,反之置0。</span></p>
<p><span lang=EN-US style='font-size:13.5pt'> For example,if
register $10 contains 0000 0000 0000 0000 0000 1101 0000 0000<sub>two</sub><br>
,and register $9 contains 0000 0000 0000 0000 0011 1100 0000 0000<sub>two</sub>then
after executing the MIPS instruction:</span></p>
<p><span lang=EN-US style='font-size:13.5pt'>
and $8 , $9 ,$10 #reg $8 =reg $9 & reg $10</span></p>
<p><span lang=EN-US style='font-size:13.5pt'>the value of register $8 would be
:0000 0000 0000 0000 0000 1100 0000 0000<sub>two</sub></span></p>
<p><span lang=EN-US style='font-size:13.5pt'> or
$8 , $9 , $10 #reg $8= reg $9|$10</span></p>
<p><span lang=EN-US style='font-size:13.5pt'>then the value of $8 is 0000 0000
0000 0000 0011 1101 0000 0000<sub>two</sub>l.</span></p>
<p><span lang=EN-US style='font-size:13.5pt'> 在MIPS中提供and
immediate(andi)和or immediate(ori)。具体看下表:</span><span lang=EN-US><o:p></o:p></span></p>
<div align=center>
<table border=1 cellspacing=0 cellpadding=0 width="80%" style='width:80.0%;
mso-cellspacing:0cm;mso-padding-alt:0cm 0cm 0cm 0cm' bordercolordark="#CC9966"
bordercolorlight="#FFCC66">
<tr>
<td width="33%" style='width:33.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>Logical Operations</span></p>
</td>
<td width="33%" style='width:33.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>C Operators</span></p>
</td>
<td width="34%" style='width:34.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>MIPS instructions</span></p>
</td>
</tr>
<tr>
<td width="33%" style='width:33.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>Shift Left</span></p>
</td>
<td width="33%" style='width:33.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'><<</span></p>
</td>
<td width="34%" style='width:34.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>sll</span></p>
</td>
</tr>
<tr>
<td width="33%" style='width:33.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>Shift Right</span></p>
</td>
<td width="33%" style='width:33.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>>></span></p>
</td>
<td width="34%" style='width:34.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>srl</span></p>
</td>
</tr>
<tr>
<td width="33%" style='width:33.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>AND</span></p>
</td>
<td width="33%" style='width:33.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>&</span></p>
</td>
<td width="34%" style='width:34.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>and,andi</span></p>
</td>
</tr>
<tr>
<td width="33%" style='width:33.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>OR</span></p>
</td>
<td width="33%" style='width:33.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>|</span></p>
</td>
<td width="34%" style='width:34.0%;padding:0cm 0cm 0cm 0cm'>
<p align=center style='text-align:center'><span lang=EN-US style='font-size:
13.5pt'>or,ori</span></p>
</td>
</tr>
</table>
</div>
<p><span lang=EN-US style='font-size:13.5pt'> 由于addi和ori通常有无符号数为操作数,立即数与无符号数一样也通过在前面加0扩展到32-bit。在MIPS中,assembler通过lui
和ori指令来产生32-bit constants。</span></p>
<p> </p>
<p> </p>
<p> </p>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -