IA32 至 Y86
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
谢谢。
最佳答案
Y86 好像没有 cmp
指令。但是,它有 sub
、push
和 pop
。
因此cmpl %ebx, %ecx
可以转换为以下代码:
pushl %ecx
subl %ebx, %ecx
popl %ecx
cmp
与 sub
完全相同,不同之处在于 cmp
不存储结果,仅更新标志。因此,cmp
始终可以替换为 push
、sub
、pop
(如果堆栈中有足够的空间)。
关于assembly - 如何将IA32 'cmp'指令转换为Y86?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15098073/