Bug 2428 - rep and repz are misdisassembled
Summary: rep and repz are misdisassembled
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-07 00:08 UTC by H.J. Lu
Modified: 2006-03-16 19:43 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2006-03-07 00:08:53 UTC
According to IA32 SDM, rep should be used with ins, outs, movs, lods, and stos,
while repz/repnz should be used with cmps and scas. Both assembler accepts
both:

[hjl@gnu-13 rep]$ cat good.s
        rep insb
        rep outsb
        rep movsb
        rep lodsb
        rep stosb
        repz cmpsb
        repz scasb
        repnz cmpsb
        repnz scasb
[hjl@gnu-13 rep]$ cat bad.s
        repz insb
        repz outsb
        repz movsb
        repz lodsb
        repz stosb
        repnz insb
        repnz outsb
        repnz movsb
        repnz lodsb
        repnz stosb
        rep cmpsb
        rep scasb
[hjl@gnu-13 rep]$ make
./as   -o good.o good.s
./as   -o bad.o bad.s
./objdump -d good.o

good.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <.text>:
   0:   f3 6c                   repz insb (%dx),%es:(%rdi)
   2:   f3 6e                   repz outsb %ds:(%rsi),(%dx)
   4:   f3 a4                   repz movsb %ds:(%rsi),%es:(%rdi)
   6:   f3 ac                   repz lods %ds:(%rsi),%al
   8:   f3 aa                   repz stos %al,%es:(%rdi)
   a:   f3 a6                   repz cmpsb %es:(%rdi),%ds:(%rsi)
   c:   f3 ae                   repz scas %es:(%rdi),%al
   e:   f2 a6                   repnz cmpsb %es:(%rdi),%ds:(%rsi)
  10:   f2 ae                   repnz scas %es:(%rdi),%al
./objdump -d bad.o

bad.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <.text>:
   0:   f3 6c                   repz insb (%dx),%es:(%rdi)
   2:   f3 6e                   repz outsb %ds:(%rsi),(%dx)
   4:   f3 a4                   repz movsb %ds:(%rsi),%es:(%rdi)
   6:   f3 ac                   repz lods %ds:(%rsi),%al
   8:   f3 aa                   repz stos %al,%es:(%rdi)
   a:   f2 6c                   repnz insb (%dx),%es:(%rdi)
   c:   f2 6e                   repnz outsb %ds:(%rsi),(%dx)
   e:   f2 a4                   repnz movsb %ds:(%rsi),%es:(%rdi)
  10:   f2 ac                   repnz lods %ds:(%rsi),%al
  12:   f2 aa                   repnz stos %al,%es:(%rdi)
  14:   f3 a6                   repz cmpsb %es:(%rdi),%ds:(%rsi)
  16:   f3 ae                   repz scas %es:(%rdi),%al
Comment 1 H.J. Lu 2006-03-07 00:18:09 UTC
I guess it is OK to assemble "repz/repnz insb". But disassembler should
disassembler it correctly.
Comment 2 H.J. Lu 2006-03-07 20:12:28 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2006-03/msg00089.html
Comment 3 H.J. Lu 2006-03-16 19:43:53 UTC
Fixed.