Bloody Beginner 2: __asm volatile

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
hpclutz
Posts: 19
Joined: Tue Jul 08, 2008 11:30 am

Re: Bloody Beginner 2: __asm volatile

Post 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 ;))
User avatar
Adek336
Member
Member
Posts: 129
Joined: Thu May 12, 2005 11:00 pm
Location: Kabaty, Warszawa
Contact:

Re: Bloody Beginner 2: __asm volatile

Post 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
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: Bloody Beginner 2: __asm volatile

Post by Omega »

That's great man, good job on getting your KBC Driver working!
Free energy is indeed evil for it absorbs the light.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Bloody Beginner 2: __asm volatile

Post 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>?
Every good solution is obvious once you've found it.
Post Reply