c - Understanding input/output operands in GCC inline assembly syntax -


as part of writing os, implementing interrupt handling , i/o functions inb , outb.

i had learn writing inline assembly in gcc , read lot online. based on understanding, wrote own code. meanwhile, looked linux's implementation of functions /usr/include/sys/io.h. outb:

static __inline void outb (unsigned char __value, unsigned short int __port) {   __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "nd" (__port)); } 

here questions:

  • the gcc manual says "n"

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

but here __port unsigned short int believe 16 bits. how decided portion of 16 bits used in inline assembly ?

  • this understanding of how works - value of __port used directly (because of "n") constant in place of %w1. value of __value copied eax. %bo replaced %al. instruction executed. correct ?

  • how decided of "n" or "d" use second operand ? there preference order ?

  • what difference make if don't use "n" ? wouldn't using "d" better, since 16 bits ?

  • if omitted "n", correct value of __port copied edx , %w1 replaced edx ?

i may mistaken, understanding "nd" means use either n or d, @ compiler's preference. if value not known constant fits in 8 bits, n not satisfiable, compiler has no choice use d. when value compile-time constant , value fits in 8 bits, using 8-bit immediate preferable wasting register.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -