Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm.

4 views
Skip to first unread message

Johnny Hung

unread,
Nov 19, 2009, 5:00:02 AM11/19/09
to
Hi All:
I want to move two local valuables to x86 arch CPU ebx, ecx
register and do outb cpu instruction by using AT&A inline asm in
kernel driver. The following code was I wrote but gcc report syntax
error:
==
unsigned int val = 10;
unsigned int tmp = 5;
....
__asm__ volatile ("movl %0, %%ebx"
"movl %1, %%ecx"
"outb $0x27, $0xb2"
:
:"r"(val), "r"(tmp)
:"%ebx", "%ecx"
);

Does anyone can point me out. Any reply is appreciated.

BRs, H. Johnny
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Viral Mehta

unread,
Nov 19, 2009, 5:10:01 AM11/19/09
to
How about putting \n at the end ?

Just try out,

__asm__ volatile ("movl %0, %%ebx\n"
"movl %1, %%ecx\n"


Thanks,
Viral Mehta,
Embedded Software Engineer,
Tel. No. 91 79 26563705, Ext. 423
www.einfochips.com <http://www.einfochips.com>
Prepare and Prevent rather than Repair and Repent


Johnny Hung wrote:
> Hi All:
> I want to move two local valuables to x86 arch CPU ebx, ecx
> register and do outb cpu instruction by using AT&A inline asm in
> kernel driver. The following code was I wrote but gcc report syntax
> error:
> ==
> unsigned int val = 10;
> unsigned int tmp = 5;
> ....
> __asm__ volatile ("movl %0, %%ebx"
> "movl %1, %%ecx"
> "outb $0x27, $0xb2"
> :
> :"r"(val), "r"(tmp)
> :"%ebx", "%ecx"
> );
>
> Does anyone can point me out. Any reply is appreciated.
>
> BRs, H. Johnny
>
> --

> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to eca...@nl.linux.org
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>
>
> Email Scanned for Virus & Dangerous Content by : www.CleanMailGateway.com
>
>
>
--
_____________________________________________________________________
Disclaimer: This e-mail message and all attachments transmitted with it
are intended solely for the use of the addressee and may contain legally
privileged and confidential information. If the reader of this message
is not the intended recipient, or an employee or agent responsible for
delivering this message to the intended recipient, you are hereby
notified that any dissemination, distribution, copying, or other use of
this message or its attachments is strictly prohibited. If you have
received this message in error, please notify the sender immediately by
replying to this message and please delete it from your computer. Any
views expressed in this message are those of the individual sender
unless otherwise stated.Company has taken enough precautions to prevent
the spread of viruses. However the company accepts no liability for any
damage caused by any virus transmitted by this email.
_____________________________________________________________________

Johnny Hung

unread,
Nov 19, 2009, 5:30:02 AM11/19/09
to
It doesn't works. :(

2009/11/19 Viral Mehta <viral...@einfochips.com>:

Américo Wang

unread,
Nov 20, 2009, 1:50:01 AM11/20/09
to
On Thu, Nov 19, 2009 at 5:50 PM, Johnny Hung <johnny....@gmail.com> wrote:
> Hi All:
>    I want to move two local valuables to x86 arch CPU ebx, ecx
> register and do outb cpu instruction by using AT&A inline asm in
> kernel driver.  The following code was I wrote but gcc report syntax
> error:

You must mean AT&T.

> ==
>    unsigned int val = 10;
>    unsigned int tmp = 5;
>    ....
>    __asm__ volatile ("movl %0, %%ebx"

You need to put "\n\t" in the end of each asm statement.

>          "movl %1, %%ecx"
>          "outb $0x27, $0xb2"


This is wrong, 'outb' instruction cann't accept both of
its operands as constants, IIRC.

>          :
>          :"r"(val), "r"(tmp)
>          :"%ebx", "%ecx"
>   );
>
> Does anyone can point me out. Any reply is appreciated.

Regards.

Jiri Slaby

unread,
Nov 20, 2009, 3:50:02 AM11/20/09
to
On 11/19/2009 10:50 AM, Johnny Hung wrote:
> Hi All:
> I want to move two local valuables to x86 arch CPU ebx, ecx
> register and do outb cpu instruction by using AT&A inline asm in
> kernel driver. The following code was I wrote but gcc report syntax
> error:
> ==
> unsigned int val = 10;
> unsigned int tmp = 5;
> ....
> __asm__ volatile ("movl %0, %%ebx"
> "movl %1, %%ecx"
> "outb $0x27, $0xb2"
> :
> :"r"(val), "r"(tmp)
> :"%ebx", "%ecx"
> );
>
> Does anyone can point me out. Any reply is appreciated.

Why not just:
("outb $0x27, %%al" : : "a" (0xb2), "b"(val), "c" (tmp));
--
js
Faculty of Informatics, Masaryk University
Suse Labs, Novell

Johnny Hung

unread,
Nov 22, 2009, 10:20:01 PM11/22/09
to
After testing:

# gcc inlineasm.c
inlineasm.c: Assembler messages:
inlineasm.c:7: Error: suffix or operands invalid for `out'
[root@debian-johnny] ~/workspace/test

# cat inlineasm.c
#include <stdio.h>

int main ()
{
unsigned int val = 5, tmp = 10;
asm volatile ("outb $0x27, %%al"


:
: "a" (0xb2), "b"(val), "c" (tmp)
);
}

It seems the source of outb instruction cannot be a constant. Is
there a AT&T instructions document for x86?

BRs, H. Johnny

Brian Gerst

unread,
Nov 23, 2009, 12:50:01 AM11/23/09
to
On Sun, Nov 22, 2009 at 10:14 PM, Johnny Hung <johnny....@gmail.com> wrote:
> After testing:
>
> # gcc inlineasm.c
> inlineasm.c: Assembler messages:
> inlineasm.c:7: Error: suffix or operands invalid for `out'
> [root@debian-johnny] ~/workspace/test
>
> # cat inlineasm.c
> #include <stdio.h>
>
> int main ()
> {
>    unsigned int val = 5, tmp = 10;
>    asm volatile ("outb $0x27, %%al"
>     :
>     : "a" (0xb2), "b"(val), "c" (tmp)
>    );
> }
>
>    It seems the source of outb instruction cannot be a constant. Is
> there a AT&T instructions document for x86?

In AT&T syntax, the source register comes first. So it should be
"outb %%al, $0x27", assuming that 0x27 is the port number you are
trying to write to.

--
Brian Gerst

0 new messages