1

In Volume 2, CHAPTER 4 INSTRUCTION SET REFERENCE, M-U, the description of OUT Instruction has this sentence:

"using the DX register as a source operand allows I/O ports from 0 to 65,535 to be accessed."

I think when using OUT instruction, the DX register is specify the IO port not the source operand.

dongli si
  • 13
  • 3
  • The destination is the IO port, not DX – Mat Feb 18 '22 at 11:06
  • @Mat Thanks, I corrected my question. – dongli si Feb 18 '22 at 11:29
  • How is DX not a source operand if it contains information used by the instruction? – Mat Feb 18 '22 at 11:30
  • @Mat The intel documentation describes it like this: Copies the value from the second operand (source operand) to the I/O port specified with the destination operand (first operand). – dongli si Feb 18 '22 at 11:37
  • Yeah, it calls it the destination operand in one sentence and the source operand in the next sentence. It has been this way since at least 2002. – prl Feb 18 '22 at 13:08
  • @harold, according to the first sentence of the description, it does. – prl Feb 18 '22 at 13:11

1 Answers1

1

What the manual attempts to say is true, even if the wording is a bit unclear.

When using an immediate parameter to specify the port number (like OUT imm8, AX), you are limited to ports 0-255 as the immediate operand is 8 bits.

When using DX to specify the port number (like OUT DX, EAX), all 65536 ports can be used.

The term 'source operand' is a bit misleading, as in the above example, the contents of EAX are output to the port specified by DX. So, the contents of DX specify the destination port number.

Sami Sallinen
  • 3,203
  • 12
  • 16
  • I get it, thanks. – dongli si Feb 18 '22 at 11:45
  • I wouldn't call it correct—it calls the first operand the destination operand in one sentence and the source operand in the following sentence. – prl Feb 18 '22 at 13:10
  • It's like a store instruction: all the registers involved are sources, and the actual destination is memory. (Or in this case, IO address space). Good point @prl on the inconsistent usage of "destination" (what the first operand normally is in x86) vs. "source" (based on what it's doing in a computer-science sense in this instruction). At least the first usage of "destination" clarifies they mean the first operand. https://www.felixcloutier.com/x86/out. If they said "the destination *port* can be specified ..." that would avoid the problem they have now. – Peter Cordes Feb 18 '22 at 20:53