Page 2 of 2

Re: Bloody Beginner 2: __asm volatile

Posted: Thu Jul 10, 2008 1:37 pm
by hpclutz
Great, guys!!!

Thanks to all your help I got it working now with

Code: Select all

char inportb(short port)
{
	char ret_val;

	_asm {
		mov dx, port
		in al, dx
		mov ret_val, al
	}

	return ret_val;
}
So I got myself a neat little Command Line Interface with update cursor and everything ready, though I don't yet do more than just print the characters I type - nonetheless, it works 8)

Thanks guys, don't know what I would have done without you all =D>

(and I'm sure to be back with the next topic soon ;))

Re: Bloody Beginner 2: __asm volatile

Posted: Thu Jul 10, 2008 2:22 pm
by Adek336
cr2 wrote:

Code: Select all

char inb (short port) {
     char val;
     __asm {
          mov dx, port
          in  eax, dx
          mov val, al
     }
     return val;
}
EAX is 4-byte long; so this code actually reads 4 bytes from a port (instead of one byte). so "al" instead of "eax" is grand

Re: Bloody Beginner 2: __asm volatile

Posted: Thu Jul 10, 2008 2:26 pm
by Omega
That's great man, good job on getting your KBC Driver working!

Re: Bloody Beginner 2: __asm volatile

Posted: Fri Jul 11, 2008 7:48 am
by Solar
Just for the records, TR18015 and TR18037 added this nice tidbit to the C library:

Code: Select all

#include <iohw.h>

unsigned int iord( ioreg dev );
Why am I mentioning this? Two reasons:

1) If you happen to have an up-to-date C library ported to your system, you can use iord() instead of writing your own function with inline assembly.

I admit that's a fat chance, so how about...

2) if you write your function with inline assembly, why not call it iord() (instead of inb()) and declare it in a header called <iohw.h>?