锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
璁╂垜浠鍏堢湅涓涓?Linux 涓嬌鐢ㄧ殑鍩烘湰姹囩紪紼嬪簭璇硶銆侴CC錛堢敤浜?Linux 鐨? GNU C 緙栬瘧鍣級浣跨敤 AT&T 姹囩紪璇硶銆備笅闈㈠垪鍑轟簡榪欑璇硶鐨勪竴浜涘熀鏈鍒欍傦紙璇ュ垪琛ㄨ偗瀹氫笉瀹屾暣錛涘彧鍖呮嫭浜嗕笌鍐呰仈姹囩紪鐩稿叧鐨勯偅浜涜鍒欍傦級
瀵勫瓨鍣ㄥ懡鍚?/strong>
瀵勫瓨鍣ㄥ悕縐版湁 % 鍓嶇紑銆傚嵆錛屽鏋滃繀欏諱嬌鐢?eax錛屽畠搴旇鐢ㄤ綔 %eax銆?
婧愭搷浣滄暟鍜岀洰鐨勬搷浣滄暟鐨勯『搴?/strong>
鍦ㄦ墍鏈夋寚浠や腑錛屽厛鏄簮鎿嶄綔鏁幫紝鐒跺悗鎵嶆槸鐩殑鎿嶄綔鏁般傝繖涓庡皢婧愭搷浣滄暟鏀懼湪鐩殑鎿嶄綔鏁頒箣鍚庣殑
Intel 璇硶涓嶅悓銆?
mov %eax, %ebx, transfers the contents of eax to ebx. |
鎿嶄綔鏁板ぇ灝?/strong>
鏍規(guī)嵁鎿嶄綔鏁版槸瀛楄妭 (byte)銆佸瓧 (word) 榪樻槸闀垮瀷
(long)錛屾寚浠ょ殑鍚庣紑鍙互鏄?b銆亀 鎴?l銆傝繖騫朵笉鏄己鍒舵х殑錛汫CC
浼?xì)灏濊瘯閫氳繃璇誨彇鎿嶄綔鏁版潵鎻愪緵鐩稿簲鐨勫悗緙銆備絾鎵嬪伐鎸囧畾鍚庣紑鍙互鏀瑰杽浠g爜鐨勫彲璇繪э紝騫跺彲浠ユ秷闄ょ紪璇戝櫒鐚滄祴涓嶆紜殑鍙兘鎬с?
movb %al, %bl -- Byte move |
绔嬪嵆鎿嶄綔鏁?/strong>
閫氳繃浣跨敤 $ 鎸囧畾鐩存帴鎿嶄綔鏁般?
movl $0xffff, %eax -- will move the value of 0xffff into eax register. |
闂存帴鍐呭瓨寮曠敤
浠諱綍瀵瑰唴瀛樼殑闂存帴寮曠敤閮芥槸閫氳繃浣跨敤 ( ) 鏉ュ畬鎴愮殑銆?
movb (%esi), %al -- will transfer the byte in the memory |
GCC 涓哄唴鑱旀眹緙栨彁渚涚壒孌婄粨鏋勶紝瀹冨叿鏈変互涓嬫牸寮忥細(xì)
GCG 鐨?"asm" 緇撴瀯
asm ( assembler template |
鏈緥涓紝姹囩紪紼嬪簭妯℃澘鐢辨眹緙栨寚浠ょ粍鎴愩傝緭鍏ユ搷浣滄暟鏄厖褰撴寚浠よ緭鍏ユ搷浣滄暟浣跨敤鐨? C 琛ㄨ揪寮忋傝緭鍑烘搷浣滄暟鏄皢瀵瑰叾鎵ц姹囩紪鎸囦護(hù)杈撳嚭鐨?C 琛ㄨ揪寮忋?/p>
鍐呰仈姹囩紪鐨勯噸瑕佹т綋鐜板湪瀹冭兘澶熺伒媧繪搷浣滐紝鑰屼笖鍙互浣垮叾杈撳嚭閫氳繃 C 鍙橀噺鏄劇ず鍑烘潵銆傚洜涓哄畠鍏鋒湁榪欑鑳藉姏錛屾墍浠?"asm" 鍙互鐢ㄤ綔姹囩紪鎸囦護(hù)鍜屽寘鍚畠鐨?C 紼嬪簭涔嬮棿鐨勬帴鍙c?/p>
涓涓潪甯稿熀鏈絾寰堥噸瑕佺殑鍖哄埆鍦ㄤ簬 綆鍗曞唴鑱旀眹緙?/em>鍙寘鎷寚浠わ紝鑰? 鎵╁睍鍐呰仈姹囩紪鍖呮嫭鎿嶄綔鏁般傝璇存槑榪欎竴鐐癸紝鑰冭檻浠ヤ笅紺轟緥錛?
鍐呰仈姹囩紪鐨勫熀鏈绱?/strong>
{ |
鍦ㄤ笂渚嬩腑錛屾垜浠嬌鐢ㄦ眹緙栨寚浠や嬌 "b" 鐨勫肩瓑浜? "a"銆傝娉ㄦ剰浠ヤ笅鍑犵偣錛?/p>
movl %1, %%eax
灝?"a" 鐨勫肩Щ鍒?%eax
涓紝
movl %%eax, %0
灝?%eax 鐨勫唴瀹圭Щ鍒?
"b" 涓?
鐜板湪璁╂垜浠洿璇︾粏鐨勪簡瑙f瘡涓欏圭殑鍚箟銆?/p>
姹囩紪紼嬪簭妯℃澘鏄竴緇勬彃鍏ュ埌 C 紼嬪簭涓殑姹囩紪鎸囦護(hù)錛堝彲浠ユ槸鍗曚釜鎸囦護(hù)錛屼篃鍙互鏄竴緇勬寚浠わ級銆傛瘡鏉℃寚浠ら兘搴旇鐢卞弻寮曞彿鎷搗錛屾垨鑰呮暣緇勬寚浠ゅ簲璇ョ敱鍙屽紩鍙鋒嫭璧楓傛瘡鏉℃寚浠よ繕搴旇鐢ㄤ竴涓畾鐣岀緇撳熬銆傛湁鏁堢殑瀹氱晫絎︿負(fù)鏂拌 (\n) 鍜屽垎鍙?(;)銆?'\n' 鍚庡彲浠ヨ窡涓涓?tab(\t) 浣滀負(fù)鏍煎紡鍖栫鍙鳳紝澧炲姞 GCC 鍦ㄦ眹緙栨枃浠朵腑鐢熸垚鐨勬寚浠ょ殑鍙鎬с?鎸囦護(hù)閫氳繃鏁?%0銆?1 絳夋潵寮曠敤 C 琛ㄨ揪寮忥紙鎸囧畾涓烘搷浣滄暟錛夈?/p>
濡傛灉甯屾湜紜繚緙栬瘧鍣ㄤ笉浼?xì)鍦?"asm" 鍐呴儴浼樺寲鎸囦護(hù)錛屽彲浠ュ湪 "asm" 鍚庝嬌鐢ㄥ叧閿瓧 "volatile"銆傚鏋滅▼搴忓繀欏諱笌 ANSI C 鍏煎錛屽垯搴旇浣跨敤 __asm__ 鍜?__volatile__錛岃屼笉鏄?asm 鍜?volatile銆?/p>
C 琛ㄨ揪寮忕敤浣?"asm" 鍐呯殑姹囩紪鎸囦護(hù)鎿嶄綔鏁般傚湪姹囩紪鎸囦護(hù)閫氳繃瀵?C 紼嬪簭鐨?C 琛ㄨ揪寮忚繘琛屾搷浣滄潵鎵ц鏈夋剰涔夌殑浣滀笟鐨勬儏鍐典笅錛屾搷浣滄暟鏄唴鑱旀眹緙栫殑涓昏鐗規(guī)с?/p>
姣忎釜鎿嶄綔鏁伴兘鐢辨搷浣滄暟綰︽潫瀛楃涓叉寚瀹氾紝鍚庨潰璺熺敤鎷姬鎷搗鐨?C 琛ㄨ揪寮忥紝渚嬪錛?constraint" (C expression)銆傛搷浣滄暟綰︽潫鐨勪富瑕佸姛鑳芥槸紜畾鎿嶄綔鏁扮殑瀵誨潃鏂瑰紡銆?/p>
鍙互鍦ㄨ緭鍏ュ拰杈撳嚭閮ㄥ垎涓悓鏃朵嬌鐢ㄥ涓搷浣滄暟銆傛瘡涓搷浣滄暟鐢遍楀彿鍒嗛殧寮銆?/p>
鍦ㄦ眹緙栫▼搴忔ā鏉垮唴閮紝鎿嶄綔鏁扮敱鏁板瓧寮曠敤銆傚鏋滄誨叡鏈? n 涓搷浣滄暟錛堝寘鎷緭鍏ュ拰杈撳嚭錛夛紝閭d箞絎竴涓緭鍑烘搷浣滄暟鐨勭紪鍙蜂負(fù) 0錛岄愰」閫掑錛屾渶鍚庨偅涓緭鍏ユ搷浣滄暟鐨勭紪鍙蜂負(fù) n -1銆傛繪搷浣滄暟鐨勬暟鐩檺鍒跺湪 10錛屽鏋滄満鍣ㄦ弿榪頒腑浠諱綍鎸囦護(hù)妯″紡涓殑鏈澶ф搷浣滄暟鏁扮洰澶т簬 10錛屽垯浣跨敤鍚庤呬綔涓洪檺鍒躲?
濡傛灉 "asm" 涓殑鎸囦護(hù)鎸囩殑鏄‖浠跺瘎瀛樺櫒錛屽彲浠ュ憡璇?GCC 鎴戜滑灝嗚嚜宸變嬌鐢ㄥ拰淇敼瀹冧滑銆傝繖鏍鳳紝GCC 灝變笉浼?xì)鍋囪畱之冭鍏ュ埌杩欎簺瀵勫瓨鍣ㄤ腑鐨勫兼槸鏈夋晥鍊箋傞氬父涓嶉渶瑕佸皢杈撳叆鍜岃緭鍑哄瘎瀛樺櫒鍒椾負(fù) clobbered錛屽洜涓?GCC 鐭ラ亾 "asm" 浣跨敤瀹冧滑錛堝洜涓哄畠浠鏄庣‘鎸囧畾涓虹害鏉燂級銆備笉榪囷紝濡傛灉鎸囦護(hù)浣跨敤浠諱綍鍏跺畠鐨勫瘎瀛樺櫒錛屾棤璁烘槸鏄庣‘鐨勮繕鏄殣鍚殑錛堝瘎瀛樺櫒涓嶅湪杈撳叆綰︽潫鍒楄〃涓嚭鐜幫紝涔熶笉鍦ㄨ緭鍑虹害鏉熷垪琛ㄤ腑鍑虹幇錛夛紝瀵勫瓨鍣ㄩ兘蹇呴』琚寚瀹氫負(fù)淇グ鍒楄〃銆備慨楗板瘎瀛樺櫒鍒楀湪絎笁涓啋鍙蜂箣鍚庯紝鍏跺悕縐拌鎸囧畾涓哄瓧絎︿覆銆?/p>
鑷充簬鍏抽敭瀛楋紝濡傛灉鎸囦護(hù)浠ユ煇浜涗笉鍙鐭ヤ笖涓嶆槑紜殑鏂瑰紡淇敼浜嗗唴瀛橈紝鍒欏彲鑳藉皢 "memory" 鍏抽敭瀛楁坊鍔犲埌淇グ瀵勫瓨鍣ㄥ垪琛ㄤ腑銆傝繖鏍峰氨鍛婅瘔 GCC 涓嶈鍦ㄤ笉鍚屾寚浠や箣闂村皢鍐呭瓨鍊奸珮閫熺紦瀛樺湪瀵勫瓨鍣ㄤ腑銆?/p>
鍓嶉潰鎻愬埌榪囷紝"asm" 涓殑姣忎釜鎿嶄綔鏁伴兘搴旇鐢辨搷浣滄暟綰︽潫瀛楃涓叉弿榪幫紝鍚庨潰璺熺敤鎷姬鎷搗鐨?C 琛ㄨ揪寮忋傛搷浣滄暟綰︽潫涓昏鏄‘瀹氭寚浠や腑鎿嶄綔鏁扮殑瀵誨潃鏂瑰紡銆傜害鏉熶篃鍙互鎸囧畾錛?/p>
綰︽潫榪樿姹備袱涓搷浣滄暟鍖歸厤銆?/p>
鍦ㄥ彲鐢ㄧ殑鎿嶄綔鏁扮害鏉熶腑錛屽彧鏈変竴灝忛儴鍒嗘槸甯哥敤鐨勶紱涓嬮潰鍒楀嚭浜嗚繖浜涚害鏉熶互鍙?qiáng)绠瑕佹弿榪般傛湁鍏蟲搷浣滄暟綰︽潫鐨勫畬鏁村垪琛紝璇峰弬鑰? GCC 鍜?GAS 鎵嬪唽銆?/p>
瀵勫瓨鍣ㄦ搷浣滄暟綰︽潫 (r)
浣跨敤榪欑綰︽潫鎸囧畾鎿嶄綔鏁版椂錛屽畠浠瓨鍌ㄥ湪閫氱敤瀵勫瓨鍣ㄤ腑銆傝鐪嬩笅渚嬶細(xì)
asm ("movl %%cr3, %0\n" :"=r"(cr3val)); |
榪欓噷錛屽彉閲?cr3val 淇濆瓨鍦ㄥ瘎瀛樺櫒涓紝%cr3 鐨勫煎鍒跺埌瀵勫瓨鍣ㄤ笂錛宑r3val 鐨勫間粠璇ュ瘎瀛樺櫒鏇存柊鍒板唴瀛樹腑銆傛寚瀹?"r" 綰︽潫鏃訛紝GCC 鍙互灝嗗彉閲?cr3val 淇濆瓨鍦ㄤ換浣曞彲鐢ㄧ殑 GPR 涓傝鎸囧畾瀵勫瓨鍣紝蹇呴』閫氳繃浣跨敤鐗瑰畾鐨勫瘎瀛樺櫒綰︽潫鐩存帴鎸囧畾瀵勫瓨鍣ㄥ悕銆?/p>
a %eax |
鍐呭瓨鎿嶄綔鏁扮害鏉?(m)
褰撴搷浣滄暟浣嶄簬鍐呭瓨涓椂錛屼換浣曞瀹冧滑鎵ц鐨勬搷浣滈兘灝嗗湪鍐呭瓨浣嶇疆涓洿鎺ュ彂鐢燂紝榪欎笌瀵勫瓨鍣ㄧ害鏉熸濂界浉鍙嶏紝鍚庤呭厛灝嗗煎瓨鍌ㄥ湪瑕佷慨鏀圭殑瀵勫瓨鍣ㄤ腑錛岀劧鍚庡皢瀹冨啓鍥炲唴瀛樹綅緗腑銆備絾瀵勫瓨鍣ㄧ害鏉熼氬父鍙湪瀵逛簬鎸囦護(hù)鏉ヨ瀹冧滑鏄粷瀵瑰繀闇鐨勶紝鎴栬呭畠浠彲浠ュぇ澶ф彁楂樿繘紼嬮熷害鏃朵嬌鐢ㄣ傚綋闇瑕佸湪
"asm" 鍐呴儴鏇存柊 C
鍙橀噺錛岃屾?zhèn)ㄥ張纭疄涓嶅笇鏈涗娇鐢ㄥ瘎瀛樺櫒鏉ヤ繚瀛樺叾鍊兼椂錛屼嬌鐢ㄥ唴瀛樼害鏉熸渶涓烘湁鏁堛備緥濡傦紝idtr
鐨勫煎瓨鍌ㄥ湪鍐呭瓨浣嶇疆 loc 涓細(xì)
("sidt %0\n" : :"m"(loc)); |
鍖歸厤錛堟暟瀛楋級綰︽潫
鍦ㄦ煇浜涙儏鍐典笅錛屼竴涓彉閲忔棦瑕佸厖褰撹緭鍏ユ搷浣滄暟錛屼篃瑕佸厖褰撹緭鍑烘搷浣滄暟銆傚彲浠ラ氳繃浣跨敤鍖歸厤綰︽潫鍦?
"asm" 涓寚瀹氳繖縐嶆儏鍐點(diǎn)?
asm ("incl %0" :"=a"(var):"0"(var)); |
鍦ㄥ尮閰嶇害鏉熺殑紺轟緥涓紝瀵勫瓨鍣?%eax 鏃㈢敤浣滆緭鍏ュ彉閲忥紝涔熺敤浣滆緭鍑哄彉閲忋傚皢 var 杈撳叆璇誨彇鍒? %eax錛屽鍔犲悗灝嗘洿鏂扮殑 %eax 鍐嶆瀛樺偍鍦?var 涓傝繖閲岀殑 "0" 鎸囧畾絎?0 涓緭鍑哄彉閲忕浉鍚岀殑綰︽潫銆傚嵆錛屽畠鎸囧畾 var 鐨勮緭鍑哄疄渚嬪彧搴旇瀛樺偍鍦?%eax 涓傝綰︽潫鍙互鐢ㄤ簬浠ヤ笅鎯呭喌錛?/p>
浣跨敤鍖歸厤綰︽潫鏈閲嶈鐨勬剰涔夊湪浜庡畠浠彲浠ュ鑷存湁鏁堝湴浣跨敤鍙敤瀵勫瓨鍣ㄣ?/p>
浠ヤ笅紺轟緥閫氳繃鍚勭涓嶅悓鐨勬搷浣滄暟綰︽潫璇存槑浜嗙敤娉曘傛湁濡傛澶氱殑綰︽潫浠ヨ嚦浜庢棤娉曞皢瀹冧滑涓涓鍒楀嚭錛岃繖閲屽彧鍒楀嚭浜嗘渶緇忓父浣跨敤鐨勯偅浜涚害鏉熺被鍨嬨?/p>
"asm" 鍜屽瘎瀛樺櫒綰︽潫 "r" 璁╂垜浠厛鐪嬩竴涓嬩嬌鐢ㄥ瘎瀛樺櫒綰︽潫 r 鐨?"asm"銆傛垜浠殑紺轟緥鏄劇ず浜?GCC 濡備綍鍒嗛厤瀵勫瓨鍣紝浠ュ強(qiáng)瀹冨浣曟洿鏂拌緭鍑哄彉閲忕殑鍊箋?
int main(void) |
鍦ㄨ渚嬩腑錛寈 鐨勫煎鍒朵負(fù) "asm" 涓殑 y銆倄 鍜?y 閮介氳繃瀛樺偍鍦ㄥ瘎瀛樺櫒涓紶閫掔粰 "asm"銆備負(fù)璇ヤ緥鐢熸垚鐨勬眹緙栦唬鐮佸涓嬶細(xì)
main: |
褰撲嬌鐢?"r" 綰︽潫鏃訛紝GCC 鍦ㄨ繖閲屽彲浠ヨ嚜鐢卞垎閰嶄換浣曞瘎瀛樺櫒銆傚湪鎴戜滑鐨勭ず渚嬩腑錛屽畠閫夋嫨 %edx 鏉ュ瓨鍌? x銆傚湪璇誨彇浜?%edx 涓?x 鐨勫煎悗錛屽畠涓?y 涔熷垎閰嶄簡鐩稿悓鐨勫瘎瀛樺櫒銆?/p>
鍥犱負(fù) y 鏄湪杈撳嚭鎿嶄綔鏁伴儴鍒嗕腑鎸囧畾鐨勶紝鎵浠?%edx 涓洿鏂扮殑鍊煎瓨鍌ㄥ湪 -8(%ebp)錛屽爢鏍堜笂 y 鐨勪綅緗腑銆傚鏋?y 鏄湪杈撳叆閮ㄥ垎涓寚瀹氱殑錛岄偅涔堝嵆浣垮畠鍦?y 鐨勪復(fù)鏃跺瘎瀛樺櫒瀛樺偍鍊?(%edx) 涓鏇存柊錛屽爢鏍堜笂 y 鐨勫間篃涓嶄細(xì)鏇存柊銆?/p>
鍥犱負(fù) %eax 鏄湪淇グ鍒楄〃涓寚瀹氱殑錛孏CC 涓嶅湪浠諱綍鍏跺畠鍦版柟浣跨敤瀹冩潵瀛樺偍鏁版嵁銆?/p>
杈撳叆 x 鍜岃緭鍑?y 閮藉垎閰嶅湪鍚屼竴涓?%edx 瀵勫瓨鍣ㄤ腑錛屽亣璁捐緭鍏ュ湪杈撳嚭浜х敓涔嬪墠琚秷鑰椼傝娉ㄦ剰錛屽鏋滄?zhèn)ㄦ湁璁稿鎸囦护锛尀兏嶆槸杩櫩U嶆儏鍐典簡銆傝紜繚杈撳叆鍜岃緭鍑哄垎閰嶅埌涓嶅悓鐨勫瘎瀛樺櫒涓紝鍙互鎸囧畾 & 綰︽潫淇グ絎︺備笅闈㈡槸娣誨姞浜嗙害鏉熶慨楗扮鐨勭ず渚嬨?/p>
int main(void) |
浠ヤ笅鏄負(fù)璇ョず渚嬬敓鎴愮殑姹囩紪浠g爜錛屼粠涓彲浠ユ槑鏄懼湴鐪嬪嚭 x 鍜?y 瀛樺偍鍦? "asm" 涓笉鍚岀殑瀵勫瓨鍣ㄤ腑銆?/p>
main: |
鐜板湪璁╂垜浠湅涓涓嬪浣曞皢涓埆瀵勫瓨鍣ㄤ綔涓烘搷浣滄暟鐨勭害鏉熸寚瀹氥傚湪涓嬮潰鐨勭ず渚嬩腑錛宑puid 鎸囦護(hù)閲囩敤 %eax 瀵勫瓨鍣ㄤ腑鐨勮緭鍏ワ紝鐒跺悗鍦ㄥ洓涓瘎瀛樺櫒涓粰鍑鴻緭鍑猴細(xì)%eax銆?ebx銆?ecx銆?edx銆傚 cpuid 鐨勮緭鍏ワ紙鍙橀噺 "op"錛変紶閫掑埌 "asm" 鐨?eax 瀵勫瓨鍣ㄤ腑錛屽洜涓?cpuid 甯屾湜瀹冭繖鏍峰仛銆傚湪杈撳嚭涓嬌鐢?a銆乥銆乧 鍜?d 綰︽潫錛屽垎鍒敹闆嗗洓涓瘎瀛樺櫒涓殑鍊箋?/p>
asm ("cpuid" |
鍦ㄤ笅闈㈠彲浠ョ湅鍒頒負(fù)瀹冪敓鎴愮殑姹囩紪浠g爜錛堝亣璁?_eax銆乢ebx 絳?.. 鍙橀噺閮藉瓨鍌ㄥ湪鍫嗘爤涓婏級錛?/p>
movl -20(%ebp),%eax /* store 'op' in %eax -- input */ |
strcpy 鍑芥暟鍙互閫氳繃浠ヤ笅鏂瑰紡浣跨敤 "S" 鍜?"D" 綰︽潫鏉ュ疄鐜幫細(xì)
asm ("cld\n |
閫氳繃浣跨敤 "S" 綰︽潫灝嗘簮鎸囬拡 src 鏀懼叆 %esi 涓紝浣跨敤 "D" 綰︽潫灝嗙洰鐨勬寚閽?dst 鏀懼叆 %edi 涓傚洜涓?rep 鍓嶇紑闇瑕?count 鍊鹼紝鎵浠ュ皢瀹冩斁鍏?%ecx 涓?/p>
鍦ㄤ笅闈㈠彲浠ョ湅鍒板彟涓涓害鏉燂紝瀹冧嬌鐢ㄤ袱涓瘎瀛樺櫒 %eax 鍜?%edx 灝嗕袱涓? 32 浣嶇殑鍊煎悎騫跺湪涓璧鳳紝鐒跺悗鐢熸垚涓涓?4 浣嶇殑鍊鹼細(xì)
#define rdtscll(val) \ |
鍦ㄤ笅闈㈠皢鐪嬪埌緋葷粺璋冪敤鐨勪唬鐮侊紝瀹冩湁鍥涗釜鍙傛暟錛?/p>
#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ |
鍦ㄤ笂渚嬩腑錛岄氳繃浣跨敤 b銆乧銆乨 鍜?S 綰︽潫灝嗙郴緇熻皟鐢ㄧ殑鍥涗釜鑷彉閲忔斁鍏? %ebx銆?ecx銆?edx 鍜?%esi 涓傝娉ㄦ剰錛屽湪杈撳嚭涓嬌鐢ㄤ簡 "=a" 綰︽潫錛岃繖鏍鳳紝浣嶄簬 %eax 涓殑緋葷粺璋冪敤鐨勮繑鍥炲煎氨琚斁鍏ュ彉閲?__res 涓傞氳繃灝嗗尮閰嶇害鏉?"0" 鐢ㄤ綔杈撳叆閮ㄥ垎涓涓涓搷浣滄暟綰︽潫錛宻yscall 鍙? __NR_##name 琚斁鍏?%eax 涓紝騫剁敤浣滃緋葷粺璋冪敤鐨勮緭鍏ャ傝繖鏍鳳紝榪欓噷鐨? %eax 鏃㈠彲浠ョ敤浣滆緭鍏ュ瘎瀛樺櫒錛屽張鍙互鐢ㄤ綔杈撳嚭瀵勫瓨鍣ㄣ傛病鏈夊叾瀹冨瘎瀛樺櫒鐢ㄤ簬榪欎釜鐩殑銆傚彟璇鋒敞鎰忥紝杈撳叆錛坰yscall 鍙鳳級鍦ㄤ駭鐢熻緭鍑猴紙syscall 鐨勮繑鍥炲鹼級涔嬪墠琚秷鑰楋紙浣跨敤錛夈?/p>
璇瘋冭檻涓嬮潰鐨勫師瀛愰掑噺鎿嶄綔錛?/p>
__asm__ __volatile__( |
涓哄畠鐢熸垚鐨勬眹緙栫被浼間簬錛?/p>
#APP |
鎮(zhèn)ㄥ彲鑳借冭檻鍦ㄨ繖閲屼負(fù) counter 浣跨敤瀵勫瓨鍣ㄧ害鏉熴傚鏋滆繖鏍峰仛錛宑ounter 鐨勫煎繀欏誨厛澶嶅埗鍒板瘎瀛樺櫒錛岄掑噺錛岀劧鍚庡鍏跺唴瀛樻洿鏂般備絾榪欐牱鎮(zhèn)ㄤ細(xì)鏃犳硶鐞嗚В閿佸畾鍜屽師瀛愭х殑鍏ㄩ儴鎰忓浘錛岃繖浜涙槑紜樉紺轟簡浣跨敤鍐呭瓨綰︽潫鐨勫繀瑕佹с?/p>
璇瘋冭檻鍐呭瓨鎷瘋礉鐨勫熀鏈疄鐜般?/p>
asm ("movl $count, %%ecx; |
褰?lodsl 淇敼 %eax 鏃訛紝lodsl 鍜?stosl 鎸囦護(hù)闅愬惈鍦頒嬌鐢ㄥ畠銆?ecx 瀵勫瓨鍣ㄦ槑紜鍏?count銆備絾 GCC 鍦ㄦ垜浠氱煡瀹冧互鍓嶆槸涓嶇煡閬撹繖浜涚殑錛屾垜浠槸閫氳繃灝?%eax 鍜?%ecx 鍖呮嫭鍦ㄤ慨楗板瘎瀛樺櫒闆嗕腑鏉ラ氱煡 GCC 鐨勩傚湪瀹屾垚榪欎竴姝ヤ箣鍓嶏紝GCC 鍋囪 %eax 鍜?%ecx 鏄嚜鐢辯殑錛屽畠鍙兘鍐沖畾灝嗗畠浠敤浣滃瓨鍌ㄥ叾瀹冪殑鏁版嵁銆傝娉ㄦ剰錛?esi 鍜?%edi 鐢?"asm" 浣跨敤錛屽畠浠笉鍦ㄤ慨楗板垪琛ㄤ腑銆傝繖鏄洜涓哄凡緇忓0鏄?"asm" 灝嗗湪杈撳叆鎿嶄綔鏁板垪琛ㄤ腑浣跨敤瀹冧滑銆傝繖閲屾渶浣庨檺搴︽槸錛屽鏋滃湪 "asm" 鍐呴儴浣跨敤瀵勫瓨鍣紙鏃犺鏄槑紜繕鏄殣鍚湴錛夛紝鏃笉鍑虹幇鍦ㄨ緭鍏ユ搷浣滄暟鍒楄〃涓紝涔熶笉鍑虹幇鍦ㄨ緭鍑烘搷浣滄暟鍒楄〃涓紝蹇呴』灝嗗畠鍒椾負(fù)淇グ瀵勫瓨鍣ㄣ?/p>
鎬葷殑鏉ヨ錛屽唴鑱旀眹緙栭潪甯稿法澶э紝瀹冩彁渚涚殑璁稿鐗規(guī)ф垜浠敋鑷沖湪榪欓噷鏍規(guī)湰娌℃湁娑夊強(qiáng)鍒般備絾濡傛灉鎺屾彙浜嗘湰鏂囨弿榪扮殑鍩烘湰鏉愭枡錛屾?zhèn)ㄥ簲璇ュ彲浠ュ紑濮嬪鑷繁鐨勫唴鑱旀眹緙栬繘琛岀紪鐮佷簡銆?/p>
Original ipmsg protocol specification is written in Japanese.
This document was translated by Mr.Kanazawa.
This document is not verified yet.
----------------------------------------------------------------------
IP Messenger communication protocol (Draft-9) 1996/02/21
Modified 2003/01/14
H.Shirouzu
shirouzu@h.email.ne.jp
----------------------------------------------------------------------
About IP Messenger
This is a Send/Receive message service using the TCP/UDP Port.
Characteristics
IP Messenger can be installed in any OS if TCP/IP is used on your machine.
Dynamic member recognition can be done within your network or specified network.
You can exchange messages between all IPMsg members.
Function description
Use TCP/UDP port(default:2425). See the following descriptions
(Message Send/Receive: UDP, File Send/Receive: TCP)
1. Command
1) Command functions (Low 8 bits from command number 32 bits)
IPMSG_NOOPERATION No Operation
IPMSG_BR_ENTRY Entry to service (Start-up with a Broadcast command)
IPMSG_BR_EXIT Exit from service (End with a Broadcast command)
IPMSG_ANSENTRY Notify a new entry
IPMSG_BR_ABSENCE Change absence mode
IPMSG_BR_ISGETLIST Search valid sending host members
IPMSG_OKGETLIST Host list sending notice
IPMSG_GETLIST Host list sending request
IPMSG_ANSLIST Host list sending
IPMSG_SENDMSG Message transmission
IPMSG_RECVMSG Message receiving check
IPMSG_READMSG Message open notice
IPMSG_DELMSG Message discarded notice
IPMSG_ANSREADMSG Message open confirmation notice(added from version-8 )
IPMSG_GETFILEDATA File Transfer request by TCP
IPMSG_RELEASEFILES Discard attachment file
IPMSG_GETDIRFILES Attachment hierarchical file request
IPMSG_GETINFO Get IPMSG version info.
IPMSG_SENDINFO Send IPMSG version info.
IPMSG_GETABSENCEINFO Get absence sentence
IPMSG_SENDABSENCEINFO Send absence sentence
IPMSG_GETPUBKEY RSA Public Key Acquisition
IPMSG_ANSPUBKEY RSA Public Key Response
2) Option flag (High 24 bits from command number 32 bits)
IPMSG_ABSENCEOPT Absence mode(Member recognition command)
IPMSG_SERVEROPT Server(Reserved)
IPMSG_DIALUPOPT Send individual member recognition command
IPMSG_SENDCHECKOPT Transmission check
IPMSG_SECRETOPT Sealed message
IPMSG_READCHECKOPT Sealed message check(added from ver8 )
IPMSG_PASSWORDOPT Lock
IPMSG_BROADCASTOPT Broadcast message
IPMSG_MULTICASTOPT Multi-cast(Multiple casts selection)
IPMSG_NEWMUTIOPT New version multi-cast(reserved)
IPMSG_AUTORETOPT Automatic response(Ping-pong protection)
IPMSG_NOLOGOPT No log files
IPMSG_NOADDLISTOPT Notice to the members outside of BR_ENTRY
IPMSG_FILEATTACHOPT File attachment
IPMSG_ENCRYPTOPT Code
IPMSG_NOPOPUPOPT (No longer valid)
IPMSG_RETRYOPT Re-send flag(Use when acquiring HOSTLIST)
3) Extended code flag (hex format combination)
IPMSG_RSA_512
IPMSG_RSA_1024
IPMSG_RSA_2048
IPMSG_RC2_40
IPMSG_RC2_128
IPMSG_RC2_256
IPMSG_BLOWFISH_128
IPMSG_BLOWFISH_256
IPMSG_SIGN_MD5
4) Extended files for attachment (fileattr low 8 bits)
IPMSG_FILE_REGULAR
IPMSG_FILE_DIR
IPMSG_FILE_RETPARENT
IPMSG_FILE_SYMLINK
IPMSG_FILE_CDEV
IPMSG_FILE_BDEV
IPMSG_FILE_FIFO
IPMSG_FILE_RESFORK
5) Attachment file extended attribute(fileattr high 24 bits)
IPMSG_FILE_RONLYOPT
IPMSG_FILE_HIDDENOPT
IPMSG_FILE_EXHIDDENOPT
IPMSG_FILE_ARCHIVEOPT
IPMSG_FILE_SYSTEMOPT
6) Extended file attribute for attachment file
IPMSG_FILE_UID
IPMSG_FILE_USERNAME
IPMSG_FILE_GID
IPMSG_FILE_GROUPNAME
IPMSG_FILE_PERM
IPMSG_FILE_MAJORNO
IPMSG_FILE_MINORNO
IPMSG_FILE_CTIME
IPMSG_FILE_MTIME
IPMSG_FILE_ATIME
IPMSG_FILE_CREATETIME
IPMSG_FILE_CREATOR
IPMSG_FILE_FILETYPE
IPMSG_FILE_FINDERINFO
IPMSG_FILE_ACL
IPMSG_FILE_ALIASFNAME
IPMSG_FILE_UNICODEFNAME
2.Command format(Use all character strings)
1) Command(Format version-1)
Ver(1) : PacketNo : SenderName : SenderHost : CommandNo : AdditionalSection
2) An example for Message Send/Receive by using the current command format
"1:100:shirouzu:jupiter:32:Hello"
3.Command process overview
1) Member recognition
An IPMSG_BR_ENTRY command notifies a new entry to the current
members at start-up.
All members add the new member to their list after getting a notification message.
An IPMSG_ANSENTRY command sends a message back to the new member.
The new member gets the current member data by a
IPMSG_ANSENTRY command. All members can communicate as long as an
IP packet exists.
An IPMSG_BR_ABSENCE command broadcasts absence mode cancel or
nickname change to all members. However, an IPMSG_ANSENTRY command
does not send a message back, which is different from an IPMSG_BR_ENTRY
command.
IPMSG_BR_ENTRY, IPMSG_ANSENTRY, and IPMSG_BR_ABSENCE commands
use an IPMSG_ABSENCEOPT flag for absence mode. Input a nickname to
additional command.
Add an IPMSG_DIALUPOPT flag for dial-up users who can't be reached by
a broadcast command. A member recognition command needs to be
sent individually to the members with this optional flag.
(Extended group)IPMSG_BR_ENTRY and IPMSG_BR_ABSENCE commands
sends a group name by adding the new group name after the current
command format character strings (Input '\0' between the current
command and extended name).
2) Send/Receive Message
Send Message uses an IPMSG_SENDMSG command that can input a message
in the extended area.
Receive Message sends back an IPMSG_RECVMSG command only
if an IPMSG_SENDCHECKOPT flag is ON. Input the original packet number
to the extended area.
Broadcast Message Send uses an IPMSG_BOADCASTOPT command
and an IPMSG_SENDMSG flag should be ON.
Auto-Send packet(absence notice) needs to be added to IPMSG_AUTORETOPT
for ping-pong protection. If either one or another packet is ON, then
confirmation/auto-send packet is not sent back.
Send Message Sealing needs to be an IPMSG_SECRETOPT packet ON.
In this case, Receive Message sends an IPMSG_READMSG command.
Input the original packet number to the extended area.
(Additional IPMSG_NOADDLISTOPT)
When receiving an IPMSG_SENDMSG packet from a host that is
not on your Send/Receive list, IPMsg will either confirm a host by
sending an IPMSG_BR_ENTRY command or add a host name to
the Send/Receive list.
However, single-shot Message Send/Receive action needs to be avoided.
Add an IPMSG_NOADDLISTOPT flag to an IPMSG_SENDMSG command.
(Additional IPMSG_READCHECKOPT from version-8 )
When an IPMSG_READMSG command contains an IPMSG_READCHECKOPT flag,
IPMsg process is the same as IPMSG_SENDMSG with an
IPMSG_SENDCHECKOPT flag.
However, Send Message uses an IPMSG_ANSREADMSG command,
not IPMSG_RECVMSG.
3) Message Send/Receive 浜卐ncrypted extension (Added in the version-9 )
Use the combination of Public-key(RSA) and common key(RC2/Blowfish).
(Encrypted extension area is used in hex format.)
(Public key acquisition)Send an IPMSG_GETPUBKEY command to Receive
Message. Receive Message gets an IPMSG_ANSPUBKEY that
means receiving RSA public key from Send Message.
IPMSG_GETPUBKEY/IPMSG_ANSPUBKEY both require the value which is
encryption capability (Exp. IPMSG_RSA_1024) flag uses "OR" at first
part of extension
In addition, In IPMSG_ANSPUBKEY, public key written as EE-NNNNNN
E=Exponent涓凬=method)devide by ':'. and Input the Fdelimiter '-'
between E and N.
This sequence can be skipped after the 2nd Send/Receive process by
memorizing public key and encrypted data.
(Encrypted message)After a sender creates a common key that is
supported both sender and receiver, a common key can encrypt a message.
In addition, a receiver's public key encrypts the common key.
(Encrypted message transmission) IPMSG_ENCRYPTOPT is used in
IPMSG_SENDMSG. At the first part of extension, input the value which
is 'or' resoult from Convination of public key and common key type .
Then use common key which encrypt with public key devide by ':'.
Then input message which is eccrypted by public key devide by ':'.
If both supports IPMSG_SIGN_XXX, then add ':' and signeture.
Also, In the method of encode padding, PKCS#1ECB key is used for RSA,
PKCS#5 CBC common key is used for RC2/blowfish.
Also, The Packet related to Entry manifestation the capability of
ecryption support using IPMSG_ENCRYPTOPT
4) Extension with file attachment(Available from version-9 )
An IPMSG_SENDMSG command with an IPMSG_FILEATTACHOPT flag for
File transfer (download permission)notification sends a message
with attachment.
Input '\0' after the message and attachment file data.
fileID:filename:size:mtime:fileattr[:extend-attr=val1
[,val2...][:extend-attr2=...]]:\a:fileID...
(size, mtime, and fileattr describe hex format.
If a filename contains ':', please replace with "::".)
When Receive Message downloads an attachment file, an IPMSG_GETFILEDATA
command requests a data transmission packet to the TCP port that is the same number
as the UDP sending port number. Input packetID:fileID: offset to the extended area.
(Use all hex format.)
File Transfer side receives the request. After recognizing that it's a correct request,
then send the specified data (no format)
When the data receiving side downloads a hierarchical attachment file,
use an IPMSG_GETDIRFILES command and input a packetID:fileID
to the extended area and send a data transmission request packet.
(all hex format)
Data sending side sends the following hierarchical data format.
header-size:filename:file-size:fileattr[:extend-attr=val1
[,val2...][:extend-attr2=...]]:contents-data
Next headersize: Next filename...
(All hex format except for filename and contetns-data)
header-size is from the beginning of header-size to the delimiter ':'
that is before contents-data. extend-attr can be omitted and used multiple
extended attributes. Use '=' for data input.
When fileattr is IPMSG_FILE_DIR, IPMsg recognizes that it is automatically
in the directory, the next file data is after the directory.
When fileattr is IPMSG_FILE_RETPARENT, IMPsg recognizes that it returns
to the parent directory. In this case, File name is always "." and the attribute
value is the current directory data.
Sending process starts from the attachment directly and returns the
IPMSG_FILE_RETPARENT command to the attachment directory.
Add an IPMSG_FILEATTACHOPT flag for an Entry packet to support the
attachment file.
5) Other commands
When acquiring different versions, send an IPMSG_GETINFO command.
Receiving side sends the version information character string to
extended area.
Send an IPMSG_GETABSENCEINFO command for acquiring an absence message.
Receiving side sends an IPMSG_SENDABSENCEINFO back if the status is absence mode.
If the status is not absence mode, a character string "Not absence mode" will be sent back.
6) Confirmation/Retry
If a confirmation packet for IPMSG_SENDMSG or IPMSG_RECVMSG is not delivered
within a specified time, then it will be sent again.
A number of retry actions or interval period is depended on the current condition.
4. Other
1) Linefeed
Linefeed characters in Send Message is standardized with UNIX type ('0x0a').
Please change if needed.
2) Delimiter ':'
':' is used as a delimiter. You can't use this delimiter for user name
and host name.
If the use/host names contain a ':', please replace with another sign,
for an example ';'.
Although using this delimiter isn