GCC Inline Assembly 'Nd' restriction

I am developing a small toy core in C. I am at the point where I need to get user input from the keyboard. So far I have implemented inbusing the following code:

static inline uint8_t inb(uint16_t port) {
     uint8_t ret;
     asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
     return ret;
}

I know that a constraint "=a"means it al/ax/eaxwill be copied to retas output, but I'm still confused about the constraint "Nd". Can someone give an idea of ​​why this restriction is necessary? Or why can't I just use a general purpose constraint like "r"or "b"? Any help would be appreciated.

+4
source share
1 answer

The instruction in(byte return) can immediately take an 8-bit value as the port number or port specified in the register dx. More information about the instructions incan be found in the instructions for instructions (Intel syntax). Used machine restrictions can be found in the GCC docs . If you scroll down to x86 family, you will see:

d

The d register

N

Unsigned 8-bit integer constant (for in and out instructions). 
+6
source

Source: https://habr.com/ru/post/1609051/


All Articles