📄 2.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>基本指令 </title>
<meta name="Microsoft Theme" content="arcs 011">
<meta name="Microsoft Border" content="none">
</head>
<body style="background-color: #FF0000" background="arctile.jpg" bgcolor="#FFFFFF" text="#000000" link="#3399FF" vlink="#666666" alink="#FF9900">
<p align="center"><font color="#000000"> <font size="6"> <b>3.2</b>
<strong>基本指令 </strong></font>
<strong> </strong></font></p>
<p align="right"><font color="#000000"><a href="index.htm"><img border="0" src="../images/back.gif" align="left" width="60" height="45"></a>
<a href="1.htm"><img border="0" src="../images/prev.gif" width="60" height="45"></a>
<a href="3.htm"><img border="0" src="../images/forw.gif" width="60" height="45"></a></font></p>
<p><strong><font color="#000000" size="4">MIPS 包括:<a href="#I.">算术运算指令</a>(<em>Arithmetic
instructions</em>),<a href="#II.">数据传输指令</a>(<em>Data transfer
instructions</em>),<a href="#III">条件转移指令</a>(<em>Conional instructions</em>)和<a href="#IV">无条件转移指令</a>(<em>Not
conditional instructions</em>).</font></strong></p>
<p><strong><font color="#000000" size="4"> <img border="0" src="../images/sub.gif" width="26" height="27"><a name="I."> I.</a> 算术运算指令 (<em>includes add,sub and addi</em>).</font></strong></p>
<p><strong><font color="#000000" size="4">在C语言中常有这样的指令:
f=(g+h)-(i+j);
</font>
</strong></p>
<p><strong><font color="#000000" size="4">变量 f,g,h,i和 j
被分配到寄存器$16,$17,$18,$19和$20中.编译器负责将程序变量与寄存器联系起来。</font></strong></p>
<p><strong><font color="#000000" size="4">编译后的程序是:</font></strong></p>
<p><strong><font color="#000000" size="4">
add $8,$17,$18
# register $8 contains g+h</font></strong></p>
<p><strong><font color="#000000" size="4">
add $9,$19,$20
# register $9 contains i+j</font></strong></p>
<p><strong><font color="#000000" size="4">
sub $16,$8,$9
# f gets $8-$9,or (g+h)-(i+j)</font></strong></p>
<p><strong><font color="#000000" size="4">addi 是立即数加法指令,即可以将寄存器与十进制数相加。如: </font></strong></p>
<p><strong><font color="#000000" size="4">
addi $16,$17,100
# $16=$17+100.</font></strong></p>
<p><font color="#000000"> </font></p>
<p><strong><font color="#000000"> <img border="0" src="../images/sub.gif" width="26" height="27">
<a name="II."><font size="4">II.</font></a><font size="4"> 数据传输指令 (<em>includes lw,sw,lui)</em></font></font></strong></p>
<p><strong><font color="#000000" size="4">如果我们假设 g 和 h
与寄存器 $17 和 $18联系,寄存器 $19 存有 4*i.(<em>for the byte
addresses of MIPS,the address</em> <em>index differ by 4</em>) </font> </strong></p>
<p><strong><font color="#000000" size="4">C 语句:
A[i]=h+A[i];</font></strong></p>
<p><strong><font color="#000000" size="4">可被编译成下面的MIPS汇编代码 :</font></strong></p>
<p><strong><font color="#000000" size="4">
lw $8,Astart($19)
# Temporary reg $8 gets A[i]</font></strong></p>
<p><strong><font color="#000000" size="4">
add $8,$18,$8
# Temporary reg $8 gets h+A[i]</font></strong></p>
<p><strong><font color="#000000" size="4">
sw $8,Astart($19)
# Stores h+A[i] back into A[i]</font></strong></p>
<p><strong><font color="#000000" size="4">lui (<em>load upper immediate</em>)当一个数较大时,超出16位,则可以用<em>lui</em>设置高16位,接着用其他指令设置低16位.如:</font>
</strong></p>
<p><strong><font color="#000000" size="4">把
0000 0000 0011 1101 0000 1001 0000 0000 这个32位的数放到寄存器$16中去,可以分两步做:</font> </strong></p>
<p><strong><font color="#000000" size="4">第一步:
lui
$16,61
# 61 decimal = 0000 0000 0011 1101 binary</font></strong></p>
<p><strong><font color="#000000" size="4">
寄存器 $16 就变成了:</font> </strong></p>
<p><strong><font color="#000000" size="4">
0000 0000 0011 1101 0000 0000 0000 0000
</font>
</strong></p>
<p><strong><font color="#000000" size="4"> 第二步:
addi
$16,$16,2304
# 2304 decimal = 0000 1001 0000 0000</font> </strong></p>
<p><strong><font color="#000000" size="4">
最后寄存器 $16 就变成了结果值:</font></strong></p>
<p><strong><font color="#000000" size="4">
0000 0000 0011 1101 0000 1001 0000 0000
</font>
</strong></p>
<p><strong><font color="#000000" size="4"> <img border="0" src="../images/sub.gif" width="26" height="27"> <a name="III">III</a>. 条件转移指令 </font> </strong></p>
<p><strong><font color="#000000" size="4">条件转移指令包括:beq,bne,slt,slti,sltu,sltiu.</font></strong></p>
<p><strong><font color="#000000" size="4">beq $1,$2,100 是判断$1,$2是否相等,如果两者相等的话,程序转到PC+4+100;</font></strong></p>
<p><strong><font color="#000000" size="4">bne $1,$2,100 与beq恰好相反,如果$1,$2不相等的话,程序转到PC+4+100.</font></strong></p>
<p><strong><font color="#000000" size="4">slt $1,$2,$3 是比较$2,$3的大小,如果$2<$3,那么$1=1,否则$1=0.</font></strong></p>
<p><strong><font color="#000000" size="4"><em>slti,sltu,sltiu</em>的基本语法与上述的<em>slt</em>是一样的,只是参数略有差别。</font></strong></p>
<p><strong><font color="#000000" size="4"> <img border="0" src="../images/sub.gif" width="26" height="27">
<a name="IV">IV</a>. 无条件转移指令</font></strong></p>
<p><strong><font color="#000000" size="4">无条件转移指令包括:j,jr,jal.</font></strong></p>
<p><strong><font color="#000000" size="4">j 10000
表示程序无条件的强行转移到目标地址10000。</font></strong></p>
<p><strong><font color="#000000" size="4">jr $31
这个语句是专为<em>switch</em>设立的,它以寄存器为转移地址,转移到$31指定的单元执行指令。</font></strong></p>
<p><strong><font color="#000000" size="4">jal 10000
这个语句是为程序调用而设立的,它的意思是$31=PC+4;程序转到10000。</font> </strong></p>
<p><strong><font color="#000000"><font size="4">我们将在后面的大程序中看到这些语句的功能。</font>
</font> </strong></p>
<p><font color="#000000"> </font></p>
<p> </p>
<p> </p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -