【问题标题】:How to convert IA32 'cmp' instruction to Y86?如何将 IA32 'cmp' 指令转换为 Y86?
【发布时间】:2013-02-26 19:55:53
【问题描述】:

IA32Y86

ATT 大会

我有以下 IA32 汇编代码:

Bubble:
.LFB0:
    pushl   %esi
    pushl   %ebx
    movl    16(%esp), %esi
    movl    12(%esp), %edx
    subl    $1, %esi
    andl    %esi, %esi
    jle .L1
.L7:
    xorl    %eax, %eax
.L5:
    movl    4(%edx,%eax,4), %ecx
    movl    (%edx,%eax,4), %ebx
    cmpl    %ebx, %ecx
    jge .L4
    movl    %ebx, 4(%edx,%eax,4)
    movl    %ecx, (%edx,%eax,4)
.L4:  
    addl    $1, %eax
    cmpl    %eax, %esi
    jg  .L5
    subl    $1, %esi
    jne .L7
.L1: 
    popl    %ebx
    popl    %esi
    ret

我正在尝试将其转换为 Y86 汇编代码。我在翻译比较指令时遇到问题:

 cmpl    %ebx, %ecx

谢谢。

【问题讨论】:

    标签: assembly x86 cmp y86


    【解决方案1】:

    Y86好像没有cmp指令。但是,它有subpushpop

    所以cmpl %ebx, %ecx可以转换成如下代码:

    pushl %ecx
    subl  %ebx, %ecx
    popl  %ecx
    

    cmpsub 完全相同,区别在于cmp 不存储结果,它只更新标志。所以cmp总是可以替换为pushsubpop(如果堆栈中有足够的空间)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-19
      • 2015-07-07
      • 1970-01-01
      • 1970-01-01
      • 2014-06-15
      相关资源
      最近更新 更多