How to convert IA32 'cmp' instruction to Y86?

ⅰ亾dé卋堺 提交于 2020-01-04 14:04:01

问题


IA32 to Y86

ATT Assembly

I have the following IA32 assembly code:

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

I'm trying to convert it to Y86 assembly code. I'm having trouble translating the compare instruction:

 cmpl    %ebx, %ecx

Thanks.


回答1:


It seems that Y86 does not have cmp instruction. However, it has sub, push and pop.

So cmpl %ebx, %ecx can be converted to the following code:

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

cmp is exactly the same as sub, with the difference that cmp does not store the result, it only updates the flags. So cmp can always be replaced with push, sub, pop (if there's enough space in the stack).



来源:https://stackoverflow.com/questions/15098073/how-to-convert-ia32-cmp-instruction-to-y86

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!