ITPub博客

首页 > 应用开发 > > C语言的汇编实现(三)条件跳转

C语言的汇编实现(三)条件跳转

作者:jasonhsp 时间:2019-08-28 16:21:15 0 删除 编辑

C源代码:

int con(int x , int y)
{
        int result;
        if(x < y)
                result = y -x;
        else
                result = x - y;

        return result;
}

gcc -Og con.c -S

汇编代码con:

    .frame    $sp,0,$31        # vars= 0, regs= 0/0, args= 0, gp= 0
    .mask    0x00000000,0
    .fmask    0x00000000,0
    .set    noreorder
    .set    nomacro
    slt    $24,$4,$5  # 如果第一个入参小于第二个入参,则置临时变量$24为1
    beq    $24,$0,$L2  #如果$24为0,则返回x-y
    nop

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

$L2:
    j    $31
    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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/615/viewspace-3123785/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-12

  • 博文量
    342
  • 访问量
    2720