[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kernelnewbies
Subject:    Re: Help with assembly code
From:       John Levon <moz () compsoc ! man ! ac ! uk>
Date:       2000-07-27 14:39:51
[Download RAW message or body]

On Wed, 26 Jul 2000, Timur Tabi wrote:

> I'm trying to port some Intel-style assembly code to gcc, and I'm having a lot
> of difficulty with it.  Trying to use the kernel source code as examples only
> makes things worse.  For starters, could someone explain this line:
> 
> 	__asm__("movl %%gs,%0" : "=r"(tmp): "0"(tmp));
> 
> Questions:
> 
> 1. Why does %%gs have two parenthesis, but %0 has only one?
> 
> 2. What does "=r" mean?
> 
> 3. What do the colons do?
> 
> 

Timur, I highly recommend you read the info page for gcc (C
Extensions->Inline Asm)

this should explain everything for you. but off the top of my head

1) gas syntax has a % prefix for registers, but inline asm also uses %. so
you must escape % by doing %% to get movl %gs... in the final asm

2) this means that the result of the assembly is to place some output in a
general register (not sure, check "r" constraint in gcc info)

3) the format of the inline asm is

( "asm insns" : <output> : <input> : <clobbers> )

see the info page for more, ask here if you have trouble since trying to
explain this stuff wiill probably help me understand it better 

-- 
"All the passengers carry their seats out onto the tarmac,
 placing the chairs in the outline of a plane. They all sit down, flap
 their wings and make jet swooshing sounds as if they are flying." 
	- Windows NT Airlines

-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.surriel.com/kernelnewbies.shtml

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic