Brian
2005-12-04 01:33:26 UTC
All,
I just spent 30 minutes trying to work out why the code I wrote in NASM
doesn't work after I convert it to inline assembler. When I went to
compare the byte code outputs of both I realised I couldn't find the
inline assembly code anywhere. I know GCC was seeing it because I had
made a couple of typos in the ASM syntax and GCC was complaining about
that.
I looked at my other inline assembly code and each of them used the
'volatile' keyword as well, so I added that and suddenly my asm code
appeared in GCC's output.
I thought 'volatile' meant "don't change the order of this statement in
relation to the others around it" or similar. Why did GCC not output
the code at all without the 'volatile' keyword as well?
Here is the code, just in case it matters:
asm volatile (
" mov $0x378, %%dx \n" // specify the data port
" out %%al, %%dx \n" // write the letter
" mov $0x37A, %%dx \n" // specify the control port
" mov $0x00D, %%al \n" // tell the hardware to send
the data
" out %%al, %%dx \n"
" mov $0x00C, %%al \n" // tell the hardware to stop
sending the data
" out %%al, %%dx \n"
: /* output */
"=a" (theAttr) // value of eax is changed
: /* input */
"a" (theGlyph) // eax needs to have
'theGlyph' stored in it.
: /* clobber */
"edx" // edx is used by 'out' and
so is clobbered
);
While we're on the discussion, how do the double-underscore variants
differ from the ones I've used? I tried using those earlier but
resorted back to the non-underscore versions (can't recall why, maybe
it was just aesthetics after I'd proved to myself that they worked
similarly).
Thanks,
Brian.
I just spent 30 minutes trying to work out why the code I wrote in NASM
doesn't work after I convert it to inline assembler. When I went to
compare the byte code outputs of both I realised I couldn't find the
inline assembly code anywhere. I know GCC was seeing it because I had
made a couple of typos in the ASM syntax and GCC was complaining about
that.
I looked at my other inline assembly code and each of them used the
'volatile' keyword as well, so I added that and suddenly my asm code
appeared in GCC's output.
I thought 'volatile' meant "don't change the order of this statement in
relation to the others around it" or similar. Why did GCC not output
the code at all without the 'volatile' keyword as well?
Here is the code, just in case it matters:
asm volatile (
" mov $0x378, %%dx \n" // specify the data port
" out %%al, %%dx \n" // write the letter
" mov $0x37A, %%dx \n" // specify the control port
" mov $0x00D, %%al \n" // tell the hardware to send
the data
" out %%al, %%dx \n"
" mov $0x00C, %%al \n" // tell the hardware to stop
sending the data
" out %%al, %%dx \n"
: /* output */
"=a" (theAttr) // value of eax is changed
: /* input */
"a" (theGlyph) // eax needs to have
'theGlyph' stored in it.
: /* clobber */
"edx" // edx is used by 'out' and
so is clobbered
);
While we're on the discussion, how do the double-underscore variants
differ from the ones I've used? I tried using those earlier but
resorted back to the non-underscore versions (can't recall why, maybe
it was just aesthetics after I'd proved to myself that they worked
similarly).
Thanks,
Brian.