wrriting outp function in MSVC++

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.
Post Reply
psnix
Member
Member
Posts: 50
Joined: Fri Oct 24, 2008 12:34 pm

wrriting outp function in MSVC++

Post by psnix »

hi

I'm try to develop my own os and i try to develop conio library for my os in visual studio 2008. i developed must of importants functions that i need, but i can't write outp and inp functions!!!

where is my wrong in this function?! ( I'm working in protected mode)

void outp(unsigned portid,int value)
{
_asm
{
mov edx,[portid]
mov eax,[value]
out dx,eax
}
}

sorry for my bad english
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: wrriting outp function in MSVC++

Post by ru2aqare »

Why not use

Code: Select all


extern "C" {
{
void    __outbyte(unsigned short Port, unsigned char Data);
#pragma intrinsic(__outbyte)
}

inline void outp(unsigned portid,int value) { __outbyte(portid, value); }
if you are using MSVC? Its faster and you don't have to write a single line of assembler.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: wrriting outp function in MSVC++

Post by neon »

Heres my routines if you want to try them:

Code: Select all

// read byte from port
inline	unsigned char _cdecl inportb (unsigned short portid) {

	unsigned char res=0;

	_asm {
		mov dx, [portid]
		in	al, dx
		mov [res], al
	}

	return res;
}

// write byte to port
inline	void _cdecl outportb (unsigned short portid, unsigned char value) {

	_asm {
		mov	al, [value]
		mov	dx, [portid]
		out	dx, al
	}
}
It doesnt really matter if you decide to use intrinsics or not as they both rely on compiler dependent code.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply