Question about assembly in set bit function for x86 architecture

Jeff Haran Jeff.Haran at citrix.com
Mon Apr 20 12:27:43 EDT 2015


> -----Original Message-----
> From: kernelnewbies-bounces+jharan=bytemobile.com at kernelnewbies.org
> [mailto:kernelnewbies-
> bounces+jharan=bytemobile.com at kernelnewbies.org] On Behalf Of nick
> Sent: Sunday, April 19, 2015 1:51 PM
> To: kernelnewbies
> Subject: Question about assembly in set bit function for x86 architecture
> 
> Greetings All,
> I am wondering what the below code in the asm modifier does:
> static inline void set_bit(int nr, void *addr) {
>          asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr)); } This would be very
> helpful as I am new to  x86 assembly and don't even known what
> register(s)/instruction(s) this touches and therefore this is impossible for me
> to look up in the Intel Manuals. If someone either tells me the
> registers/instructions this uses or explains the code that would be very
> helpful.
> Nick

You are dealing with 2 levels of complexity here. First, there's what the actual generated assembly code is doing. For that you'll want to get the Intel manuals but you can get started with the Wikipedia on x86 assembly. Be forewarned, there's two different standards for the syntax here, AT&T's and Intel's, so you'll want to become familiar with the differences between them so you know which one you are reading.

The second level is the embedded assembly-in-C syntax, which is the glue that links C to assembly. What I do whenever I need to read this stuff is I go ahead and compile the code in question then use objdump -S on the .o file to dump the assembly intermixed with the C source. That means I don't have to decipher what that second level is doing. With the original C source and the generated assembly, I can usually figure out what it's doing.

Jeff Haran




More information about the Kernelnewbies mailing list