LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   How add assebly in linux kernel module program? (https://www.linuxquestions.org/questions/linux-kernel-70/how-add-assebly-in-linux-kernel-module-program-706938/)

aminoamide 02-23-2009 03:02 PM

How add assebly in linux kernel module program?
 
Hello,

I am writing a linux kernel module program on Fedora core 6 and I am wondering if anyone could tell me how to add an assembly code shown below in my program. The assembly code was written for Windows and I have no idea how to convert to Linux kernel program.

#ifdef _MSC_VER

Unsigned char lookKbits(char k)
{
_asm {
mov dl, k
mov cl, 16
sub cl, dl
mov eax, [wordval]
shr eax, cl
}
}

Unsigned char WORD_hi_lo(char byte_high, char byte_low)
{
_asm {
mov ah,byte_high
mov al,byte_low
}
}
#endif

ErV 02-24-2009 04:56 AM

See C compiler documentation - because assembly format within C code differs on GCC/MSVC.
However you shouldn't use assembly in kernel modules - this makes modules non-portable (to other compilers and/or architectures). I recommend to use C instead, (because modern compiler can do better job optimizing code).

Suresh Maniyath 02-24-2009 08:13 AM

It is not recommended to use assembly coding. But to answer your question, GCC follows the standard as below.

__asm__ __volatile__ (assembler template
: output operands
: input operands
: list of clobbered registers
);

Regards,
Suresh Maniyath

XavierP 02-24-2009 10:39 AM

Moved: This thread is more suitable in Linux-Kernel and has been moved accordingly to help your thread/question get the exposure it deserves.


All times are GMT -5. The time now is 09:00 PM.