????GCC???????(INLINE ASSEMBLY)
???????????????Inline assembly???
????1??????GCC??C??????????????C?????????д??????
????2???????????C??????в????????
?????к??????
????1??C????????????????CPU????? ????????Щ?????????????gdt??(Global Descriptor Table ???????????)??????????????????
????2????????C?????????????????????????????У?????????????????????????????
??????ι?????
????1???????????????????????????
????2????C???????γ??????
???????????С??????????????????????????????
????GCC???????-Example 1
?????????? Assembly(*.S):
????movl $0xffff?? %eax     //??0xffff??eax
??????????? Inline assembly(*.c):
????asm("movl $0xffff?? %%eax ")    //1????????????????????asm?????????????????????????????????? 2???????????%%
????GCC???????-??
????asm("assmbler template"               //assmbler template??example 1 ???????????????????????
????:output operands (optional)????//??????????????????????????
????:input operands   (optional)????//??????????????????????????
????:clobbers              (optional)????//??????????
????);
????GCC???????-Example2
????Inline assembly(*.c)
????uint32_t cr0;??????????????????????????????????  //?????cr0?????
????asm volatile("movl %%cr0?? %0 " :"=r"(cr0));?? ??//??cr0????????????%0???????????У? =r?????????????????cr0??????????????????
????cr0 |= 0x80000000;??????????????????????????    //??????λ???1
????asm volatile("movl %0?? %%cr0 " ::"r"(cr0));????  //???cr0???????????д???cr0????????С???cr0????????????????????????????????????????cr0????????????????
?????Щ?????????
????volatile:No reordering; No elimination. ???????????????????????????????????
????%0????:The first constraint following. ??????????????
????r?????? :A constraint; GCC is free to use any register. ????????????
????????????????????????????????
????Generated assembly code(*.s):
????movl %cr0?? %ebx                             //cr0 --> ebx
????movl %ebx?? 12(%esp)                     //ebx??????????????12(%esp)
????orl    $-2147483648?? 12(%esp)       //?????
????movl 12(%esp)?? %eax                     //???eax
????movl %eax?? %cr0????????????????//???eax?????????????????cr0
????GCC???????-Example3
????Inline assembly(*.c)
????long _res?? arg1 = 2?? arg2 = 22?? arg3 = 222?? arg4 = 233;
????_asm_volatile("int $0x80"
????:"=a"(_res)
????:"0"(11)?? "b"(arg1)?? "c"(arg2)?? "d"(arg3)?? "S"(arg4));    //??arg1??ebx?? arg2??ecx??arg3??edx?? arg4??esi
???????????????
????a = %eax?? b = %ebx?? c = %ecx?? d = %edx?? S = %esi?? D = %edi?? 0 = same as the first ??????????????
????Generated assembly code(*.s):
????mov $11?? %eax
????movl-28(%ebp)?? %ebx
????movl-24(%ebp)?? %ecx
????movl-20(%ebp)?? %edx
????movl-16(%ebp)?? %esi
????int $0x80
????movl %edi?? -12(%ebp)