- 论坛徽章:
- 0
|
C嵌入汇编 GCC1.4
///////////////////////////////////////////////////////
#define _fs()({\
register unsigned short __res;\
__asm__("mov %%fs,%%ax":"=a"(__res):);\
__res;})
#define get_seg_long(seg,addr)({ \
register unsigned long __res; \
__asm__("push %%fs\n\t" \
"mov %%ax,%%fs\n\t" \
"movl %%fs:%2,%%eax\n\t" \
"pop %%fs\n\t" \
:"=a"(__res) \
:"0"(seg),"m"(*(addr)) \
:"ax"); \
__res;})
void main(void)
{
int a, b;
a = 12; b = 32;
_fs();
get_seg_long(1,&b);
}
///////////////////////////////////////////////////////
.file "test.c"
gcc_compiled.:
.text
.align 2
.globl _main
_main:
pushl %ebp
movl %esp,%ebp
subl $12,%esp
movl $12,-4(%ebp)
movl $32,-8(%ebp)
/APP
mov %fs,%ax
/NO_APP
movw %ax,-12(%ebp)
movl $1,%eax
/APP
push %fs
mov %ax,%fs
movl %fs:-8(%ebp),%eax
pop %fs
/NO_APP
movl %eax,%edx
L1:
leave
ret
\
__res;})
//////////////////////////////////////////////////////////
反斜杠后不能有空格,如果没有会被修改的寄存器则冒号也要去掉
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/46595/showart_366922.html |
|