0

I want to use rep insw instruction. Operands for this instruction are predetermined. It looks like this:

rep insw (%dx),%es:(%rdi)

dx and rdiare general-purpose registers so I can freely modify them. What about es? It points to "extra data". I have never used it and I don't know what it means. It would be nice if I could set it to zero and rdi to linear address. Will something break if I set these (segment) registers to any value like general-purpose registers?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
yomol777
  • 463
  • 4
  • 16
  • 2
    CS/DS/ES/SS base addresses are already fixed at 0 on x86-64. Whether you can put a random *selector* value (index into GDT) into them is a separate question. If you just want a flat virtual address space, you don't have to do anything at all in 64-bit code, just avoid FS and GS segment overrides (no instructions use them implicitly). In practice, same for 32-bit code under any mainstream OS, and in your own custom kernel code where you're using `insw` if you set up the GDT that way. – Peter Cordes Jun 09 '20 at 08:20
  • 2
    [Is segmentation completely not used in x64?](https://stackoverflow.com/q/57222727) is a possible duplicate. Does that answer everything you were wondering? Also related, [Why segmentation cannot be completely disable?](https://stackoverflow.com/q/49811461) covers the vestiges of segmentation that are necessary to keep the CPU happy. – Peter Cordes Jun 09 '20 at 08:23

0 Answers0