{"id":1675,"date":"2020-07-01T11:21:55","date_gmt":"2020-07-01T03:21:55","guid":{"rendered":"http:\/\/bloo.heing.fun\/?p=1675"},"modified":"2020-07-01T11:53:45","modified_gmt":"2020-07-01T03:53:45","slug":"pc-assembly-language-%e6%b1%87%e7%bc%96%e5%bc%80%e5%8f%91","status":"publish","type":"post","link":"https:\/\/bloo.heing.fun\/?p=1675","title":{"rendered":"pc assembly language \u6c47\u7f16\u5f00\u53d1"},"content":{"rendered":"\n<ol class=\"wp-block-list\"><li>\u9700\u8981\u4e00\u4e9b\u57fa\u7840\u5e93\u6587\u4ef6<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>% ls env\nasm_io.inc  asm_io.o  cdecl.h  driver.c<\/code><\/pre>\n\n\n\n<p>2. \u6c47\u7f16\u6a21\u677f\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>%include \"asm_io.inc\"\n\n\nsegment .data\n\nsegment .text\n    global asm_main\nasm_main:\n    enter 0, 0\n    pusha\n\n    popa\n    mov eax,0\n    leave\n    ret<\/code><\/pre>\n\n\n\n<p>3. \u81ea\u5df1\u5199\u7684\u4e00\u952e\u6267\u884c\u6c47\u7f16\u6587\u4ef6\u7684shell\u7a0b\u5e8f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>% cat \/root\/bin\/exasm\nif &#91; $# -eq 1 ]; then\n    nasm -o \"$1.m.o\" -f elf \"$1\"\n    gcc -m32 -o \"$1.m\" driver.c asm_io.o \"$1.m.o\"\n    .\/\"$1.m\"\n\n    mv $1.m* ~\/trash\/\nfi\n\nif &#91; $# -eq 2 ]; then\n    nasm -o \"$1.m.o\" -f elf \"$1\"\n    gcc -g -m32 -o \"$1.m\" \"$2\" asm_io.o \"$1.m.o\"\n    .\/\"$1.m\"\n\n    #mv \"$1.m\" ~\/trash\n    #mv \"$1.m.o\" ~\/trash\/\nfi\n<\/code><\/pre>\n\n\n\n<p>4. \u4e00\u822c\u662f\u8fd9\u6837\u8fd0\u884c\u6c47\u7f16\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>% ls\nasm_io.inc  asm_io.o  cdecl.h  driver.c  env  lab1.asm  m_temp.asm\n% exasm lab1.asm<\/code><\/pre>\n\n\n\n<p>5. debug\u6c47\u7f16\u7a0b\u5e8f<\/p>\n\n\n\n<p>5.1 \u751f\u6210\u53cd\u6c47\u7f16\u6587\u4ef6\uff0c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>% cat \/root\/bin\/asm_gen_out\nif &#91; $# -eq 1 ]; then\n    nasm -o \"$1.m.o\" -f elf \"$1\"\n    gcc -g -m32 -o \"$1.m\" driver.c asm_io.o \"$1.m.o\"\n    objdump -S \"$1.m\" > \"$1.m.dis_asm\"\nfi\n% asm_gen_out lab1.asm\n% ls\nasm_io.asm  asm_io.o  driver.c  lab1.asm.m          lab1.asm.m.o\nasm_io.inc  cdecl.h   lab1.asm  lab1.asm.m.dis_asm  m_temp.asm\n\n<\/code><\/pre>\n\n\n\n<p>\u63a5\u7740\u53ef\u4ee5\u6253\u5f00xxx.m.dis_asm\u770b\u53cd\u6c47\u7f16\u6587\u4ef6\uff0c\u53ef\u4ee5\u770b\u5230\u6307\u4ee4\u7684\u5730\u5740\u3002\u53ef\u4ee5\u901a\u8fc7vim\u641c\u7d22asm_main\u51fd\u6570\u3002<\/p>\n\n\n\n<p>5.2 gdb\u8c03\u8bd5\u6c47\u7f16\u7a0b\u5e8f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>% cat \/root\/bin\/asm_debug\nif &#91; $# -eq 1 ]; then\n    nasm -o \"$1.m.o\" -f elf \"$1\"\n    gcc -g -m32 -o \"$1.m\" driver.c asm_io.o \"$1.m.o\"\n    gdb \"$1.m\"\n\nfi\n% asm_debug lab1.asm\nGNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.el7\nCopyright (C) 2013 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later &lt;http:\/\/gnu.org\/licenses\/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\nand \"show warranty\" for details.\nThis GDB was configured as \"x86_64-redhat-linux-gnu\".\nFor bug reporting instructions, please see:\n&lt;http:\/\/www.gnu.org\/software\/gdb\/bugs\/>...\nReading symbols from \/root\/pro\/as\/pcasl-linux\/wut_asm\/lab1.asm.m...done.\n(gdb) \n<\/code><\/pre>\n\n\n\n<p>\u53ef\u4ee5\u901a\u8fc7\u5982 b *0x80bbef\u5728\u67d0\u4e2a\u5730\u5740\u65ad\u70b9\u3002\u53ef\u4ee5\u901a\u8fc7si\u5355\u6b65\u8c03\u8bd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(gdb) b *0x80487d5\nBreakpoint 1 at 0x80487d5\n(gdb) c\nThe program is not being run.\n(gdb) r\nStarting program: \/root\/pro\/as\/pcasl-linux\/wut_asm\/lab1.asm.m \n\nBreakpoint 1, 0x080487d5 in asm_main ()\nMissing separate debuginfos, use: debuginfo-install glibc-2.17-292.el7.i686\n(gdb) si\n0x080487da in asm_main ()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u8981\u4e00\u4e9b\u57fa\u7840\u5e93\u6587\u4ef6 2. \u6c47\u7f16\u6a21\u677f\u6587\u4ef6\uff1a 3. \u81ea\u5df1\u5199\u7684\u4e00\u952e\u6267\u884c\u6c47\u7f16\u6587\u4ef6\u7684shell\u7a0b\u5e8f\uff1a 4. \u4e00\u822c\u662f\u8fd9\u6837\u8fd0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[83,36],"tags":[],"class_list":["post-1675","post","type-post","status-publish","format-standard","hentry","category-83","category-36"],"_links":{"self":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts\/1675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1675"}],"version-history":[{"count":6,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts\/1675\/revisions"}],"predecessor-version":[{"id":1681,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=\/wp\/v2\/posts\/1675\/revisions\/1681"}],"wp:attachment":[{"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bloo.heing.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}