Compare two values from the stack? [duplicate]

旧时模样 提交于 2019-12-02 11:08:13
Ira Baxter

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.

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