Compare two values from the stack? [duplicate]

醉酒当歌 提交于 2019-12-02 19:05:01

问题


I stuck in my assembler code where I want to compare two values of the stack.

x86, Syntax AT&T

cmpl -4(%ebp), 4(%ebp)

Error: too many memory references for `cmp'

I think it is not possible to compare two values based on a multiplier and ebp. Any suggestions ?


回答1:


You can compare two values in memory using the CMPSD instruction.

Op wants to do something equivalent to:

  cmpl -4(%ebp), 4(%ebp)

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

(forgive my non-expert abuse of AT&T syntax).

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.



来源:https://stackoverflow.com/questions/40440658/compare-two-values-from-the-stack

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