c - GCC Inline Assembly 'Nd' constraint -


i'm developing small toy kernel in c. i'm @ point need user input keyboard. far, have implemented inb using 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 "=a" constraint means al/ax/eax copied ret output, i'm still confused "nd" constraint. can provide insight on why constraint necessary? or why can't use general purpose register constraint "r" or "b"? appreciated.

the in instruction (returning byte) can either take immediate 8 bit value port number, or port specified in dx register. more on in instruction can found in instruction reference (intel syntax) . machine constraints being used can found in gcc docs . if scroll down x86 family you'll see:

d

the d register 

n

unsigned 8-bit integer constant (for in , out instructions).  

Comments