问题描述
我卡住了在我要比较两个值的汇编代码中堆栈.
I stuckin my assembler code where I want to compare two values of thestack.
x86,语法AT& T
x86, Syntax AT&T
cmpl -4(%ebp), 4(%ebp)
我认为不可能基于乘数和ebp比较两个值.有什么建议吗?
I think it is not possible to compare two values based on a multiplier and ebp. Any suggestions ?
推荐答案
您可以使用CMPSD指令比较内存中的两个值.
You can compare two values in memory using the CMPSD instruction.
Op想做的事情等同于:
Op wants to do something equivalent to:
cmpl -4(%ebp), 4(%ebp)
他可以通过将感兴趣的内存位置的地址分别放在ESI和EDI中,然后使用 CMPSD内存到内存字符串比较指令:
He can do that by placing the addresses of the memory locations of interest in ESI and EDI respectively, and then using the CMPSD memory-to-memory string-compare instruction:
lea -4(%ebp), %esi
lea 4(%ebp), %edi
cmpsd
(原谅我对AT& T语法的非专业滥用).
(forgive my non-expert abuse of AT&T syntax).
与实践中的任何人都不同.此处提供的其他答案(将值加载到寄存器中并进行比较)更加实用.如果没有其他问题,那么这些解决方案只会烧掉一个寄存器,而这个hack会烧掉两个寄存器.
That's different than anybody would do this in practice. The other answers provided here (load a value into a register and compare) are much more practical. If nothing else, those solutions only burn one register, and this hack burns two.
课程:在汇编程序中,几乎总有不止一种为猫皮剥皮的方法.
Lesson: in assembler, there's almost always more than one way to skin a cat.
这篇关于比较堆栈中的两个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!