Page 1 of 1

wrriting outp function in MSVC++

Posted: Wed Nov 12, 2008 6:49 am
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

Re: wrriting outp function in MSVC++

Posted: Wed Nov 12, 2008 7:50 am
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.

Re: wrriting outp function in MSVC++

Posted: Wed Nov 12, 2008 4:59 pm
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.