'Why does AT&T syntax use parens around DX in IN / OUT instructions like inb (%dx),%al

7c6f:   ec   in     (%dx),%al

Here my doubt is due to ()

Many places I wrote code this worked as take the value inside (%dx) and use it as memory location and value located there is value needed.

But here it should be doing just in %dx,%al ; and %dx hold port no Just like in 0x000,al



Solution 1:[1]

Your question is quite unclear, but I'll do my best to answer.

Using (%dx) as the first operand doesn’t work the way you think it does; for in and out,
(%dx) is not a memory operand, unlike how the same syntax is used for operands to other instructions.

The IN instruction takes two operands:

  1. An immediate 8-bit value (like $0x42) or the DX register.

  2. AL, AX, or EAX.

This means you cannot use a memory location for either operand.

Also, as seen in @PeterCordes’s answer, using %dx as a memory address is never valid.

For these two reasons, (%dx) cannot be interpreted as a memory address, so your assembler instead ignores the parentheses and interprets it as the register %dx alone.

That means in (%dx),%al is exactly the same as in %dx,%al.

If you want to take input from a port number stored in memory, you must first load the value into the %dx register:

mov (%something),%dx
in %dx,%al

For more information, consult page 3-494 in Volume 2A of the Intel IA-32 reference manual, or this reference page.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Cordes