1

So basically I am trying to re-use some asm code disassembled from objdump on 32 bit Linux, ELF binary.

In the disassembled file, I see this instruction:

8057a01:       f3 c3                   repz ret

and when I try to re-use repz ret in my asm code, I got this error:

 Error: expecting string instruction after `repz'

I tried to specify a ret type like this:

repz retq

but I still got the same error again..

Could anyone give me some help?

lllllllllllll
  • 8,519
  • 9
  • 45
  • 80
  • possible duplicate of [Disassembling, modifying and then reassembling a Linux executable](http://stackoverflow.com/questions/4309771/disassembling-modifying-and-then-reassembling-a-linux-executable) – Jonathon Reinhart May 12 '14 at 01:34
  • @JonathonReinhart I don't think so, please double-check what they are talking about and basically my question is why `repz ret` cannot be assembled – lllllllllllll May 12 '14 at 01:38

2 Answers2

4

Your assembler probably wasn't prepared for that use of repz.

repz does not do anything per se when placed in front of a ret instruction, but it is used sometimes to prevent a jump directly to a ret instruction - for padding, essentially - because jumping directly to a ret has bad performance on certain CPU models.

You should be able to encode the instruction combination with a db sequence.

3

The solution is simple, you just need to put the repz and the ret on two consecutive lines. Also note that this optimization is obsolete, AMD now recommends to use ret 0 if your ret is a branch target (even for fall-through). In fact for even more recent AMD chips this whole optimization is not needed because the branch predictor works differently.

Jester
  • 56,577
  • 4
  • 81
  • 125