Chinaunix首页 | 论坛 | 博客
  • 博客访问: 994083
  • 博文数量: 21
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 216
  • 用 户 组: 普通用户
  • 注册时间: 2018-11-27 17:55
文章分类
文章存档

2019年(21)

我的朋友

分类: C/C++

2019-06-05 08:08:47


点击(此处)折叠或打开

  1. long exchange(long *xp, long y)
  2. {
  3.     long x = *xp;
  4.     *xp = y;
  5.     return x;
  6. }

MIPS汇编实现

点击(此处)折叠或打开

  1. exchange:
  2.     .frame    $sp,0,$31        # vars= 0, regs= 0/0, args= 0, gp= 0
  3.     .mask    0x00000000,0
  4.     .fmask    0x00000000,0
  5.     .set    noreorder
  6.     .set    nomacro
  7.     lw    $2,0($4)    #返回值取第一个入参指向的值
  8.     j    $31
  9.     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


阅读(1593) | 评论(0) | 转发(0) |
0

上一篇:ONU状态释义

下一篇:mips的32个通用寄存器

给主人留下些什么吧!~~