{"id":205719,"date":"2025-06-12T10:46:55","date_gmt":"2025-06-12T02:46:55","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205719\/"},"modified":"2025-06-12T10:46:55","modified_gmt":"2025-06-12T02:46:55","slug":"golang-%e5%87%bd%e6%95%b0%e7%9a%84%e6%ba%90%e7%a0%81%e5%88%86%e6%9e%90%ef%bc%9a%e7%aa%a5%e6%8e%a2%e5%86%85%e9%83%a8%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205719\/","title":{"rendered":"Golang \u51fd\u6570\u7684\u6e90\u7801\u5206\u6790\uff1a\u7aa5\u63a2\u5185\u90e8\u5b9e\u73b0"},"content":{"rendered":"<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929GOLANG\u5c31\u6574\u7406\u5206\u4eab\u300aGOLANG \u51fd\u6570\u7684\u6e90\u7801\u5206\u6790\uff1a\u7aa5\u63a2\u5185\u90e8\u5b9e\u73b0\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9GOLANG\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7GOLANG\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002,Go \u51fd\u6570\u6267\u884c\u6d41\u7a0b\uff1a\u8bbe\u7f6e\u6808\u5e27\u5e76\u5206\u914d\u7a7a\u95f4\u3002\u8c03\u7528 Go \u8fd0\u884c\u65f6\u7684 newproc \u51fd\u6570\u521b\u5efa\u534f\u7a0b\u3002\u68c0\u67e5\u8fd4\u56de\u503c\u5e76\u7ec8\u6b62\u51fd\u6570\uff08\u5982\u6709\u9700\u8981\uff09\u3002\u5207\u6362\u6570\u636e\u6bb5\u5e76\u8df3\u8f6c\u5230\u51fd\u6570\u5165\u53e3\u70b9\u3002\u6267\u884c\u51fd\u6570\u5e76\u521d\u59cb\u5316\u8fd4\u56de\u503c\u3002\u8fd4\u56de\u5230\u8c03\u7528\u70b9\u3002,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729948822671cec960e568.jpg\" class=\"aligncenter\">,<br \/>\n<strong>Go \u51fd\u6570\u7684\u6e90\u7801\u5206\u6790\uff1a\u7aa5\u63a2\u5185\u90e8\u5b9e\u73b0<\/strong>,<br \/>\n<strong>\u7b80\u4ecb<\/strong>,\u5728 Go \u8bed\u8a00\u4e2d\uff0c\u51fd\u6570\u662f\u7a0b\u5e8f\u4e2d\u6267\u884c\u7279\u5b9a\u4efb\u52a1\u7684\u4ee3\u7801\u5757\u3002\u4e86\u89e3\u51fd\u6570\u7684\u5185\u90e8\u5b9e\u73b0\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u6df1\u5165\u7406\u89e3 Go \u7684\u5de5\u4f5c\u539f\u7406\u3002\u672c\u6587\u5c06\u901a\u8fc7\u5206\u6790 Go \u8fd0\u884c\u65f6\u7684\u6e90\u4ee3\u7801\uff0c\u9010\u6b65\u5256\u6790\u4e00\u4e2a\u51fd\u6570\u7684\u6267\u884c\u8fc7\u7a0b\u3002,<br \/>\n<strong>\u5b9e\u6218\u6848\u4f8b\uff1aHello\uff0cWorld\uff01<\/strong>,\u8ba9\u6211\u4eec\u4ece\u4e00\u4e2a\u7b80\u5355\u7684 Hello\uff0cWorld\uff01\u51fd\u6570\u5f00\u59cb\uff1a,<br \/>\n<strong>\u6e90\u4ee3\u7801\u5206\u6790<\/strong>,\u8981\u67e5\u770b\u8be5\u51fd\u6570\u7684\u6e90\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<br \/>\n<code>go tool compile -S main.go<\/code> \u547d\u4ee4\u3002\u8fd9\u5c06\u751f\u6210\u53cd\u6c47\u7f16\u4ee3\u7801\uff0c\u5176\u4e2d\u5305\u542b\u51fd\u6570\u7684\u673a\u5668\u7801\u8868\u793a\u3002,\u5bf9\u4e8e<br \/>\n<code>main<\/code> \u51fd\u6570\uff0c\u53cd\u6c47\u7f16\u4ee3\u7801\u5982\u4e0b\uff1a,<br \/>\n<strong>\u6267\u884c\u6d41\u7a0b<\/strong>,\u8be5\u53cd\u6c47\u7f16\u4ee3\u7801\u63ed\u793a\u4e86\u51fd\u6570\u6267\u884c\u7684\u4ee5\u4e0b\u6b65\u9aa4\uff1a,<br \/>\n<strong>\u7ed3\u8bba<\/strong>,\u901a\u8fc7\u5206\u6790 Go \u51fd\u6570\u7684\u6e90\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u6df1\u5165\u4e86\u89e3 Go \u8fd0\u884c\u65f6\u7684\u5185\u90e8\u673a\u5236\u3002\u8fd9\u6709\u52a9\u4e8e\u6211\u4eec\u7406\u89e3\u51fd\u6570\u7684\u6267\u884c\u8fc7\u7a0b\u4ee5\u53ca\u5982\u4f55\u4f18\u5316\u6211\u4eec\u7684\u4ee3\u7801\u3002,\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aGOLANG \u51fd\u6570\u7684\u6e90\u7801\u5206\u6790\uff1a\u7aa5\u63a2\u5185\u90e8\u5b9e\u73b0\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002,\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929GOLANG\u5c31\u6574\u7406\u5206\u4eab\u300aGOLANG \u51fd\u6570\u7684\u6e90\u7801\u5206\u6790\uff1a\u7aa5\u63a2\u5185\u90e8\u5b9e\u73b0\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9GOLANG\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7GOLANG\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>GOLANG \u51fd\u6570\u7684\u6e90\u7801\u5206\u6790\uff1a\u7aa5\u63a2\u5185\u90e8\u5b9e\u73b0<\/span><\/p>\n<h1>GOLANG \u51fd\u6570\u7684\u6e90\u7801\u5206\u6790\uff1a\u7aa5\u63a2\u5185\u90e8\u5b9e\u73b0<\/h1>\n<p><span>2024-10-26 21:20:37<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929GOLANG\u5c31\u6574\u7406\u5206\u4eab\u300aGOLANG \u51fd\u6570\u7684\u6e90\u7801\u5206\u6790\uff1a\u7aa5\u63a2\u5185\u90e8\u5b9e\u73b0\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9GOLANG\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7GOLANG\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p>Go \u51fd\u6570\u6267\u884c\u6d41\u7a0b\uff1a\u8bbe\u7f6e\u6808\u5e27\u5e76\u5206\u914d\u7a7a\u95f4\u3002\u8c03\u7528 Go \u8fd0\u884c\u65f6\u7684 newproc \u51fd\u6570\u521b\u5efa\u534f\u7a0b\u3002\u68c0\u67e5\u8fd4\u56de\u503c\u5e76\u7ec8\u6b62\u51fd\u6570\uff08\u5982\u6709\u9700\u8981\uff09\u3002\u5207\u6362\u6570\u636e\u6bb5\u5e76\u8df3\u8f6c\u5230\u51fd\u6570\u5165\u53e3\u70b9\u3002\u6267\u884c\u51fd\u6570\u5e76\u521d\u59cb\u5316\u8fd4\u56de\u503c\u3002\u8fd4\u56de\u5230\u8c03\u7528\u70b9\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729948822671cec960e568.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>Go \u51fd\u6570\u7684\u6e90\u7801\u5206\u6790\uff1a\u7aa5\u63a2\u5185\u90e8\u5b9e\u73b0<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u5728 Go \u8bed\u8a00\u4e2d\uff0c\u51fd\u6570\u662f\u7a0b\u5e8f\u4e2d\u6267\u884c\u7279\u5b9a\u4efb\u52a1\u7684\u4ee3\u7801\u5757\u3002\u4e86\u89e3\u51fd\u6570\u7684\u5185\u90e8\u5b9e\u73b0\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u6df1\u5165\u7406\u89e3 Go \u7684\u5de5\u4f5c\u539f\u7406\u3002\u672c\u6587\u5c06\u901a\u8fc7\u5206\u6790 Go \u8fd0\u884c\u65f6\u7684\u6e90\u4ee3\u7801\uff0c\u9010\u6b65\u5256\u6790\u4e00\u4e2a\u51fd\u6570\u7684\u6267\u884c\u8fc7\u7a0b\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1aHello\uff0cWorld\uff01<\/strong><\/p>\n<p>\u8ba9\u6211\u4eec\u4ece\u4e00\u4e2a\u7b80\u5355\u7684 Hello\uff0cWorld\uff01\u51fd\u6570\u5f00\u59cb\uff1a<\/p>\n<pre>package main\n\nimport \"fmt\"\n\nfunc main() {\n    fmt.Println(\"Hello\uff0cWorld\uff01\")\n}<\/pre>\n<p><strong>\u6e90\u4ee3\u7801\u5206\u6790<\/strong><\/p>\n<p>\u8981\u67e5\u770b\u8be5\u51fd\u6570\u7684\u6e90\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>go tool compile -S main.go<\/code> \u547d\u4ee4\u3002\u8fd9\u5c06\u751f\u6210\u53cd\u6c47\u7f16\u4ee3\u7801\uff0c\u5176\u4e2d\u5305\u542b\u51fd\u6570\u7684\u673a\u5668\u7801\u8868\u793a\u3002<\/p>\n<p>\u5bf9\u4e8e <code>main<\/code> \u51fd\u6570\uff0c\u53cd\u6c47\u7f16\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>TEXT    main(SB), ABIInternal, $0-8\n    MOV    BP, BX\n    MOV    BX, R13\n    MOV    R13, BP\n    SUB    $16, SP\n    CALL    runtime.newproc(SB)\n    MOV    R12, AX\n    CMP    $1, AX\n    SETHI    AX\n    MOV    BX, DS\n    JMP    AX\n    MOV    $0, AX\n    MOV    AX, FS\n    MOV    $0, AX\n    RET<\/pre>\n<p><strong>\u6267\u884c\u6d41\u7a0b<\/strong><\/p>\n<p>\u8be5\u53cd\u6c47\u7f16\u4ee3\u7801\u63ed\u793a\u4e86\u51fd\u6570\u6267\u884c\u7684\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li><strong>\u8bbe\u7f6e\u51fd\u6570\u6808\u5e27\uff1a<\/strong> <code>MOV BP, BX<\/code> \u548c <code>MOV BX, R13<\/code> \u6307\u4ee4\u8bbe\u7f6e\u6808\u5e27\u6307\u9488\u5bc4\u5b58\u5668 (BP) \u5e76\u4fdd\u5b58\u5f53\u524d\u5e27\u7684\u57fa\u5730\u5740 (BX) \u5728 R13 \u4e2d\u3002<\/li>\n<li><strong>\u5206\u914d\u6808\u7a7a\u95f4\uff1a<\/strong> <code>SUB $16, SP<\/code> \u4e3a\u51fd\u6570\u8c03\u7528\u5206\u914d\u4e86 16 \u5b57\u8282\u7684\u6808\u7a7a\u95f4\u3002<\/li>\n<li><strong>\u8c03\u7528 runtime.newproc\uff1a<\/strong> <code>CALL runtime.newproc(SB)<\/code> \u8c03\u7528 Go \u8fd0\u884c\u65f6\u7684 <code>newproc<\/code> \u51fd\u6570\uff0c\u521b\u5efa\u65b0\u7684\u534f\u7a0b\uff08goroutine\uff09\u7528\u4e8e\u6267\u884c\u51fd\u6570\u3002<\/li>\n<li><strong>\u68c0\u67e5\u8fd4\u56de\u503c\uff1a<\/strong> <code>CMP $1, AX<\/code> \u6307\u4ee4\u6bd4\u8f83 <code>newproc<\/code> \u7684\u8fd4\u56de\u503c\u662f\u5426\u4e3a 1\u3002\u5982\u679c\u4e3a 1\uff0c\u5219\u51fd\u6570\u5c06\u7ec8\u6b62\u3002<\/li>\n<li><strong>\u5207\u6362\u6570\u636e\u6bb5\uff1a<\/strong> <code>MOV BX, DS<\/code> \u6307\u4ee4\u5c06\u6570\u636e\u6bb5\u5bc4\u5b58\u5668 (DS) \u8bbe\u7f6e\u4e3a\u5806\u6808\u6bb5\u3002<\/li>\n<li><strong>\u8df3\u8f6c\u5230\u51fd\u6570\u5165\u53e3\u70b9\uff1a<\/strong> <code>JMP AX<\/code> \u6307\u4ee4\u8df3\u8f6c\u5230 <code>runtime.main<\/code>\uff0c\u5373 <code>main<\/code> \u51fd\u6570\u7684\u5165\u53e3\u70b9\u3002<\/li>\n<li><strong>\u6267\u884c\u51fd\u6570\uff1a<\/strong> <code>MOV $0, AX<\/code> \u548c <code>MOV AX, FS<\/code> \u6307\u4ee4\u521d\u59cb\u5316\u51fd\u6570\u7684\u8fd4\u56de\u503c\u5e76\u8bbe\u7f6e\u6808\u6bb5\u5bc4\u5b58\u5668 (FS)\u3002<\/li>\n<li><strong>\u8fd4\u56de\uff1a<\/strong> <code>RET<\/code> \u6307\u4ee4\u4f7f\u51fd\u6570\u8fd4\u56de\u5230\u8c03\u7528\u70b9\u3002<\/li>\n<\/ol>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u5206\u6790 Go \u51fd\u6570\u7684\u6e90\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u6df1\u5165\u4e86\u89e3 Go \u8fd0\u884c\u65f6\u7684\u5185\u90e8\u673a\u5236\u3002\u8fd9\u6709\u52a9\u4e8e\u6211\u4eec\u7406\u89e3\u51fd\u6570\u7684\u6267\u884c\u8fc7\u7a0b\u4ee5\u53ca\u5982\u4f55\u4f18\u5316\u6211\u4eec\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aGOLANG \u51fd\u6570\u7684\u6e90\u7801\u5206\u6790\uff1a\u7aa5\u63a2\u5185\u90e8\u5b9e\u73b0\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   golang \u6846\u67b6\u4e0e ASP.NET Core: C# \u4e0e Go \u7684\u89d2\u9010\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   Java\u51fd\u6570\u4e2d\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u7684\u6a21\u5f0f\u548c\u53cd\u6a21\u5f0f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205719","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205719"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205719\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}