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.
 

Linguofreak

Well-known member
Joined
May 10, 2008
Messages
5,017
Reaction score
1,253
Points
188
Location
Dallas, TX
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:

orb

O-F Administrator,
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
What does the error message say?
 

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,214
Reaction score
1,560
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
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
    }
}
 

thegrogen

New member
Joined
Jun 30, 2008
Messages
32
Reaction score
0
Points
0
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++.
 
Top