Question C coding- impossible constraint in 'asm'

luki1997a

Active member
Joined
Dec 9, 2010
Messages
314
Reaction score
0
Points
31
Location
Biłgoraj
Hello:hello:
I've started my adventures with C coding:lol: I'm going to make a simple and easy kernel. I'm using DevC++ and I've got a problem described in title.

Code:
Code:
unsigned char inportb (unsigned short _port)
{
    unsigned char rv;
[COLOR="DarkOrange"]    __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));[/COLOR]
    return rv;
}

void outportb (unsigned short _port, unsigned char _data)
{
    __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}

Problem happes at coloured line. Any suggestions? I'm new to C.
 
I myself have done very little with C and nothing with inline assembly, but after reading up on the topic can't find any glaringly obvious errors.

Anyhow, the code compiles without error under gcc or g++ on Linux. Perhaps it's a bug in your compiler?

Of course, as I said, I have almost no knowledge of the subject, so it could be that something is wrong with the code that I don't know about, and that it is in fact a bug in gcc that allows it to compile for me at all.
 
Last edited:
What does the error message say?
 
Try this (this is under Microsoft Visual Studio, though, so it may take a few tweaks for your C compiler version):

Code:
unsigned char inportb (unsigned short _port)
{
    unsigned char rv;
    __asm 
    {
        mov dx, [_port]
        in al, dx
        mov [rv], al
    }
    
    return rv;
}

Or better yet, you can drop rv entirely since the return code is already in al:

Code:
unsigned char inportb (unsigned short _port)
{
    __asm 
    {
        mov dx, [_port]
        in al, dx     ; al is the return code
    }
}
 
It could very well be a compiler bug. The compiler that ships with Dev-C++ is about 5-6 years out of date at this point. This is why the use of Dev-C++ is usually recommended against by people who write a lot of C and C++.
 
Back
Top