0

So I'm working on this file. I have to transform complex addressing mode into simple addressing mode.

I've managed to do

movl $0, 0(%esp)

into

addl $0, %esp
movl $0, (%esp)
addl $-0, %esp

works just fine, for all cases.

However I can't do the same thing with

cmpl $4, 28(%esp)

I understand that a compare is not the same as a move. But has anyone an idea how the simple version of the last line would look like? Thx in advance

Michael
  • 57,169
  • 9
  • 80
  • 125
Anja Lube
  • 15
  • 2
  • Note that `0(%esp)` and `(%esp)` mean the same thing (they result in exactly the same machine code sequences), so the two `addl`s are unnecessary in that case. – Michael May 14 '15 at 16:15

1 Answers1

1

It's the same logic though:

movl %esp, %eax
addl $28, %eax
cmpl $4, (%eax)

Notice I used eax as temporary. You could move the stack pointer, but that's bad idea, and also it will mess up the flags when you try to restore it. You would need a temporary anyway, such as:

addl $28, %esp
movl (%esp), %eax
addl $-28, %esp
cmpl $4, %eax

You could of course use lea as that doesn't modify the flags, but you are apparently forbidden to use complex addressing mode. You can't use pushf/popf either, because those need the stack pointer.

Jester
  • 56,577
  • 4
  • 81
  • 125