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

2019年(21)

我的朋友

分类: C/C++

2019-06-21 17:03:49


C源代码:

点击(此处)折叠或打开

  1. int con(int x , int y)
  2. {
  3.         int result;
  4.         if(x < y)
  5.                 result = y -x;
  6.         else
  7.                 result = x - y;

  8.         return result;
  9. }

gcc -Og con.c -S

汇编代码

点击(此处)折叠或打开

  1. con:
  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.     slt    $24,$4,$5  # 如果第一个入参小于第二个入参,则置临时变量$24为1
  8.     beq    $24,$0,$L2  #如果$24为0,则返回x-y
  9.     nop

  10.     j    $31
  11.     subu    $2,$5,$4  #如果$24为1,则返回y-x

  12. $L2:
  13.     j    $31
  14.     subu    $2,$4,$5

mips的跳转指令如下
b target # unconditional branch to program label target
beq
$t0,$t1,target # branch to target if $t0 = $t1
blt
$t0,$t1,target # branch to target if $t0 < $t1
ble
$t0,$t1,target # branch to target if $t0 <= $t1
bgt
$t0,$t1,target # branch to target if $t0 > $t1
bge
$t0,$t1,target # branch to target if $t0 >= $t1
bne
$t0,$t1,target # branch to target if $t0 <> $t1
阅读(2460) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~