Re: how to insert an asm instruction in C code and how to compile it

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use gcc inline assembly

Nothing extra needed in compilation just gcc hello.c
eg:-

                 asm mov ah,0x0E;
asm volatile("mov $0x0E,%ah"

Read online documentation (google) regarding gcc inline assembly and 
at&t assembly notation.
It is quite opposite to Intel ASM Notation
eg-
   mov ah,0x0E (INTEL ASSEMBLER SYNTAX)
  is
  mov  $0x0e,%ah (AT&T used by GCC)

Here is a example
compilation is gcc file.c 
./a.out
-----------------------------------
#include <stdio.h>

int a=10;
int b=20;
int result;

int main()
{
        asm(    "movl   a,%eax\n\t"
                "movl   b,%ebx\n\t"
                "imull  %ebx,%eax\n\t"
                "movl   %eax,result\n\t"
        );

        printf("%d*%d=%d\n",a,b,result);
        return 0;
}
~

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux