-
long exchange(long *xp, long y)
-
{
-
long x = *xp;
-
*xp = y;
-
return x;
-
}
MIPS汇编实现
-
exchange:
-
.frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0
-
.mask 0x00000000,0
-
.fmask 0x00000000,0
-
.set noreorder
-
.set nomacro
-
lw $2,0($4) #返回值取第一个入参指向的值
-
j $31
-
sw $5,0($4) #第二个入参存入第一个参数指针指向的位置
这里涉及到两条指令,lw, sw,具体如下:
Load / Store Instructions
加载/保存指令集
RAM access only allowed with load and store instructions,all other instructions use register operands
load:
lw register_destination, RAM_source
#copy word (4 bytes) at source RAM location to destination register.
(lw中的'w'意为'word',即该数据大小为4个字节)
store
#将指定寄存器中的数据 写入 到指定的内存中
sw register_source, RAM_destination
阅读(1648) | 评论(0) | 转发(0) |