?????????GCC???????
???????????? ???????[ 2016/2/3 10:55:09 ] ????????GCC ??????
????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)
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11