{"id":504,"date":"2026-03-07T19:57:55","date_gmt":"2026-03-07T11:57:55","guid":{"rendered":"http:\/\/8.129.82.128\/?p=504"},"modified":"2026-03-07T19:57:55","modified_gmt":"2026-03-07T11:57:55","slug":"8086%e6%b1%87%e7%bc%9610","status":"publish","type":"post","link":"http:\/\/8.129.82.128\/?p=504","title":{"rendered":"8086\u6c47\u7f16#10"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"zh-CN\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>\u7b2c\u5341\u7ae0 CALL\u548cRET\u6307\u4ee4 &#8211; \u6c47\u7f16\u8bed\u8a00\u63d0\u7eb2<\/title>\n    <style>\n        #asm-wrapper {\n            all: initial;\n            display: block;\n            width: 100%;\n            min-height: 100vh;\n            margin: 0;\n            padding: 30px 25px;\n            box-sizing: border-box;\n            font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Microsoft YaHei\", sans-serif !important;\n            line-height: 1.8;\n            background: linear-gradient(180deg, #d4ecf7 0%, #a8e6cf 50%, #88d8b0 100%) !important;\n            color: #2c3e50 !important;\n        }\n        #asm-wrapper * { box-sizing: border-box; margin: 0; padding: 0; }\n        #asm-wrapper h1 { text-align: center; color: #1a5276 !important; font-size: 1.8em; border-bottom: 3px solid #27ae60 !important; padding-bottom: 15px; }\n        #asm-wrapper h2 { color: #1e8449 !important; border-left: 4px solid #27ae60 !important; padding-left: 15px; margin-top: 30px; }\n        #asm-wrapper h3 { color: #196f3d !important; margin-top: 20px; }\n        #asm-wrapper p { margin: 10px 0; }\n        #asm-wrapper ul, #asm-wrapper ol { margin: 10px 0; padding-left: 25px; }\n        #asm-wrapper li { margin: 5px 0; }\n        #asm-wrapper strong { color: #e74c3c !important; font-weight: 700 !important; }\n        #asm-wrapper pre { background: #1e3d2f !important; color: #a8e6cf !important; padding: 15px 20px; border-radius: 8px; overflow-x: auto; font-size: 0.85em; line-height: 1.6; margin: 15px 0; border: 2px solid #27ae60; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }\n        #asm-wrapper pre code { background: none !important; padding: 0; color: inherit !important; border: none; }\n        #asm-wrapper table { width: 100%; border-collapse: collapse; margin: 15px 0; font-size: 0.9em; }\n        #asm-wrapper th, #asm-wrapper td { border: 1px solid #7f8c8d; padding: 10px 12px; text-align: left; }\n        #asm-wrapper th { background: #27ae60 !important; color: white !important; }\n        #asm-wrapper tr:nth-child(even) { background: #d5f5e3 !important; }\n        #asm-wrapper img { max-width: 100%; height: auto; display: block; margin: 25px 0; padding: 15px; background: white !important; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.15); border: 2px solid #27ae60; }\n        #asm-wrapper hr { border: none; border-top: 2px dashed #27ae60; margin: 30px 0; }\n<\/style>\n<\/head>\n<body>\n    <div id=\"asm-wrapper\">\n        <h1>\u7b2c\u5341\u7ae0 CALL\u548cRET\u6307\u4ee4<\/h1>\n        <pre><code>\u7b2c\u5341\u7ae0 CALL\u548cRET\u6307\u4ee4<\/strong><strong><\/strong>\n10.1 ret\u548cretf\n<u>ret\u7528\u6808\u4e2d\u7684\u6570\u636e\u4fee\u6539IP\u7684\u5185\u5bb9,\u5b9e\u73b0\u8fd1\u8f6c\u79fb<\/u>\nret\u6307\u4ee4\u6267\u884c\u8fc7\u7a0b\u76f8\u5f53\u4e8e:pop IP\n<u>retf\u7528\u6808\u4e2d\u7684\u6570\u636e\u4fee\u6539CS\u548cIP\u4e2d\u7684\u5185\u5bb9\uff0c\u5b9e\u73b0\u8fdc\u8f6c\u79fb<\/u><u><\/u>\nretf\u6307\u4ee4\u6267\u884c\u8fc7\u7a0b\u76f8\u5f53\u4e8e:\npop IP\npop CS<\/code><\/pre>\n<p>\u68c0\u6d4b\u70b910.1 <\/p>\n<pre><code>\u8865\u5168\u7a0b\u5e8f\uff0c\u5b9e\u73b0\u4ece\u5185\u5b581000\uff1a0000\u5904\u5f00\u59cb\u6267\u884c\u6307\u4ee4\u3002\nassume cs:code\nstack segment\ndb 16 dup (0)\nstack ends\ncode segment\nstart:mov ax,stack\nmov ss,ax\nmov sp,16\nmov ax,<u> 1000h <\/u><u><\/u>\npush ax\nmov ax,<u>   0   <\/u>\npush ax\nretf\ncode ends\nend start\n10.2~10.6 call\u6307\u4ee4\n<![if !supportLists]>1. <![endif]>\u6267\u884ccall\u6307\u4ee4\u65f6,\u8fdb\u884c\u4e24\u6b65\u64cd\u4f5c:\n<![if !supportLists]>(1) <![endif]>\u5c06\u5f53\u524d\u7684IP\u6216CS\u548cIP\u538b\u5165\u6808\u4e2d\n<![if !supportLists]>(2) <![endif]>\u8f6c\u79fb\n<u>call\u4e0d\u80fd\u5b9e\u73b0\u77ed\u8f6c\u79fb\uff0c\u5176\u5b9e\u73b0\u8f6c\u79fb\u7684\u65b9\u6cd5\u548cjmp\u6307\u4ee4\u539f\u7406\u76f8\u540c<\/u><u><\/u>\n<![if !supportLists]>2. <![endif]>\u4f9d\u636e\u4f4d\u79fb\u8fdb\u884c\u8f6c\u79fb\u7684call\u6307\u4ee4\n<strong>call \u6807\u53f7<\/strong><strong><\/strong>\n<u>\u6b64\u6307\u4ee4\u5c06\u5f53\u524dIP\u538b\u5165\u6808\u4e2d,\u5e76\u8f6c\u5230\u6807\u53f7\u5904\u6267\u884c\u6307\u4ee4<\/u>\uff0c\u76f8\u5f53\u4e8e\u8fdb\u884c:\npush IP\njmp near ptr \u6807\u53f7\n\u5728call\u6307\u4ee4\u7684\u673a\u5668\u7801\u4e2d\u6ca1\u6709\u8f6c\u79fb\u7684\u76ee\u7684\u5730\u5740,\u800c\u662f\u4f4d\u79fb\n<strong><u>\u6ce8\u610f:\u8bfb\u53d6\u4e00\u6761\u6307\u4ee4\u540e,IP\u4e2d\u7684\u503c\u81ea\u52a8\u589e\u52a0,\u518d\u6267\u884c\u8bfb\u53d6\u7684\u6307\u4ee4<\/u><\/strong><strong><u><\/u><\/strong><\/code><\/pre>\n<p>\u68c0\u6d4b\u70b910.2<\/p>\n<p>\u4e0b\u9762\u7684\u7a0b\u5e8f\u6267\u884c\u540e\uff0cax\u4e2d\u7684\u6570\u503c\u4e3a\u591a\u5c11\uff1f<\/p>\n<pre><code>\u5185\u5b58\u5730\u5740    \u673a\u5668\u7801      \u6c47\u7f16\u6307\u4ee4     \u6267\u884c\u540e\u60c5\u51b5\n1000:0     b8 00 00     mov ax,0     ax=0 ip\u6307\u54111000:3\n1000:3     e8 01 00     call s       pop ip ip\u6307\u54111000:7\n1000:6     40           inc ax\n1000:7     58         s:pop ax       ax=6\n\u7528debug\u8fdb\u884c\u8ddf\u8e2a\u786e\u8ba4\uff0c\u201ccall \u6807\u53f7\u201d\u662f\u5c06\u8be5\u6307\u4ee4\u540e\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282\u504f\u79fb\u5730\u5740\u5165\u6808\uff0c\u518d\u8f6c\u5230\u6807\u53f7\u5904\u6267\u884c\u6307\u4ee4\u3002\n<![if !supportLists]>3. <![endif]>\u8f6c\u79fb\u7684\u76ee\u7684\u5730\u5740\u5728\u6307\u4ee4\u4e2d\u7684call\u6307\u4ee4\n<strong>call far ptr \u6807\u53f7<\/strong><strong><\/strong>\n\u8be5\u6307\u4ee4\u5b9e\u73b0\u6bb5\u95f4\u8f6c\u79fb\uff0c\u76f8\u5f53\u4e8e:\npush CS\npush IP\njmp far ptr \u6807\u53f7<\/code><\/pre>\n<p>\u68c0\u6d4b\u70b910.3<\/p>\n<p>\u4e0b\u9762\u7684\u7a0b\u5e8f\u6267\u884c\u540e\uff0cax\u4e2d\u7684\u6570\u503c\u4e3a\u591a\u5c11\uff1f <\/p>\n<pre><code>\u5185\u5b58\u5730\u5740   \u673a\u5668\u7801           \u6c47\u7f16\u6307\u4ee4            \u6267\u884c\u540e\u60c5\u51b5 \n1000:0    b8 00 00          mov ax,0           ax=0,ip\u6307\u54111000:3 \n1000:3    9a 09 00 00 10    call far ptr s     pop cs,pop ip,ip\u6307\u54111000:9 \n1000:8    40                inc ax \n1000:9    58                s:pop ax           ax=8h \n                            add ax,ax          ax=10h \n                            pop bx             bx=1000h \n                            add ax,bx          ax=1010h \n\u7528debug\u8fdb\u884c\u8ddf\u8e2a\u786e\u8ba4\uff0c\u201ccall far ptr s\u201d\u662f\u5148\u5c06\u8be5\u6307\u4ee4\u540e\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282\u6bb5\u5730\u5740cs=1000h\u5165\u6808\uff0c\u518d\u5c06\u504f\u79fb\u5730\u5740ip=8h\u5165\u6808\uff0c\u6700\u540e\u8f6c\u5230\u6807\u53f7\u5904\u6267\u884c\u6307\u4ee4\u3002 <\/code><\/pre>\n<p>\u51fa\u6808\u65f6\uff0c\u6839\u636e\u6808\u5148\u8fdb\u540e\u51fa\u7684\u539f\u5219\uff0c\u5148\u51fa\u7684\u4e3aip\uff1d8h\uff0c\u540e\u51fa\u7684\u4e3acs\uff1d1000h<\/p>\n<pre><code><![if !supportLists]>4. <![endif]>\u8f6c\u79fb\u5730\u5740\u5728\u5bc4\u5b58\u5668\u4e2d\u7684call\u6307\u4ee4\n<strong>call <\/strong><strong> 16\u4f4dreg<\/strong><strong><\/strong><\/code><\/pre>\n<p>\u76f8\u5f53\u4e8e:<\/p>\n<pre><code>push IP\njmp 16\u4f4dreg<\/code><\/pre>\n<p>\u68c0\u6d4b\u70b910.4<\/p>\n<p>\u4e0b\u9762\u7684\u7a0b\u5e8f\u6267\u884c\u540e\uff0cax\u4e2d\u7684\u6570\u503c\u4e3a\u591a\u5c11\uff1f<\/p>\n<pre><code>\u5185\u5b58\u5730\u5740   \u673a\u5668\u7801        \u6c47\u7f16\u6307\u4ee4       \u6267\u884c\u540e\u60c5\u51b5\n1000:0     b8 06 00      mov ax,6       ax=6,ip\u6307\u54111000:3\n1000:3     ff d0         call ax        pop ip,ip\u6307\u54111000:6\n1000:5     40            inc ax\n1000:6     58            mov bp,sp      bp=sp=fffeh\n                         add ax,[bp]    ax=[6+ds:(fffeh)]=6+5=0bh\n\u7528debug\u8fdb\u884c\u8ddf\u8e2a\u786e\u8ba4\uff0c\u201ccall ax(16\u4f4dreg)\u201d\u662f\u5148\u5c06\u8be5\u6307\u4ee4\u540e\u7684\u7b2c\u4e00\u4e2a\u5b57\u8282\u504f\u79fb\u5730\u5740ip\u5165\u6808\uff0c\u518d\u8f6c\u5230\u504f\u79fb\u5730\u5740\u4e3aax(16\u4f4dreg)\u5904\u6267\u884c\u6307\u4ee4\u3002\n<![if !supportLists]>5. <![endif]>\u8f6c\u79fb\u5730\u5740\u5728\u5185\u5b58\u4e2d\u7684call\u6307\u4ee4\n<![if !supportLists]>(1) <![endif]><strong>call word ptr \u5185\u5b58\u5355\u5143\u5730\u5740<\/strong><strong><\/strong><\/code><\/pre>\n<p>\u76f8\u5f53\u4e8e:<\/p>\n<pre><code>push IP\njmp word ptr \u5185\u5b58\u5355\u5143\u5730\u5740\n<![if !supportLists]>(2) <![endif]><strong>call dword ptr \u5185\u5b58\u5355\u5143\u5730\u5740<\/strong><strong><\/strong><\/code><\/pre>\n<p>\u76f8\u5f53\u4e8e:<\/p>\n<pre><code>push CS\npush IP\njmp dword ptr \u5185\u5b58\u5355\u5143\u5730\u5740<\/code><\/pre>\n<p>\u68c0\u6d4b\u70b910.5<\/p>\n<p>(1)\u4e0b\u9762\u7684\u7a0b\u5e8f\u6267\u884c\u540e\uff0cax\u4e2d\u7684\u6570\u503c\u4e3a\u591a\u5c11\uff1f<\/p>\n<pre><code>assume cs:code\nstack segment\ndw 8 dup (0)\nstack ends\ncode segment\nstart:mov ax,stack\nmov ss,ax\nmov sp,16\nmov ds,ax\nmov ax,0\ncall word ptr ds:[0eh]\ninc ax\ninc ax\ninc ax\nmov ax,4c00h\nint 21h\ncode ends\nend start\n\u6267\u884ccall word ptr ds:[0eh]\u6307\u4ee4\u65f6\uff0c\u5148cs\u5165\u6808\uff0c\u518dip=11\u5165\u6808\uff0c\u6700\u540eip\u8f6c\u79fb\u5230(ds:[0eh])\u3002(ds:[0eh])=11h\uff0c\u6267\u884cinc ax\u6700\u7ec8ax=3<\/code><\/pre>\n<p>(2)\u4e0b\u9762\u7684\u7a0b\u5e8f\u6267\u884c\u540e\uff0cax\u548cbx\u4e2d\u7684\u6570\u503c\u4e3a\u591a\u5c11\uff1f<\/p>\n<pre><code>assume cs:codesg\nstack segment\n    dw 8 dup(0)\nstack ends\ncodesg segment\nstart:\n    mov ax,stack\n    mov ss,ax\n    mov sp,10h\n    mov word ptr ss:[0],offset s ;(ss:[0])=1ah\n    mov ss:[2],cs                ;(ss:[2])=cs\n    call dword ptr ss:[0]        ;cs\u5165\u6808,ip=19h\u5165\u6808,\u8f6c\u5230cs:1ah\u5904\u6267\u884c\u6307\u4ee4\n                                 ;(ss:[4])=cs,(ss:[6])=ip\n    nop\ns:  mov ax,offset s              ;ax=1ah\n    sub ax,ss:[0ch]              ;<b >ax<\/strong>=1ah-(ss:[0ch])=1ah-19h<b >=1<\/strong>\n    mov bx,cs                    ;bx=cs\uff1d0c5bh\n    sub bx,ss:[0eh]              ;<b >bx<\/strong>=cs-cs<b >=0<\/strong>\n    mov ax,4c00h\n    int 21h\ncodesg ends\nend start\n10.7 call\u548cret\u7684\u914d\u5408\u4f7f\u7528<\/code><\/pre>\n<p>\u5b50\u7a0b\u5e8f\u7684\u6846\u67b6:<\/p>\n<p>\u6807\u53f7:<\/p>\n<pre><code>\u6307\u4ee4\nret<\/code><\/pre>\n<p>\u5177\u6709\u5b50\u7a0b\u5e8f\u7684\u6e90\u7a0b\u5e8f\u6846\u67b6:<\/p>\n<pre><code>assume cs:code\ncode segment<\/code><\/pre>\n<p>main:;\u4e3b\u7a0b\u5e8f<\/p>\n<pre><code>...\ncall sub1;\u8c03\u7528\u5b50\u7a0b\u5e8f\n...\nmov ax,4c00h\nint 21h\nsub1:\n...\ncall sub2;\u8c03\u7528\u5b50\u7a0b\u5e8f\n...\nret;\u8fd4\u56de\nsub2:\n...\nret;\u8fd4\u56de\ncode ends\nend\n10.8 mul\u6307\u4ee4\nmul\u6307\u4ee4\u4e3a\u4e58\u6cd5\u6307\u4ee4\uff0c\u7528\u6cd5\u5982\u4e0b\n<![if !supportLists]>(1) <![endif]><u>\u4e24\u4e2a\u4e58\u6570:\u8981\u4e48\u90fd\u662f8\u4f4d\uff0c\u8981\u4e48\u90fd\u662f16\u4f4d\u30028\u4f4d\u4e58\u6cd5\u4e2d\uff0c\u4e00\u4e2a\u4e58\u6570\u653e\u5728AL\u4e2d,\u4e00\u4e2a\u653e\u57288\u4f4d\u5185\u5b58\u5b57\u8282\u5355\u5143\u62168\u4f4dreg\u4e2d\uff1b16\u4f4d\u4e58\u6cd5\u4e2d,\u4e00\u4e2a\u4e58\u6570\u653e\u5728AX\u4e2d,\u53e6\u4e00\u4e2a\u653e\u572816\u4f4dreg\u6216\u5bc4\u5b58\u5668\u4e2d.<\/u><u><\/u>\n<![if !supportLists]>(2) <![endif]><u>\u7ed3\u679c:8\u4f4d\u4e58\u6cd5\u5728AX\u4e2d,16\u4f4d\u4e58\u6cd5\u5728DX\u548cAX\u4e2d(DX\u653e\u9ad816\u4f4d,AX\u653e\u4f4e16\u4f4d)<\/u><u><\/u>\n<![if !supportLists]>(3) <![endif]><u>\u683c\u5f0f:<\/u><u><\/u>\n<u>mul reg<\/u><u><\/u>\n<u>mul \u5185\u5b58\u5355\u5143(\u6ce8\u610f:\u8981\u7528byte ptr\u548cword ptr\u6307\u51fa\u662f8\u4f4d\u8fd8\u662f16\u4f4d\u4e58\u6cd5)<\/u><u><\/u><\/code><\/pre>\n<p>10.9~10.11 \u6a21\u5757\u5316\u8bbe\u8ba1 &#038; \u9644\u6ce84 \u7528\u6808\u4f20\u9012\u53c2\u6570<\/p>\n<p>1.\u4f20\u9012\u53c2\u6570\u548c\u8fd4\u56de:\u4f7f\u7528\u6307\u5b9a\u7684\u5bc4\u5b58\u5668\u6216\u5185\u5b58\u5355\u5143<\/p>\n<p><strong>2.\u7528\u6808\u4f20\u9012\u53c2\u6570<\/strong><strong><\/strong><\/p>\n<p><strong>\u539f\u7406:\u5c06\u8981\u4f20\u9012\u7ed9\u5b50\u7a0b\u5e8f\u7684\u53c2\u6570\u538b\u5165\u6808\u4e2d,\u5b50\u7a0b\u5e8f\u4ece\u6808\u4e2d\u53d6\u5f97\u53c2\u6570<\/strong><strong><\/strong><\/p>\n<p><strong>\u4e3e\u4f8b:\u8ba1\u7b97(a-b)^3,a\u3001b\u4e3a\u5b57\u578b\u6570\u636e<\/strong><strong><\/strong><\/p>\n<pre><code><strong>difcube:<\/strong><strong><\/strong>\n<strong>push bp<\/strong><strong><\/strong>\n<strong>mov bp,sp<\/strong><strong><\/strong>\n<strong>mov ax,[bp+4]<\/strong><strong>;ax=a<\/strong><strong>[bp+4]=byte a<\/strong><strong><\/strong>\n<strong>sub ax,[bp+6]<\/strong><strong>;a=a-b <\/strong><strong>[bp+6]=byte b<\/strong><strong><\/strong>\n<strong>mov bp,ax<\/strong><strong><\/strong>\n<strong>mul bp<\/strong><strong><\/strong>\n<strong>mul bp<\/strong><strong><\/strong>\n<strong>pop bp<\/strong><strong><\/strong>\n<strong>ret 4<\/strong><strong><\/strong>\n<strong>\u6307\u4ee4ret n\u7684\u542b\u4e49:<\/strong><strong><\/strong>\n<strong>pop ip<\/strong><strong><\/strong>\n<strong>add sp,n<\/strong><strong><\/strong>\n<strong>\u7531\u4e8e\u7528\u6808\u4f20\u9012\u53c2\u6570,\u5728\u8c03\u7528\u65f6\u5411\u6808\u4e2d\u538b\u5165\u53c2\u6570,\u5b50\u7a0b\u5e8f\u5728\u8fd4\u56de\u7684\u65f6\u5019\u53ef\u4ee5\u7528ret n\u5c06\u6808\u9876\u6307\u9488\u6062\u590d\u3002\u8c03\u7528\u4ee5\u4e0a\u7a0b\u5e8f\u7684\u8fc7\u7a0b:<\/strong><strong><\/strong>\n<strong>mov ax,1<\/strong><strong><\/strong>\n<strong>push ax<\/strong><strong><\/strong>\n<strong>mov ax,3<\/strong><strong><\/strong>\n<strong>push ax<\/strong><strong><\/strong>\n<strong>call difcube<\/strong><strong><\/strong>\n<strong>\u6b64\u65f6\u9700\u6ce8\u610f\u53c2\u6570\u7684\u538b\u6808\u987a\u5e8f<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong>\u793a\u4f8b\uff1aC\u8bed\u8a00\u7f16\u8bd1\u4e3a\u6c47\u7f16<\/strong><strong><\/strong><\/p>\n<p><strong>C\u7a0b\u5e8f<\/strong><strong><\/strong><\/p>\n<pre><code><strong>void add(int,int,int);<\/strong><strong><\/strong>\n<strong>int main(void)<\/strong><strong><\/strong>\n<strong>{<\/strong><strong><\/strong>\n<strong>int a=1;<\/strong><strong><\/strong>\n<strong>int b=2;<\/strong><strong><\/strong>\n<strong>int c=0;<\/strong><strong><\/strong>\n<strong>add(a,b,c);<\/strong><strong><\/strong>\n<strong>c++;<\/strong><strong><\/strong>\n<strong>}<\/strong><strong><\/strong>\n<strong>void add(int a,int b,int c)<\/strong><strong><\/strong>\n<strong>{<\/strong><strong><\/strong>\n<strong>c=a+b;<\/strong><strong><\/strong>\n<strong>}<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong>main()\u51fd\u6570\u4e0d\u662f\u7a0b\u5e8f\u542f\u52a8\u540e\u6267\u884c\u7684\u7b2c\u4e00\u4e2a\u51fd\u6570\uff0c\u8fd8\u6709\u522b\u7684\u51fd\u6570\u8c03\u7528main()<\/strong><strong><\/strong><\/p>\n<pre><code><strong>\u5c40\u90e8\u53d8\u91cf\u4e5f\u5728\u6808\u4e2d\u5b58\u50a8<\/strong><strong><\/strong>\n<strong>\u6c47\u7f16\u7a0b\u5e8f<\/strong><strong><\/strong>\n<strong>main:<\/strong><strong>;int main(void)<\/strong><strong><\/strong>\n<strong>mov bp,sp<\/strong><strong><\/strong>\n<strong>sub sp,6<\/strong><strong>;\u7ed9\u5c40\u90e8\u53d8\u91cf\u8ba9\u51fa\u7a7a\u95f4<\/strong><strong><\/strong>\n<strong>mov word ptr[bp-6],0001<\/strong><strong>;int a=1<\/strong><strong><\/strong>\n<strong>mov word ptr[bp-4],0002<\/strong><strong>;int b=2<\/strong><strong><\/strong>\n<strong>mov word ptr[bp-2],0000<\/strong><strong>;int c=0<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong>;\u4ee5\u4e0a\u4e3amain()\u7684\u5c40\u90e8\u53d8\u91cfa,b,c<\/strong><strong><\/strong><\/p>\n<pre><code><strong>push [bp-2]<\/strong><strong><\/strong>\n<strong>push [bp-4]<\/strong><strong><\/strong>\n<strong>push [bp-6]<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong>;\u4f20\u53c2<\/strong><strong><\/strong><\/p>\n<pre><code><strong>call add<\/strong><strong>;add(a,b,c)<\/strong><strong><\/strong>\n<strong>add sp,6<\/strong><strong>;\u6e05\u7406\u8c03\u7528\u7684\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u548c\u53c2\u6570<\/strong><strong><\/strong>\n<strong>inc word ptr [bp-2]<\/strong><strong>;c++<\/strong><strong><\/strong>\n<strong>add:<\/strong><strong><\/strong>\n<strong>push bp<\/strong><strong>;\u5907\u4efdbp<\/strong><strong><\/strong>\n<strong>mov bp,sp<\/strong><strong><\/strong>\n<strong>mov ax,[bp+4]<\/strong><strong>;AX=a<\/strong><strong><\/strong>\n<strong>add ax,[bp+6]<\/strong><strong>;AX=a+b<\/strong><strong><\/strong>\n<strong>mov [bp+8],ax<\/strong><strong>;c=a+b<\/strong><strong><\/strong>\n<strong>mov sp,bp<\/strong><strong><\/strong>\n<strong>pop bp<\/strong><strong>;\u6062\u590dbp<\/strong><strong><\/strong>\n<strong>ret<\/strong><strong><\/strong><\/code><\/pre>\n<p>10.12 \u5bc4\u5b58\u5668\u51b2\u7a81\u7684\u95ee\u9898<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5:\u5728\u5b50\u7a0b\u5e8f\u7684\u5f00\u59cb\u5c06\u5b50\u7a0b\u5e8f\u4e2d\u6240\u6709\u7528\u5230\u7684\u5bc4\u5b58\u5668\u4e2d\u7684\u5185\u5bb9\u90fd\u5165\u6808\u4fdd\u5b58\u8d77\u6765,\u5728\u5b50\u7a0b\u5e8f\u8fd4\u56de\u524d\u6062\u590d\u3002<\/p>\n<p><strong>\u5b50\u7a0b\u5e8f\u7684\u6846\u67b6:<\/strong><strong><\/strong><\/p>\n<p><strong>\u5b50\u7a0b\u5e8f:\u5b50\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u7684\u5bc4\u5b58\u5668\u5165\u6808<\/strong><strong><\/strong><\/p>\n<pre><code><strong>\u5b50\u7a0b\u5e8f\u5185\u5bb9<\/strong><strong><\/strong>\n<strong>\u5b50\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u7684\u5bc4\u5b58\u5668\u51fa\u6808<\/strong><strong><\/strong>\n<strong>\u8fd4\u56de(ret\\retf)<\/strong><strong><\/strong><\/code><\/pre>\n<p>\u793a\u4f8b:\u5c0f\u5199\u8f6c\u5927\u5199\u7a0b\u5e8f:<\/p>\n<pre><code>capital:push cx\npush si\nchange:mov cl,[si]\nmov ch,0<\/code><\/pre>\n<p>jcxz ok<\/p>\n<pre><code>and byte ptr[si],11011111b\ninc si\njmp short change\nok:pop si\npop cx\nret<\/code><\/pre>\n<p><strong>\u5b9e\u9a8c10 \u7f16\u5199\u5b50\u7a0b\u5e8f<\/strong><strong><\/strong><\/p>\n<pre><code><![if !supportLists]>1. <![endif]>\u663e\u793a\u5b57\u7b26\u4e32\n\u5b50\u7a0b\u5e8f\u63cf\u8ff0<\/code><\/pre>\n<p>\u540d\u79f0:show_str<\/p>\n<p>\u529f\u80fd:\u5728\u6307\u5b9a\u7684\u4f4d\u7f6e\u4f7f\u7528\u6307\u5b9a\u7684\u989c\u8272,\u663e\u793a\u4e00\u4e2a\u75280\u7ed3\u675f\u7684\u5b57\u7b26\u4e32<\/p>\n<p>\u53c2\u6570:(dh)=\u884c\u53f7(\u53d6\u503c\u8303\u56f40~24),(dl)=\u5217\u53f7(\u53d6\u503c\u8303\u56f40~79)<\/p>\n<p>(cl)=\u989c\u8272,ds:si\u6307\u5411\u5b57\u7b26\u4e32\u9996\u5730\u5740<\/p>\n<p>\u8fd4\u56de:\u65e0<\/p>\n<p>Program ex-10-1 \u81ea\u4e3b\u89e3\u6cd5<\/p>\n<pre><code>assume cs<strong>:<\/strong>code,ds<strong>:<\/strong>data,ss<strong>:<\/strong>stack<br>data segment<br>    db <strong>'<\/strong>welcome to masm!<strong>'<\/strong>,0<br>data ends<br>stack segment<br>    db 256 dup<strong>(<\/strong>0<strong>)<\/strong><strong><br><\/strong>stack ends<br>code segment<br>start<strong>:<\/strong><strong><br><\/strong>    <strong>mov<\/strong> ax,stack<br>    <strong>mov<\/strong> ss,ax<br>    <strong>mov<\/strong> sp,256    <i>;ss:sp=stack:256<\/i><i><br><\/i>    <br>    <strong>mov<\/strong> dh,8    <i>;row=8<\/i><i><br><\/i>    <strong>mov<\/strong> dl,3    <i>;line=3<\/i><i><br><\/i>    <strong>mov<\/strong> cl,2    <i>;color=2<\/i><i><br><\/i>    <strong>mov<\/strong> ax,data<br>    <strong>mov<\/strong> ds,ax<br>    <strong>mov<\/strong> si,0    <i>;str=data:0<\/i><i><br><\/i>    <strong>call<\/strong> show_str<br>    <br>    <strong>mov<\/strong> ax,4c00h<br>    <strong>int<\/strong> 21h<br>show_str<strong>:<\/strong><strong><br><\/strong><i>;show_str(byte row=(dh),byte line=(dl),<\/i><i><br><\/i><i>;byte color=(cl),const char* str =(ds:si));<\/i><i><br><\/i><i>;\u663e\u5b58\u504f\u79fb\u5730\u5740offset_display=row*160+line*2<\/i><i><br><\/i>    <strong>push<\/strong> ax<br>    <strong>push<\/strong> bx<br>    <strong>push<\/strong> cx<br>    <strong>push<\/strong> dx<br>    <strong>push<\/strong> si<br>    <strong>push<\/strong> di<br>    <strong>push<\/strong> es<br>    <br>    <strong>mov<\/strong> al,dh<br>    <strong>mov<\/strong> ah,160<br>    <strong>mul<\/strong> ah        <i>;AX=row*160<\/i><i><br><\/i>    <strong>mov<\/strong> bh,0    <br>    <strong>mov<\/strong> bl,dl    <i>;BX=(word)line<\/i><i><br><\/i>    <strong>add<\/strong> ax,bx<br>    <strong>add<\/strong> ax,bx    <i>;AX=offset_display=row*160+line*2<\/i><i><br><\/i>    <strong>mov<\/strong> di,ax    <i>;DI=offset_display<\/i><i><br><\/i>    <br>    <strong>mov<\/strong> ax,0b800h<br>    <strong>mov<\/strong> es,ax    <i>;ES=\u663e\u793a\u7f13\u51b2\u533a<\/i><i><br><\/i>    <strong>mov<\/strong> dl,cl    <i>;DL=color<\/i><i><br><\/i>    <i>;es:di \u6307\u5411\u663e\u5b58\u663e\u793a\u7f13\u51b2\u533a\u7684\u6307\u9488<\/i><i><br><\/i>display<strong>:<\/strong><strong><br><\/strong>    <strong>mov<\/strong> ch,0<br>    <strong>mov<\/strong> cl,[si]    <i>;CX=(word)(DS:SI)<\/i><i><br><\/i>    <strong>jcxz<\/strong> ok        <i>;if((cx)==0) return;<\/i><i><br><\/i>    <strong>mov<\/strong> es<strong>:<\/strong>[di],cl    <i>;(ES:DI)=(DS:SI)<\/i><i><br><\/i>    <strong>mov<\/strong> es<strong>:<\/strong>[di<strong>+<\/strong>1],dl<i>;(ES:DI+1)=color<\/i><i><br><\/i>    <strong>add<\/strong> di,2<br>    <strong>add<\/strong> si,1<br>    <strong>jmp<\/strong> display<br>    <br>ok<strong>:<\/strong>    <strong>pop<\/strong> es<br>    <strong>pop<\/strong> di<br>    <strong>pop<\/strong> si<br>    <strong>pop<\/strong> dx<br>    <strong>pop<\/strong> cx<br>    <strong>pop<\/strong> bx<br>    <strong>pop<\/strong> ax<br>    <strong>ret<\/strong><strong><br><\/strong>code ends<br>end start<\/code><\/pre>\n<p>Program ex-10-2 \u53c2\u8003\u89e3\u6cd5<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" width=\"330\"  height=\"166\"  src=\"http:\/\/8.129.82.128\/wp-content\/uploads\/2026\/03\/asm202405\u7248\u63d0\u7eb242603.png\" > <\/p>\n<pre><code>;\u6548\u679c\u56fe<\/code><\/pre>\n<p>;\u5728\u5c4f\u5e55\u76848\u884c3\u4f8b\uff0c\u7528\u7eff\u8272\u663e\u793adata\u6bb5\u4e2d\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<pre><code>assume cs:code,ds:data\ndata segment\ndb 'welcome to masm!',0\ndata ends\ncode segment\nstart:mov dh,8\nmov dl,3\nmov cl,2\nmov ax,data\nmov ds,ax\nmov si,0\ncall show_str<\/code><\/pre>\n<p> <\/p>\n<pre><code>mov ax,4c00h\nint 21h\nshow_str:\npush ax\npush bx\npush es\npush si\nmov ax,0b800h\nmov es,ax\nmov ax,160\nmul dh\nmov bx,ax;bx=160*dh\nmov ax,2\nmul dl;ax=dl*2\nadd bx,ax;mov bx,(160*dh+dl*2)\u8bbe\u7f6ees:bx\u6307\u5411\u663e\u5b58\u9996\u5730\u5740\nmov al,cl;\u628a\u989c\u8272cl\u8d4b\u503cal\nmov cl,0\nshow0:\nmov ch,[si]<\/code><\/pre>\n<p>jcxz show1;(ds:si)=0\u65f6\uff0c\u8f6c\u5230show1\u6267\u884c<\/p>\n<pre><code>mov es:[bx],ch\nmov es:[bx].1,al\ninc si;ds:si\u6307\u5411\u4e0b\u4e00\u4e2a\u5b57\u7b26\u5730\u5740\nadd bx,2;es:bx\u6307\u5411\u4e0b\u4e00\u4e2a\u663e\u5b58\u5730\u5740\njmp show0\nshow1:\npop si\npop es\npop bx\npop ax\nret<\/code><\/pre>\n<p> <\/p>\n<pre><code>code ends\nend start\n<![if !supportLists]>2. <![endif]>\u89e3\u51b3\u9664\u6cd5\u6ea2\u51fa\u7684\u95ee\u9898<\/code><\/pre>\n<p>\u5982\u679c\u7ed3\u679c\u7684\u5546\u5927\u4e8eAL\u6216AX\u6240\u80fd\u5b58\u50a8\u7684\u6700\u5927\u503c,\u4fbf\u4f1a\u5f15\u53d1CPU\u7684\u4e00\u4e2a\u5185\u90e8\u9519\u8bef\u51fa\u73b0\u9664\u6cd5\u6ea2\u51fa<\/p>\n<pre><code>\u5b50\u7a0b\u5e8f\u63cf\u8ff0<\/code><\/pre>\n<p>\u540d\u79f0:divdw<\/p>\n<p>\u529f\u80fd:\u8fdb\u884c\u4e0d\u4f1a\u6ea2\u51fa\u7684\u9664\u6cd5\u64cd\u4f5c\uff0c\u88ab\u9664\u6570\u4e3adword\u578b,\u9664\u6570\u4e3aword\u578b,\u7ed3\u679c\u4e3adword\u578b<\/p>\n<p>\u53c2\u6570:(ax)=dword\u578b\u6570\u636e\u7684\u4f4e16\u4f4d\uff0c(dx)=dword\u578b\u6570\u636e\u7684\u9ad816\u4f4d\uff0c(cx)=\u9664\u6570<\/p>\n<p>\u8fd4\u56de:(dx)=\u7ed3\u679c\u7684\u9ad816\u4f4d,(ax)=\u7ed3\u679c\u7684\u4f4e16\u4f4d,(cx)=\u4f59\u6570<\/p>\n<pre><code>\u63d0\u793a\nx\/n=int(h\/n)*65536+[rem(h\/n)*65536+l]\/n<\/code><\/pre>\n<p>x:\u88ab\u9664\u6570\uff0c\u8303\u56f4[0,FFFFFFFF]<\/p>\n<p>n:\u9664\u6570,\u8303\u56f4[0,FFFF]<\/p>\n<p>h:x\u9ad816\u4f4d<\/p>\n<p>l:x\u4f4e16\u4f4d<\/p>\n<p>int()\u53d6\u5546<\/p>\n<p>rem()\u53d6\u4f59<\/p>\n<p>\u516c\u5f0f\u7684\u8bc1\u660e:<\/p>\n<p>\u8bc1\u660e\u6cd51:<\/p>\n<p>\u5c06\u8ba1\u7b97 X \/ n \u5206\u89e3\u4e3a\u8ba1\u7b97\uff1a<\/p>\n<pre><code>( H \/ n ) * 65536 + ( L \/ n ) \uff1b H = int ( x \/ 65536 ) \uff1b L = rem ( x \/ 65536 )\nDIV \u6307\u4ee4\u53ea\u80fd\u5f97\u51fa\u4f59\u6570\u548c\u5546\uff0c\u800c\u6211\u4eec\u53ea\u4fdd\u7559\u5546\u3002\u4f59\u6570\u5fc5\u7136\u5c0f\u4e8e\u9664\u6570\uff0c\u4e00\u6b21\u6b63\u786e\u7684\u9664\u6cd5\u8fd0\u7b97\u53ea\u80fd\u4e22\u6389\u4e00\u4e2a\u4f59\u6570\u3002\u6211\u4eec\u867d\u7136\u5728\u5177\u4f53\u5904\u7406\u65f6\u8fdb\u884c\u4e86\u4e24\u6b21\u9664\u6cd5\u8fd0\u7b97 ( H \/ n ) \u548c ( L \/ n ) \uff1b\u4f46\u8fd9\u5b9e\u8d28\u4e0a\u662f\u4e00\u6b21\u9664\u6cd5\u8fd0\u7b97\uff08X \/ n\uff09\u95ee\u9898\u7684\u5206\u89e3\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e3a\u4fdd\u8bc1\u6700\u7ec8\u7ed3\u679c\u7684\u6b63\u786e\uff0c\u4e24\u6b21\u9664\u6cd5\u8fd0\u7b97\u53ea\u80fd\u4e22\u6389\u4e00\u4e2a\u4f59\u6570\u3002<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u95ee\u9898\u4e2d\uff0cH \/ n \u4ea7\u751f\u7684\u4f59\u6570\u662f\u7edd\u5bf9\u4e0d\u80fd\u4e22\u7684\uff0c\u56e0\u4e3a\u4e22\u6389\u4e86\u5b83\uff08\u8bbe\u4e3a r \uff09\u5c31\u76f8\u5f53\u4e8e\u4e22\u6389\u4e86 r * 65536 \u3002<\/p>\n<p>\u90a3\u4e48\u5982\u4f55\u5904\u7406 \uff08 H \/ n \uff09\u4ea7\u751f\u7684\u4f59\u6570\u5462\uff1f<\/p>\n<pre><code>\u6211\u4eec\u77e5\u9053\uff1aH = int ( H \/ n) * n + rem ( H \/ n )\n\u6240\u4ee5\u6709\uff1a\n( H \/ n ) * 65536 + ( L \/ n )\n= [ int ( H \/ n) * n + rem ( H \/ n ) ] \/ n * 65536 + L \/ n\n= int ( H \/ n) * 65536 + rem ( H \/ n ) * 65536 \/ n  + L \/ n\n= int ( H \/ n) * 65536 + [ rem ( H \/ n ) * 65536 + L ] \/ n<\/code><\/pre>\n<p>\u73b0\u5728\u8bb2\u8ba1\u7b97X \/ n \u8f6c\u5316\u4e3a\u8ba1\u7b97\uff1a<\/p>\n<pre><code>int ( H \/ n) * 65536 + [ rem ( H \/ n ) * 65536 + L ] \/ n \uff1b\nH = int ( x \/ 65536 ) \uff1bL = rem ( x \/ 65536 ) \n\u5728\u8fd9\u91cc\u8981\u8fdb\u884c\u4e24\u6b21\u9664\u6cd5\u8fd0\u7b97\uff1a<\/code><\/pre>\n<p>\u7b2c\u4e00\u6b21\uff1a H \/ n<\/p>\n<p>\u7b2c\u4e8c\u6b21\uff1a [ rem ( H \/ n ) * 65536 + L ] \/ n<\/p>\n<pre><code>\u6211\u4eec\u77e5\u9053\u7b2c\u4e00\u6b21\u4e0d\u4f1a\u4ea7\u751f\u9664\u6cd5\u6ea2\u51fa\u3002\n\u73b0\u8bc1\u660e\u7b2c\u4e8c\u6b21\uff1a<\/code><\/pre>\n<p>\u2460L \u2264 65535<\/p>\n<p>\u2461rem ( H \/ n ) \u2264 n \u2013 1<\/p>\n<p>\u7531\u2461\u6709\uff1a<\/p>\n<p>\u2462rem ( H \/ n ) * 65536 \u2264 ( n \u2013 1 ) *65536<\/p>\n<p>\u7531\u2460\uff0c\u2462\u6709\uff1a<\/p>\n<p>&#9315;rem ( H \/ n ) * 65536 + L \u2264 ( n \u2013 1 ) *65536 + 65535<\/p>\n<p>\u7531&#9315;\u6709\uff1a<\/p>\n<p>&#9316;[ rem ( H \/ n ) * 65536 + L ] \/ n \u2264 [ ( n \u2013 1 ) *65536 + 65535 ] \/ n<\/p>\n<p>\u7531&#9316;\u6709\uff1a<\/p>\n<p>&#9317;[ rem ( H \/ n ) * 65536 + L ] \/ n \u2264 65536 \u2013 ( 1 \/ n )<\/p>\n<p>\u6240\u4ee5 [ rem ( H \/ n ) * 65536 + L ] \/ n \u4e0d\u4f1a\u4ea7\u751f\u9664\u6cd5\u6ea2\u51fa\u3002<\/p>\n<pre><code>\u5219\uff1aX \/ n = int ( H \/ n) * 65536 + [ rem ( H \/ n ) * 65536 + L ] \/ n \uff1b\nH = int ( x \/ 65536 ) \uff1bL = rem ( x \/ 65536 ) <\/code><\/pre>\n<p><strong>\u8bc1\u660e\u6cd52:\u6570\u5b66\u8bc1\u660e<\/strong><strong><\/strong><\/p>\n<p><img decoding=\"async\" width=\"326\"  height=\"491\"  src=\"http:\/\/8.129.82.128\/wp-content\/uploads\/2026\/03\/asm202405\u7248\u63d0\u7eb244861.png\" ><\/p>\n<p><strong>Program ex-10-3 \u81ea\u4e3b\u89e3\u6cd5<\/strong><strong><\/strong><\/p>\n<pre><code>assume cs<strong>:<\/strong>code,ds<strong>:<\/strong>data,ss<strong>:<\/strong>stack<br>data segment<br>    db 256 dup<strong>(<\/strong>0<strong>)<\/strong><strong><br><\/strong>data ends<br>stack segment<br>    db 256 dup<strong>(<\/strong>0<strong>)<\/strong><strong><br><\/strong>stack ends<br>code segment<br>start<strong>:<\/strong><strong><br><\/strong>    <strong>mov<\/strong> ax,stack<br>    <strong>mov<\/strong> ss,ax    <i>;ss=stack<\/i><i><br><\/i>    <strong>mov<\/strong> sp,256<br>    <strong>mov<\/strong> ax,data<br>    <strong>mov<\/strong> ds,ax    <i>;ds=data<\/i><i><br><\/i>    <strong>mov<\/strong> ax,4240h<i>;L(16bit)<\/i><i><br><\/i>    <strong>mov<\/strong> dx,000fh<i>;H(16bit)<\/i><i><br><\/i>    <strong>mov<\/strong> cx,0ah    <i>;N(16bit)<\/i><i><br><\/i>    <i>;\u8ba1\u7b971000000\/10(F4240h\/0ah)<\/i><i><br><\/i>    <strong>call<\/strong> divdw<br>    <strong>mov<\/strong> ax,4c00h<br>    <strong>int<\/strong> 21h<br>divdw<strong>:<\/strong><strong><br><\/strong>    <strong>push<\/strong> si<br>    <strong>mov<\/strong> si,0<br>    <strong>mov<\/strong> [si],ax        <i>;ds:0=l<\/i><i><br><\/i>    <strong>mov<\/strong> [si<strong>+<\/strong>2],dx    <i>;ds:2=h<\/i><i><br><\/i>    <strong>mov<\/strong> [si<strong>+<\/strong>4],cx    <i>;ds:4=n<\/i><i><br><\/i>    <i>;x\/n=int(h\/n)*65536+[rem(h\/n)*65536+l]\/n<\/i><i><br><\/i>    <i>;\u8ba1\u7b97int(h\/n)<\/i><i><br><\/i>    <i>;\u4e0d\u8981\u4e58\u4ee565536!\u76f4\u63a5\u4f5c\u4e3a\u4e00\u4e2a\u53cc\u5b50\u6570\u636e\u9ad816\u4f4d\u5904\u7406<\/i><i><br><\/i>    <i>;int(h\/n)\u662f\u7ed3\u679c\u5f97\u9ad816\u4f4d<\/i><i><br><\/i>    <strong>mov<\/strong> ax,[si<strong>+<\/strong>2]<br>    <strong>mov<\/strong> dx,0<br>    <strong>div<\/strong> word ptr[si<strong>+<\/strong>4]<br>    <strong>mov<\/strong> [si<strong>+<\/strong>6],ax    <i>;int(h\/n) \u5546<\/i><i><br><\/i>    <strong>mov<\/strong> [si<strong>+<\/strong>8],dx    <i>;rem(h\/n) \u4f59\u6570<\/i><i><br><\/i>    <i>;\u8ba1\u7b97[rem(h\/n)*65536+l]\/n<\/i><i><br><\/i>    <strong>mov<\/strong> ax,[si]<br>    <i>;(dx*0FFFFh+ax)=rem(h\/n)*65536+l<\/i><i><br><\/i>    <strong>div<\/strong> word ptr[si<strong>+<\/strong>4]<br>    <i>;ax=[rem(h\/n)*65536+l]\/n,\u4e3a\u7ed3\u679c\u7684\u4f4e16\u4f4d<\/i><i><br><\/i>    <i>;dx\u4e3a\u4f59\u6570,\u79fb\u5165cx<\/i><i><br><\/i>    <strong>mov<\/strong> cx,dx<br>    <strong>mov<\/strong> dx,[si<strong>+<\/strong>6]    <br>    <strong>pop<\/strong> si<br>    <strong>ret<\/strong><strong><br><\/strong>code ends<br>end start<\/code><\/pre>\n<p>Program ex-10-4\u53c2\u8003\u89e3\u6cd5<\/p>\n<p><img decoding=\"async\" width=\"290\"  height=\"147\"  src=\"http:\/\/8.129.82.128\/wp-content\/uploads\/2026\/03\/asm202405\u7248\u63d0\u7eb245886.png\"  align=\"left\"  hspace=\"12\" > <\/p>\n<p> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p> <\/p>\n<pre><code>\u6548\u679c\u56fe<\/code><\/pre>\n<p><strong>;\u5e94\u7528\u4e3e\u4f8b\uff1a\u8ba1\u7b971000000\/10(f4240h\/0ah)<\/strong><strong><\/strong><\/p>\n<pre><code><strong>assume cs:code<\/strong><strong><\/strong>\n<strong>code segment<\/strong><strong><\/strong>\n<strong>start:<\/strong><strong>mov ax,4240h<\/strong><strong><\/strong>\n<strong>mov dx,000fh<\/strong><strong><\/strong>\n<strong>mov cx,0ah<\/strong><strong><\/strong>\n<strong>call divdw<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong> <\/strong><\/p>\n<pre><code><strong>mov ax,4c00h<\/strong><strong><\/strong>\n<strong>int 21h<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong> <\/strong><\/p>\n<pre><code><strong>divdw:<\/strong><strong><\/strong>\n<strong>push si<\/strong><strong><\/strong>\n<strong>push bx<\/strong><strong><\/strong>\n<strong>push ax<\/strong><strong><\/strong>\n<strong>mov ax,dx<\/strong><strong><\/strong>\n<strong>mov dx,0<\/strong><strong><\/strong>\n<strong>div cx<\/strong><strong>;\u88ab\u9664\u6570\u7684\u9ad8\u4f4d\/cx,\u9ad8\u4f4d\u5728ax,\u4f59\u6570\u5728dx<\/strong><strong><\/strong>\n<strong>mov si,ax<\/strong><strong><\/strong>\n<strong>pop ax <\/strong><strong><\/strong>\n<strong>div cx<\/strong><strong>;(\u88ab\u9664\u6570\u9ad8\u4f4d\u7684\u5546+\u4f4e\u4f4d)\/cx,\u9ad8\u4f4d\u5728ax,\u4f59\u6570\u5728dx<\/strong><strong><\/strong>\n<strong>mov cx,dx<\/strong><strong>;\u4f59\u6570\u5165cx<\/strong><strong><\/strong>\n<strong>mov dx,si<\/strong><strong>;\u9ad8\u4f4d\u7684\u5546\u5165dx<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong> <\/strong><\/p>\n<pre><code><strong>pop bx<\/strong><strong><\/strong>\n<strong>pop si<\/strong><strong><\/strong>\n<strong>ret<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong> <\/strong><\/p>\n<pre><code><strong>code ends<\/strong><strong><\/strong>\n<strong>end start<\/strong>\n\u516c\u5f0fx\/n=int(h\/n)*65536+[rem(h\/n)*65536+l]\/n\u89e3\u6790\uff1a <\/code><\/pre>\n<p>\u5982\u679c\u9ad8\u4f4d\u9664\u6cd5\u6709\u5546\uff0c\u90a3\u4e48\u5546\u5c31\u662f\u7ed3\u679c\u7684\u9ad8\u4f4d\u503c\uff0c\u5982\u679c\u4f1a\u6709\u4f59\u6570\uff0c\u90a3\u4e48\u4f59\u6570\u81ea\u7136\u4e0d\u80fd\u4e22\u5f03\uff0c\u4f59\u6570\u5c31\u4f5c\u4e3a\u4f4e\u4f4d\u9664\u6cd5\u7684dx(\u4e5f\u5c31\u662f\u9ad8\u4f4d\u7684\u88ab\u9664\u6570\uff0c\u56e0\u4e3a\u4ed6\u662f\u4ece\u9ad8\u4f4d\u9664\u6cd5\u4e2d\u4f59\u4e0b\u7684\uff09  <\/p>\n<p>\u505a\u4f4e\u4f4d\u9664\u6cd5\u7684\u65f6\u5019\uff0c\u5c31\u62ff\u4f59\u4e0b\u7684dx+\u4f4e\u4f4d\u6570\u7684ax\u9664\u4ee5\u9664\u6570\uff0c\u4f1a\u5f97\u5230 \u4e00\u4e2a\u4f4e\u4f4d\u7684\u5546 \u548c \u4f59\u6570  <\/p>\n<p>\u9ad8\u4f4d\u7684\u5546+\u4f4e\u4f4d\u6570\u7684\u5546+\u4f59\u6570 \u5c31\u662f\u7ed3\u679c<\/p>\n<pre><code><![if !supportLists]>3. <![endif]>\u6570\u503c\u663e\u793a<\/code><\/pre>\n<p>\u7f16\u7a0b,\u5c06data\u6bb5\u4e2d\u7684\u6570\u636e\u4ee5\u5341\u8fdb\u5236\u5f62\u5f0f\u663e\u793a<\/p>\n<pre><code>\u5b50\u7a0b\u5e8f\u63cf\u8ff0<\/code><\/pre>\n<p>\u540d\u79f0: dtoc<\/p>\n<p>\u529f\u80fd:\u5c06word\u578b\u6570\u636e\u8f6c\u53d8\u4e3a\u8868\u793a\u5341\u8fdb\u5236\u5f62\u5f0f\u7684\u5b57\u7b26\u4e32\uff0c\u5b57\u7b26\u4e32\u4ee50\u7ed3\u5c3e<\/p>\n<p>\u53c2\u6570:(ax)=word\u578b\u6570\u636e<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"196\"  height=\"156\"  src=\"http:\/\/8.129.82.128\/wp-content\/uploads\/2026\/03\/asm202405\u7248\u63d0\u7eb246549.png\"  align=\"left\"  hspace=\"12\" >ds:si\u6307\u5411\u5b57\u7b26\u4e32\u7684\u9996\u5730\u5740<\/p>\n<p>\u8fd4\u56de:\u65e0<\/p>\n<pre><code>\u63d0\u793a\u4e0e\u5206\u6790<\/code><\/pre>\n<p>\u5341\u8fdb\u5236\u6570\u7801\u5b57\u7b26\u5bf9\u5e94\u7684ASCII\u7801=\u5341\u8fdb\u5236\u6570\u7801\u503c+30H<\/p>\n<p>\u6216\u8005\u7528\u6570\u7801\u503c+&#8217;0&#8217;\u4e5f\u53ef\u4ee5<\/p>\n<p>\u5f97\u51fa10\u8fdb\u5236\u6570\u6bcf\u4f4d\u7684\u503c\u7684\u65b9\u6cd5<\/p>\n<p>\u6ce8:\u8fd9\u4e0e10\u8fdb\u5236\u6570\u8f6c\u6362\u4e3a\u5176\u4ed6\u8fdb\u5236\u7684\u65b9\u6cd5\u7c7b\u4f3c\uff0c\u8be5\u7528\u6cd5\u76f8\u5f53\u4e8e\u752810\u8fdb\u5236\u8f6c\u636210\u8fdb\u5236<\/p>\n<pre><code>\u6ce8\u610f\u51fa\u6765\u7684\u4f59\u6570\u5e94\u8be5\u5012\u8fc7\u6765\u624d\u662f\u539f\u6765\u7684\u6570\u5b57<\/code><\/pre>\n<p>\u4f7f\u7528C++\u6f14\u793a\u539f\u7406:<\/p>\n<pre><code>#include<strong><<\/strong>iostream<strong>><\/strong><strong><br><\/strong><strong>using<\/strong> <strong>namespace<\/strong> <strong>std<\/strong><strong>;<\/strong><strong><br><\/strong><strong>int<\/strong> main<strong>()<\/strong><strong><br><\/strong><strong>{<\/strong><strong><br><\/strong>    <strong>int<\/strong> a<strong>=<\/strong>12666<strong>;<\/strong><strong><br><\/strong>    <strong>while<\/strong><strong>(<\/strong>a<strong>!=<\/strong>0<strong>)<\/strong><strong><br><\/strong>    <strong>{<\/strong><strong><br><\/strong>        cout<strong><<(<\/strong><strong>char<\/strong><strong>)(<\/strong>a<strong>%<\/strong>10<strong>+<\/strong>'0'<strong>)<<<\/strong><strong>\" \"<\/strong><strong>;<\/strong><strong><br><\/strong>        a<strong>\/=<\/strong>10<strong>;<\/strong><strong><br><\/strong>    <strong>}<\/strong><strong><br><\/strong>    <strong>return<\/strong> 0<strong>;<\/strong><strong><br><\/strong><strong>}<\/strong><\/code><\/pre>\n<p>\u7ed3\u679c:6 6 6 2 1<\/p>\n<p><strong>Program ex-10-5 \u81ea\u4e3b\u89e3\u6cd5<\/strong><strong><\/strong><\/p>\n<pre><code>assume cs<strong>:<\/strong>code,ss<strong>:<\/strong>stack,ds<strong>:<\/strong>data<br>stack segment<br>    db 256 dup<strong>(<\/strong>0<strong>)<\/strong><strong><br><\/strong>stack ends<br>data segment<br>    db 256 dup<strong>(<\/strong>0<strong>)<\/strong><strong><br><\/strong>data ends<br>code segment<br>start<strong>:<\/strong><strong><br><\/strong>    <strong>mov<\/strong> ax,stack<br>    <strong>mov<\/strong> ss,ax<br>    <strong>mov<\/strong> sp,256<br>    <strong>mov<\/strong> ax,data<br>    <strong>mov<\/strong> ds,ax<br>    <strong>mov<\/strong> si,0<br>    <strong>mov<\/strong> ax,12666<br>    <strong>call<\/strong> dtoc<br>    <strong>mov<\/strong> cl,2<br>    <strong>mov<\/strong> dh,8<br>    <strong>mov<\/strong> dl,3<br>    <strong>call<\/strong> show_str<br>    <br>    <strong>mov<\/strong> ax,4c00h<br>    <strong>int<\/strong> 21h<br>dtoc<strong>:<\/strong><strong><br><\/strong><i>;void dtoc(word data=(ax),const char* str=(ds:si));<\/i><i><br><\/i>    <strong>push<\/strong> dx<br>    <strong>push<\/strong> cx<br>    <strong>push<\/strong> bx<br>    <strong>push<\/strong> ax<br>    <strong>push<\/strong> si<br>    <strong>push<\/strong> di<br>    <strong>mov<\/strong> di,si    <i>;si\u521d\u503c<\/i><i><br><\/i>    <strong>mov<\/strong> bx,10<br>    <strong>mov<\/strong> dx,0<br>    <i>;\u6ce8\u610f\u76f4\u63a5\u9664\u4f1a\u6ea2\u51fa!<\/i><i><br><\/i>dt_l1<strong>:<\/strong><strong><br><\/strong>    <strong>mov<\/strong> dx,0<br>    <strong>div<\/strong> bx            <i>;ax=ax\/10,dx=ax%10;<\/i><i><br><\/i>    <strong>add<\/strong> dl,<strong>'<\/strong>0<strong>'<\/strong>        <i>;dl+='0';<\/i><i><br><\/i>    <strong>mov<\/strong> [si],dl        <i>;ds:si=dl<\/i><i><br><\/i>    <strong>mov<\/strong> cx,ax<br>    <strong>inc<\/strong> si<br>    <strong>jcxz<\/strong> exit_dtoc<br>    <strong>jmp<\/strong> dt_l1<br>exit_dtoc<strong>:<\/strong><strong><br><\/strong>    <i>;\u53cd\u8f6c\u5b57\u7b26\u4e32<\/i><i><br><\/i>    <strong>mov<\/strong> ax,si<br>    <strong>sub<\/strong> ax,di    <i>;ax=si-di<\/i><i><br><\/i>    <strong>mov<\/strong> cx,ax    <i>;ax=\u5b57\u7b26\u6570<\/i><i><br><\/i>reverse_str<strong>:<\/strong><strong><br><\/strong>    <i>;\u7531\u4e8epush\u548cpop\u64cd\u4f5c\u4e3a\u5b57\u64cd\u4f5c<\/i><i><br><\/i>    <i>;\u56e0\u6b64\u8981\u5c06\u6bcf\u4e2a\u5b57\u7b26\u4ece\u5b57\u8282\u8f6c\u4e3a\u5b57<\/i><i><br><\/i>    <strong>mov<\/strong> bx,[di]<br>    <strong>mov<\/strong> bh,0<br>    <strong>push<\/strong> bx<br>    <strong>inc<\/strong> di        <br>    <strong>loop<\/strong> reverse_str<br>    <strong>sub<\/strong> si,ax    <i>;\u5c06si\u6062\u590d\u4e3a\u521d\u59cb\u503c<\/i><i><br><\/i>    <strong>mov<\/strong> cx,ax<br>copy_str<strong>:<\/strong><strong><br><\/strong>    <strong>pop<\/strong> bx<br>    <strong>mov<\/strong> [si],bl<br>    <strong>inc<\/strong> si<br>    <strong>loop<\/strong> copy_str<br>    <br>    <strong>pop<\/strong> di<br>    <strong>pop<\/strong> si<br>    <strong>pop<\/strong> ax<br>    <strong>pop<\/strong> bx<br>    <strong>pop<\/strong> cx<br>    <strong>pop<\/strong> dx<br>    <strong>ret<\/strong><strong><br><\/strong>    <br>show_str<strong>:<\/strong><strong><br><\/strong><strong>......<\/strong><strong><br><\/strong>code ends<br>end start<\/code><\/pre>\n<p><strong>Program ex-10-<\/strong><strong>6<\/strong><strong> <\/strong><strong>\u53c2\u8003<\/strong><strong>\u89e3\u6cd5<\/strong><strong><\/strong><\/p>\n<pre><code><strong>assume cs:code,ds:data<\/strong><strong><\/strong>\n<strong>data segment<\/strong><strong><\/strong>\n<strong>db 10 dup (0)<\/strong><strong><\/strong>\n<strong>data ends<\/strong><strong><\/strong>\n<strong>code segment<\/strong><strong><\/strong>\n<strong>start:<\/strong><strong>mov ax,12666<\/strong><strong><\/strong>\n<strong>mov bx,data<\/strong><strong><\/strong>\n<strong>mov ds,bx<\/strong><strong><\/strong>\n<strong>mov si,0<\/strong><strong>;ds:si\u6307\u5411data\u9996\u5730\u5740<\/strong><strong><\/strong>\n<strong>call dtoc1<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong> <\/strong><\/p>\n<pre><code><strong>mov dh,8<\/strong><strong><\/strong>\n<strong>mov dl,3<\/strong><strong><\/strong>\n<strong>mov cl,2<\/strong><strong><\/strong>\n<strong>call show_str<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong> <\/strong><\/p>\n<pre><code><strong>mov ax,4c00h<\/strong><strong><\/strong>\n<strong>int 21h<\/strong><strong><\/strong>\n<strong>dtoc1:<\/strong><strong>push ax<\/strong><strong><\/strong>\n<strong>push bx<\/strong><strong><\/strong>\n<strong>push cx<\/strong><strong><\/strong>\n<strong>push dx<\/strong><strong><\/strong>\n<strong>push si<\/strong><strong><\/strong>\n<strong>push di<\/strong><strong><\/strong>\n<strong>mov di,0<\/strong><strong><\/strong>\n<strong>d10:<\/strong><strong>mov dx,0<\/strong><strong>;\u8bbe\u7f6e\u88ab\u9664\u6570\u9ad8\u4f4d\u4e3a0<\/strong><strong><\/strong>\n<strong>mov bx,10<\/strong><strong>;\u9664\u6570\u4e3a10<\/strong><strong><\/strong>\n<strong>div bx<\/strong><strong><\/strong>\n<strong>add dx,30h<\/strong><strong>;ax\/10\u7684\u4f59\u6570+30h\uff0c\u8f6c\u4e3a\u5b57\u7b26<\/strong><strong><\/strong>\n<strong>push dx<\/strong><strong>;\u5b57\u7b26\u5165\u6808<\/strong><strong><\/strong>\n<strong>inc di<\/strong><strong>;\u8bb0\u5f55\u5b57\u7b26\u4e2a\u6570<\/strong><strong><\/strong>\n<strong>mov cx,ax<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong>jcxz d11<\/strong><strong>;\u5f53ax\/10\u7684\u5546=0\u65f6\uff0c\u8f6c\u5230d11\u6267\u884c<\/strong><strong><\/strong><\/p>\n<pre><code><strong>jmp d10<\/strong><strong><\/strong>\n<strong>d11:<\/strong><strong>mov cx,di<\/strong><strong><\/strong>\n<strong>d12:<\/strong><strong>pop dx<\/strong><strong>;\u5b57\u7b26\u51fa\u6808<\/strong><strong><\/strong>\n<strong>mov [si],dl<\/strong><strong><\/strong>\n<strong>inc si<\/strong><strong>;ds:si\u6307\u5411\u4e0b\u4e00\u5355\u5143<\/strong><strong><\/strong>\n<strong>loop d12<\/strong><strong><\/strong>\n<strong>mov dl,0<\/strong><strong><\/strong>\n<strong>mov [si],dl<\/strong><strong>;\u8bbe\u7f6e\u7ed3\u5c3e\u7b260<\/strong><strong><\/strong>\n<strong>pop si<\/strong><strong><\/strong>\n<strong>pop di<\/strong><strong><\/strong>\n<strong>pop dx<\/strong><strong><\/strong>\n<strong>pop cx<\/strong><strong><\/strong>\n<strong>pop bx<\/strong><strong><\/strong>\n<strong>pop ax<\/strong><strong><\/strong>\n<strong>ret<\/strong><strong><\/strong>\n<strong>show_str:<\/strong><strong><\/strong>\n<strong>push ax<\/strong><strong><\/strong>\n<strong>push bx<\/strong><strong><\/strong>\n<strong>mov ax,0b800h<\/strong><strong><\/strong>\n<strong>mov es,ax<\/strong><strong><\/strong>\n<strong>mov ax,160<\/strong><strong><\/strong>\n<strong>mul dh<\/strong><strong><\/strong>\n<strong>mov bx,ax<\/strong><strong>;bx=160*dh<\/strong><strong><\/strong>\n<strong>mov ax,2<\/strong><strong><\/strong>\n<strong>mul dl<\/strong><strong>;ax=dl*2<\/strong><strong><\/strong>\n<strong>add bx,ax<\/strong><strong>;mov bx,(160*dh+dl*2)\u8bbe\u7f6ees:bx\u6307\u5411\u663e\u5b58\u9996\u5730\u5740<\/strong><strong><\/strong>\n<strong>mov al,cl<\/strong><strong>;\u628a\u989c\u8272cl\u8d4b\u503cal<\/strong><strong><\/strong>\n<strong>mov cl,0<\/strong><strong><\/strong>\n<strong>show0:<\/strong><strong><\/strong>\n<strong>mov ch,[si]<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong>jcxz show1<\/strong><strong>;(ds:si)=0\u65f6\uff0c\u8f6c\u5230show1\u6267\u884c<\/strong><strong><\/strong><\/p>\n<pre><code><strong>mov es:[bx],ch<\/strong><strong><\/strong>\n<strong>mov es:[bx].1,al<\/strong><strong><\/strong>\n<strong>inc si<\/strong><strong>;ds:si\u6307\u5411\u4e0b\u4e00\u4e2a\u5b57\u7b26\u5730\u5740<\/strong><strong><\/strong>\n<strong>add bx,2<\/strong><strong>;es:bx\u6307\u5411\u4e0b\u4e00\u4e2a\u663e\u5b58\u5730\u5740<\/strong><strong><\/strong>\n<strong>jmp show0<\/strong><strong><\/strong>\n<strong>show1:<\/strong><strong><\/strong>\n<strong>pop bx<\/strong><strong><\/strong>\n<strong>pop ax<\/strong><strong><\/strong>\n<strong>ret<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong> <\/strong><\/p>\n<pre><code><strong>code ends<\/strong><strong><\/strong>\n<strong>end start<\/strong><strong><\/strong><\/code><\/pre>\n<p>\u6539\u8fdb\u7a0b\u5e8f:\u5c06dword\u578b\u6570\u636e\u8f6c\u4e3a\u5b57\u7b26<\/p>\n<p>\u540d\u79f0\uff1adtoc2<\/p>\n<p>\u529f\u80fd\uff1a\u5c06dword\u578b\u6570\u636e\u8f6c\u53d8\u4e3a\u8868\u793a\u5341\u8fdb\u5236\u7684\u5b57\u7b26\u4e32\uff0c\u5b57\u7b26\u4e32\u4ee50\u4e3a\u7ed3\u5c3e\u7b26\u3002<\/p>\n<p>\u53c2\u6570\uff1a(ax)=dword\u578b\u6570\u636e\u7684\u4f4e16\u4f4d\uff1b<\/p>\n<p>      (dx)=dword\u578b\u6570\u636e\u7684\u9ad816\u4f4d\uff1b<\/p>\n<p>      ds:si\u6307\u5411\u5b57\u7b26\u4e32\u9996\u5730\u5740\u3002<\/p>\n<pre><code>\u8fd4\u56de\uff1a\u65e0\u3002<\/code><\/pre>\n<p><strong>Program ex-10-7 \u81ea\u4e3b\u89e3\u6cd5<\/strong><strong><\/strong><\/p>\n<pre><code>assume cs<strong>:<\/strong>code,ss<strong>:<\/strong>stack,ds<strong>:<\/strong>data<br>stack segment<br>    db 256 dup<strong>(<\/strong>0<strong>)<\/strong><strong><br><\/strong>stack ends<br>data segment<br>    db 256 dup<strong>(<\/strong>0<strong>)<\/strong><strong><br><\/strong>data ends<br>code segment<br>start<strong>:<\/strong><strong><br><\/strong>    <strong>mov<\/strong> ax,stack<br>    <strong>mov<\/strong> ss,ax<br>    <strong>mov<\/strong> sp,256<br>    <strong>mov<\/strong> ax,data<br>    <strong>mov<\/strong> ds,ax<br>    <strong>mov<\/strong> si,0<br>    <i>;\u6ce8\u610f\u8fd9\u91cc\u4e0d\u8981\u752810\u8fdb\u5236\u5199!<\/i><i><br><\/i>    <strong>mov<\/strong> ax,0bf52h<br>    <strong>mov<\/strong> dx,1h<br>    <strong>call<\/strong> dtoc2<br>    <strong>mov<\/strong> cl,2<br>    <strong>mov<\/strong> dh,8<br>    <strong>mov<\/strong> dl,3<br>    <strong>call<\/strong> show_str<br>    <br>    <strong>mov<\/strong> ax,4c00h<br>    <strong>int<\/strong> 21h<br>dtoc2<strong>:<\/strong><strong><br><\/strong><i>;void dtoc2(dword data=(bx)*65536+(ax),const char* str=(ds:si));<\/i><i><br><\/i>    <strong>push<\/strong> dx<br>    <strong>push<\/strong> cx<br>    <strong>push<\/strong> bx<br>    <strong>push<\/strong> ax<br>    <strong>push<\/strong> si<br>    <strong>push<\/strong> di<br>    <strong>mov<\/strong> di,si    <i>;si\u521d\u503c<\/i><i><br><\/i>    <br>    dt_l1<strong>:<\/strong><strong><br><\/strong>        <strong>mov<\/strong> cx,10<br>        <strong>call<\/strong> divdw<br>        <i>;dx*65536+ax=\u5546,cx=\u4f59\u6570<\/i><i><br><\/i>        <strong>add<\/strong> cl,<strong>'<\/strong>0<strong>'<\/strong>        <i>;cl+='0';<\/i><i><br><\/i>        <strong>mov<\/strong> [si],cl        <i>;ds:si=cl<\/i><i><br><\/i>        <strong>mov<\/strong> cx,dx<br>        <strong>jcxz<\/strong> dx_is_0    <i>;dx==0\u65f6\u7ee7\u7eed\u5224\u65adax\u662f\u5426\u4e3a0<\/i><i><br><\/i>        <strong>jmp<\/strong> dx_is_not_0 <i>;dx!=0\u65f6<\/i><i><br><\/i>    dx_is_0<strong>:<\/strong><strong><br><\/strong>        <strong>mov<\/strong> cx,ax<br>    dx_is_not_0<strong>:<\/strong>    <br>        <strong>inc<\/strong> si<br>        <strong>jcxz<\/strong> exit_dtoc    <i>;ax==0\u65f6\u5411\u5916\u8df3\u8f6c,\u5426\u5219\u5411\u4e0b        <\/i><i><br><\/i>        <strong>jmp<\/strong> dt_l1<br>    exit_dtoc<strong>:<\/strong><strong><br><\/strong>        <i>;\u53cd\u8f6c\u5b57\u7b26\u4e32<\/i><i><br><\/i>        <strong>mov<\/strong> ax,si<br>        <strong>sub<\/strong> ax,di    <i>;ax=si-di<\/i><i><br><\/i>        <strong>mov<\/strong> cx,ax    <i>;ax=\u5b57\u7b26\u6570<\/i><i><br><\/i>    reverse_str<strong>:<\/strong><strong><br><\/strong>        <i>;\u7531\u4e8epush\u548cpop\u64cd\u4f5c\u4e3a\u5b57\u64cd\u4f5c<\/i><i><br><\/i>        <i>;\u56e0\u6b64\u8981\u5c06\u6bcf\u4e2a\u5b57\u7b26\u4ece\u5b57\u8282\u8f6c\u4e3a\u5b57<\/i><i><br><\/i>        <strong>mov<\/strong> bx,[di]<br>        <strong>mov<\/strong> bh,0<br>        <strong>push<\/strong> bx<br>        <strong>inc<\/strong> di        <br>        <strong>loop<\/strong> reverse_str<br>        <strong>sub<\/strong> si,ax    <i>;\u5c06si\u6062\u590d\u4e3a\u521d\u59cb\u503c<\/i><i><br><\/i>        <strong>mov<\/strong> cx,ax<br>    copy_str<strong>:<\/strong><strong><br><\/strong>        <strong>pop<\/strong> bx<br>        <strong>mov<\/strong> [si],bl<br>        <strong>inc<\/strong> si<br>        <strong>loop<\/strong> copy_str<br>        <br>        <strong>pop<\/strong> di<br>        <strong>pop<\/strong> si<br>        <strong>pop<\/strong> ax<br>        <strong>pop<\/strong> bx<br>        <strong>pop<\/strong> cx<br>        <strong>pop<\/strong> dx<br>        <strong>ret<\/strong><strong><br><\/strong>    <br>show_str<strong>:<\/strong><strong><br><\/strong><strong>......<\/strong>    <br>divdw<strong>:<\/strong><strong><br><\/strong>    <strong>push<\/strong> si<br>    <strong>mov<\/strong> si,0<br>    <i>;\u4e3a\u4e86\u9632\u6b62\u5f71\u54cd\u5230\u5176\u4ed6\u7a0b\u5e8f\u7684\u5185\u5b58,\u5c06\u4f7f\u7528\u7684\u5355\u5143\u5907\u4efd<\/i><i><br><\/i>    <i>;\u89e3\u51b3\u5185\u5b58\u51b2\u7a81\u7684\u65b9\u6cd5:<\/i><i><br><\/i>    <strong>push<\/strong> [si]<br>    <strong>push<\/strong> [si<strong>+<\/strong>2]<br>    <strong>push<\/strong> [si<strong>+<\/strong>4]<br>    <strong>push<\/strong> [si<strong>+<\/strong>6]<br>    <strong>push<\/strong> [si<strong>+<\/strong>8]<br>    <br>    <strong>mov<\/strong> [si],ax        <i>;ds:0=l<\/i><i><br><\/i>    <strong>mov<\/strong> [si<strong>+<\/strong>2],dx    <i>;ds:2=h<\/i><i><br><\/i>    <strong>mov<\/strong> [si<strong>+<\/strong>4],cx    <i>;ds:4=n<\/i><i><br><\/i>    <i>;x\/n=int(h\/n)*65536+[rem(h\/n)*65536+l]\/n<\/i><i><br><\/i>    <i>;\u8ba1\u7b97int(h\/n)<\/i><i><br><\/i>    <i>;\u4e0d\u8981\u4e58\u4ee565536!\u76f4\u63a5\u4f5c\u4e3a\u4e00\u4e2a\u53cc\u5b50\u6570\u636e\u9ad816\u4f4d\u5904\u7406<\/i><i><br><\/i>    <i>;int(h\/n)\u662f\u7ed3\u679c\u5f97\u9ad816\u4f4d<\/i><i><br><\/i>    <strong>mov<\/strong> ax,[si<strong>+<\/strong>2]<br>    <strong>mov<\/strong> dx,0<br>    <strong>div<\/strong> word ptr[si<strong>+<\/strong>4]<br>    <strong>mov<\/strong> [si<strong>+<\/strong>6],ax    <i>;int(h\/n) \u5546<\/i><i><br><\/i>    <strong>mov<\/strong> [si<strong>+<\/strong>8],dx    <i>;rem(h\/n) \u4f59\u6570<\/i><i><br><\/i>    <i>;\u8ba1\u7b97[rem(h\/n)*65536+l]\/n<\/i><i><br><\/i>    <strong>mov<\/strong> ax,[si]<br>    <i>;(dx*0FFFFh+ax)=rem(h\/n)*65536+l<\/i><i><br><\/i>    <strong>div<\/strong> word ptr[si<strong>+<\/strong>4]<br>    <i>;ax=[rem(h\/n)*65536+l]\/n,\u4e3a\u7ed3\u679c\u7684\u4f4e16\u4f4d<\/i><i><br><\/i>    <i>;dx\u4e3a\u4f59\u6570,\u79fb\u5165cx<\/i><i><br><\/i>    <strong>mov<\/strong> cx,dx<br>    <strong>mov<\/strong> dx,[si<strong>+<\/strong>6]    <br>    <br>    <strong>pop<\/strong> [si<strong>+<\/strong>8]<br>    <strong>pop<\/strong> [si<strong>+<\/strong>6]<br>    <strong>pop<\/strong> [si<strong>+<\/strong>4]<br>    <strong>pop<\/strong> [si<strong>+<\/strong>2]<br>    <strong>pop<\/strong> [si]<br>    <strong>pop<\/strong> si<br>    <strong>ret<\/strong><strong><br><\/strong>code ends<br>end start<\/code><\/pre>\n<p><strong>Program ex-10-8 \u53c2\u8003\u89e3\u6cd5<\/strong><strong><\/strong><\/p>\n<p><strong>;\u5e94\u7528\u4e3e\u4f8b\uff1a\u5c06\u6570\u636e2494967295\u4ee5\u5341\u8fdb\u5236\u7684\u5f62\u5f0f\u5728\u5c4f\u5e55\u76848\u884c3\u5217\uff0c\u7528\u7eff\u8272\u663e\u793a\u51fa\u6765\u3002<\/strong><strong><\/strong><\/p>\n<pre><code><strong>assume cs:code,ds:data<\/strong><strong><\/strong>\n<strong>data segment<\/strong><strong><\/strong>\n<strong>db 10 dup (0)<\/strong><strong><\/strong>\n<strong>data ends<\/strong><strong><\/strong>\n<strong>code segment<\/strong><strong><\/strong>\n<strong>start:<\/strong><strong>mov ax,0ffffh<\/strong><strong><\/strong>\n<strong>mov dx,0ffffh<\/strong><strong><\/strong>\n<strong>mov bx,data<\/strong><strong><\/strong>\n<strong>mov ds,bx<\/strong><strong><\/strong>\n<strong>mov si,0<\/strong><strong>;ds:si\u6307\u5411\u5b57\u7b26\u4e32\u9996\u5730\u5740<\/strong><strong><\/strong>\n<strong>call dtoc2<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong> <\/strong><\/p>\n<pre><code><strong>mov dh,8<\/strong><strong><\/strong>\n<strong>mov dl,3<\/strong><strong><\/strong>\n<strong>mov cl,2<\/strong><strong><\/strong>\n<strong>call show_str<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong> <\/strong><\/p>\n<pre><code><strong>mov ax,4c00h<\/strong><strong><\/strong>\n<strong>int 21h<\/strong><strong><\/strong>\n<strong>dtoc2:<\/strong><strong><\/strong>\n<strong>push ax<\/strong><strong><\/strong>\n<strong>push bx<\/strong><strong><\/strong>\n<strong>push cx<\/strong><strong><\/strong>\n<strong>push dx<\/strong><strong><\/strong>\n<strong>push si<\/strong><strong><\/strong>\n<strong>push di<\/strong><strong><\/strong>\n<strong>mov di,0<\/strong><strong><\/strong>\n<strong>d20:<\/strong><strong>mov cx,10<\/strong><strong>;\u9664\u6570\u4e3a10<\/strong><strong><\/strong>\n<strong>call divdw<\/strong><strong><\/strong>\n<strong>add cx,30h<\/strong><strong>;\u4f59\u6570+30h\uff0c\u8f6c\u4e3a\u5b57\u7b26<\/strong><strong><\/strong>\n<strong>push cx<\/strong><strong>;\u5b57\u7b26\u5165\u6808<\/strong><strong><\/strong>\n<strong>inc di<\/strong><strong>;\u8bb0\u5f55\u5b57\u7b26\u4e2a\u6570<\/strong><strong><\/strong>\n<strong>mov cx,ax <\/strong><strong><\/strong><\/code><\/pre>\n<p><strong>jcxz d21<\/strong><strong>;\u4f4e\u4f4d\u5546=0\u65f6\uff0c\u8f6c\u5230d21\u68c0\u6d4b\u9ad8\u4f4d\u5546<\/strong><strong><\/strong><\/p>\n<pre><code><strong>jmp d20<\/strong><strong><\/strong>\n<strong>d21:<\/strong><strong>mov cx,dx<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong>jcxz d22<\/strong><strong>;\u9ad8\u4f4e\u4f4d\u5546\u5168=0\u65f6\uff0c\u8f6c\u5230d22\u6267\u884c<\/strong><strong><\/strong><\/p>\n<pre><code><strong>jmp d20<\/strong><strong><\/strong>\n<strong>d22:<\/strong><strong>mov cx,di<\/strong><strong><\/strong>\n<strong>d23:<\/strong><strong>pop ax<\/strong><strong>;\u5b57\u7b26\u51fa\u6808<\/strong><strong><\/strong>\n<strong>mov [si],al<\/strong><strong><\/strong>\n<strong>inc si<\/strong><strong>;ds:si\u6307\u5411\u4e0b\u4e00\u5355\u5143<\/strong><strong><\/strong>\n<strong>loop d23<\/strong><strong><\/strong>\n<strong>mov al,0<\/strong><strong><\/strong>\n<strong>mov [si],al<\/strong><strong>;\u8bbe\u7f6e\u7ed3\u5c3e\u7b260<\/strong><strong><\/strong>\n<strong>pop di<\/strong><strong><\/strong>\n<strong>pop si<\/strong><strong><\/strong>\n<strong>pop dx<\/strong><strong><\/strong>\n<strong>pop cx<\/strong><strong><\/strong>\n<strong>pop bx<\/strong><strong><\/strong>\n<strong>pop ax<\/strong><strong><\/strong>\n<strong>ret<\/strong><strong><\/strong>\n<strong>show_str:<\/strong><strong><\/strong>\n<strong>push ax<\/strong><strong><\/strong>\n<strong>push bx<\/strong><strong><\/strong>\n<strong>mov ax,0b800h<\/strong><strong><\/strong>\n<strong>mov es,ax<\/strong><strong><\/strong>\n<strong>mov ax,160<\/strong><strong><\/strong>\n<strong>mul dh<\/strong><strong><\/strong>\n<strong>mov bx,ax<\/strong><strong>;bx=160*dh<\/strong><strong><\/strong>\n<strong>mov ax,2<\/strong><strong><\/strong>\n<strong>mul dl<\/strong><strong>;ax=dl*2<\/strong><strong><\/strong>\n<strong>add bx,ax<\/strong><strong>;mov bx,(160*dh+dl*2)\u8bbe\u7f6ees:bx\u6307\u5411\u663e\u5b58\u9996\u5730\u5740<\/strong><strong><\/strong>\n<strong>mov al,cl<\/strong><strong>;\u628a\u989c\u8272cl\u8d4b\u503cal<\/strong><strong><\/strong>\n<strong>mov cl,0<\/strong><strong><\/strong>\n<strong>show0:<\/strong><strong><\/strong>\n<strong>mov ch,[si]<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong>jcxz show1<\/strong><strong>;(ds:si)=0\u65f6\uff0c\u8f6c\u5230show1\u6267\u884c<\/strong><strong><\/strong><\/p>\n<pre><code><strong>mov es:[bx],ch<\/strong><strong><\/strong>\n<strong>mov es:[bx].1,al<\/strong><strong><\/strong>\n<strong>inc si<\/strong><strong>;ds:si\u6307\u5411\u4e0b\u4e00\u4e2a\u5b57\u7b26\u5730\u5740<\/strong><strong><\/strong>\n<strong>add bx,2<\/strong><strong>;es:bx\u6307\u5411\u4e0b\u4e00\u4e2a\u663e\u5b58\u5730\u5740<\/strong><strong><\/strong>\n<strong>jmp show0<\/strong><strong><\/strong>\n<strong>show1:<\/strong><strong><\/strong>\n<strong>pop bx<\/strong><strong><\/strong>\n<strong>pop ax<\/strong><strong><\/strong>\n<strong>ret<\/strong><strong><\/strong>\n<strong>divdw:<\/strong><strong><\/strong>\n<strong>push si<\/strong><strong><\/strong>\n<strong>push bx<\/strong><strong><\/strong>\n<strong>push ax<\/strong><strong><\/strong>\n<strong>mov ax,dx<\/strong><strong><\/strong>\n<strong>mov dx,0<\/strong><strong><\/strong>\n<strong>div cx<\/strong><strong>;\u88ab\u9664\u6570\u7684\u9ad8\u4f4d\/cx<\/strong><strong><\/strong>\n<strong>mov si,ax<\/strong><strong><\/strong>\n<strong>pop ax <\/strong><strong><\/strong>\n<strong>div cx<\/strong><strong>;(\u88ab\u9664\u6570\u9ad8\u4f4d\u7684\u5546+\u4f4e\u4f4d)\/cx<\/strong><strong><\/strong>\n<strong>mov cx,dx<\/strong><strong>;\u4f59\u6570\u5165cx<\/strong><strong><\/strong>\n<strong>mov dx,si<\/strong><strong>;\u9ad8\u4f4d\u7684\u5546\u5165dx<\/strong><strong><\/strong>\n<strong>pop bx<\/strong><strong><\/strong>\n<strong>pop si<\/strong><strong><\/strong>\n<strong>ret<\/strong><strong><\/strong>\n<strong>code ends<\/strong><strong><\/strong>\n<strong>end start<\/strong><strong><\/strong><\/code><\/pre>\n<p><strong>\u8bfe\u7a0b\u8bbe\u8ba1<\/strong><strong>1<\/strong><strong><\/strong><\/p>\n<p>\u5c06\u5b9e\u9a8c7\u4e2d\u7684Power idea\u516c\u53f8\u7684\u6570\u636e\u6309\u7167\u56fe\u6240\u793a\u7684\u683c\u5f0f\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u73b0\u6765\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"417\"  height=\"212\"  src=\"http:\/\/8.129.82.128\/wp-content\/uploads\/2026\/03\/asm202405\u7248\u63d0\u7eb252948.png\" > <\/p>\n<pre><code>\u6548\u679c\u56fe<\/code><\/pre>\n<p><strong>Program lesson-design-1-1 \u81ea\u5df1\u7684\u89e3\u6cd5<\/strong><strong><\/strong><\/p>\n<pre><code>assume cs<strong>:<\/strong>code,ds<strong>:<\/strong>data,ss<strong>:<\/strong>stack,es<strong>:<\/strong>table_<br>data segment<br>    db <strong>'<\/strong>1975<strong>'<\/strong>,<strong>'<\/strong>1976<strong>'<\/strong>,<strong>'<\/strong>1977<strong>'<\/strong>,<strong>'<\/strong>1978<strong>'<\/strong>,<strong>'<\/strong>1979<strong>'<\/strong>,<strong>'<\/strong>1980<strong>'<\/strong>,<strong>'<\/strong>1981<strong>'<\/strong>,<strong>'<\/strong>1982<strong>'<\/strong>,<strong>'<\/strong>1983<strong>'<\/strong><strong><br><\/strong>    db <strong>'<\/strong>1984<strong>'<\/strong>,<strong>'<\/strong>1985<strong>'<\/strong>,<strong>'<\/strong>1986<strong>'<\/strong>,<strong>'<\/strong>1987<strong>'<\/strong>,<strong>'<\/strong>1988<strong>'<\/strong>,<strong>'<\/strong>1989<strong>'<\/strong>,<strong>'<\/strong>1990<strong>'<\/strong>,<strong>'<\/strong>1991<strong>'<\/strong>,<strong>'<\/strong>1992<strong>'<\/strong><strong><br><\/strong>    db <strong>'<\/strong>1993<strong>'<\/strong>,<strong>'<\/strong>1994<strong>'<\/strong>,<strong>'<\/strong>1995<strong>'<\/strong><strong><br><\/strong>    <i>;\u4ee5\u4e0a\u4e3a21\u5e74\u768421\u4e2a\u5b57\u7b26\u4e32(+84byte)<\/i><i><br><\/i>    dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514<br>    dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000<br>    <i>;\u4ee5\u4e0a\u4e3a21\u5e74\u7684\u603b\u6536\u5165\u6570\u636e(+168byte)<\/i><i><br><\/i>    dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226<br>    dw 11452,14430,15257,17800<br>    <i>;\u4ee5\u4e0a\u4e3a21\u5e74\u6bcf\u5e74\u7684\u96c7\u5458\u4eba\u6570<\/i><i><br><\/i>data ends<br>temp segment<br>    db 512 dup<strong>(<\/strong>0<strong>)<\/strong><strong><br><\/strong>temp ends<br>stack segment<br>    db 256 dup<strong>(<\/strong>0<strong>)<\/strong><strong><br><\/strong>stack ends<br>table_ segment<br>    db 21 dup <strong>(<\/strong><strong>'<\/strong>year<strong>'<\/strong>,0,<strong>'<\/strong>summ ne ?? <strong>'<\/strong><strong>)<\/strong><strong><br><\/strong>table_ ends<br>code segment<br>start<strong>:<\/strong><strong><br><\/strong>    <strong>mov<\/strong> ax,data<br>    <strong>mov<\/strong> ds,ax    <i>;ds=data<\/i><i><br><\/i>    <strong>mov<\/strong> ax,table_<br>    <strong>mov<\/strong> es,ax    <i>;es=table_<\/i><i><br><\/i>    <strong>mov<\/strong> ax,stack<br>    <strong>mov<\/strong> ss,ax    <i>;ss=stack<\/i><i><br><\/i>    <strong>mov<\/strong> sp,256<br>    <br>    <strong>mov<\/strong> bx,0<br>    <strong>mov<\/strong> cx,21    <br>    <strong>mov<\/strong> di,0<br>    <i>;\u5199\u5165\u5e74\u4efd<\/i><i><br><\/i>    l1<strong>:<\/strong><strong><br><\/strong>        <strong>mov<\/strong> ax,[di]<br>        <strong>mov<\/strong> es<strong>:<\/strong>[bx<strong>+<\/strong>0],ax<br>        <strong>mov<\/strong> ax,[di<strong>+<\/strong>2]<br>        <strong>mov<\/strong> es<strong>:<\/strong>[bx<strong>+<\/strong>2],ax<br>        <strong>add<\/strong> di,4<br>        <i>;\u6362\u4e0b\u4e00\u884c<\/i><i><br><\/i>        <strong>add<\/strong> bx,16<br>    <strong>loop<\/strong> l1<br>    <i>;\u5199\u5165\u6536\u5165<\/i><i><br><\/i>    <strong>mov<\/strong> bx,0<br>    <strong>mov<\/strong> cx,21<br>    l2<strong>:<\/strong><strong><br><\/strong>        <strong>mov<\/strong> ax,[di]<br>        <strong>mov<\/strong> es<strong>:<\/strong>[bx<strong>+<\/strong>5],ax<br>        <strong>mov<\/strong> ax,[di<strong>+<\/strong>2]<br>        <strong>mov<\/strong> es<strong>:<\/strong>[bx<strong>+<\/strong>7],ax<br>        <strong>add<\/strong> di,4<br>        <strong>add<\/strong> bx,16<br>    <strong>loop<\/strong> l2<br>    <i>;\u5199\u5165\u96c7\u5458\u6570<\/i><i><br><\/i>    <strong>mov<\/strong> bx,0 <br>    <strong>mov<\/strong> cx,21<br>    l3<strong>:<\/strong><strong><br><\/strong>        <strong>mov<\/strong> ax,[di]<br>        <strong>mov<\/strong> es<strong>:<\/strong>[bx<strong>+<\/strong>0ah],ax<br>        <strong>add<\/strong> di,2 <br>        <strong>add<\/strong> bx,16<br>    <strong>loop<\/strong> l3<br>    <i>;\u8ba1\u7b97\u4eba\u5747\u6536\u5165<\/i><i><br><\/i>    <strong>mov<\/strong> bx,0 <br>    <strong>mov<\/strong> cx,21<br>    <strong>mov<\/strong> di,84<br>    <strong>mov<\/strong> si,0    <i>;\u7528\u4e8e\u5b9a\u4f4d\u88ab\u9664\u6570<\/i><i><br><\/i>    l4<strong>:<\/strong><strong><br><\/strong>        <strong>mov<\/strong> dx,[di<strong>+<\/strong>2]<br>        <strong>mov<\/strong> ax,[di]<br>        <strong>div<\/strong> word ptr[168<strong>+<\/strong>si]<br>        <strong>mov<\/strong> es<strong>:<\/strong>[bx<strong>+<\/strong>0dh],ax<br>        <strong>add<\/strong> si,2<br>        <strong>add<\/strong> di,4<br>        <strong>add<\/strong> bx,16<br>    <strong>loop<\/strong> l4<br>    <i>;\u663e\u793atable<\/i><i><br><\/i>    <strong>mov<\/strong> ax,table_<br>    <strong>mov<\/strong> ds,ax    <i>;ds=table_<\/i><i><br><\/i>    <strong>mov<\/strong> si,0    <i>;\u8868\u683c\u6bcf\u4e00\u884c\u7684\u5730\u5740<\/i><i><br><\/i>    <strong>mov<\/strong> cx,21<br>    <strong>mov<\/strong> dh,2    <i>;\u884c\u53f7<\/i><i><br><\/i>s1<strong>:<\/strong>    <br>    <strong>mov<\/strong> dl,20    <i>;\u6bcf\u6b21\u90fd\u8981\u8fd8\u539f\u5217\u53f7<\/i><i><br><\/i>    <strong>push<\/strong> cx        <i>;\u663e\u793a\u5e74\u4efd<\/i><i><br><\/i>    <strong>mov<\/strong> cl,2<br>    <strong>call<\/strong> show_str    <i>;str=ds:si<\/i><i><br><\/i>    <strong>pop<\/strong> cx<br>    <br>    <strong>add<\/strong> si,10h    <i>;\u8868\u683c\u4e0b\u4e00\u884c<\/i><i><br><\/i>    <strong>inc<\/strong> dh        <i>;\u4e0b\u4e00\u884c<\/i><i><br><\/i>    <strong>loop<\/strong> s1<br><br>    <strong>mov<\/strong> ax,temp<br>    <strong>mov<\/strong> ds,ax    <i>;ds=temp<\/i><i><br><\/i>    <strong>mov<\/strong> si,0    <i>;ds:si\u5b58\u653e\u5b57\u7b26<\/i><i><br><\/i>    <strong>mov<\/strong> di,0    <i>;es:di\u53d6\u6570\u636e<\/i><i><br><\/i>    <strong>mov<\/strong> cx,21<br>    <strong>mov<\/strong> si,0<br>s2<strong>:<\/strong>    <br>    <i>;\u5c06\u6536\u5165\u8f6c\u4e3a\u5b57\u7b26<\/i><i><br><\/i>    <strong>mov<\/strong> ax,es<strong>:<\/strong>[di<strong>+<\/strong>5]<br>    <strong>mov<\/strong> dx,es<strong>:<\/strong>[di<strong>+<\/strong>7]<br>    <strong>call<\/strong> dtoc2<br>    <i>;\u5b57\u7b26\u4f4d\u4e8eds:0<\/i><i><br><\/i>    <i>;\u5c06\u96c7\u5458\u6570\u8f6c\u4e3a\u5b57\u7b26<\/i><i><br><\/i>    <strong>add<\/strong> si,10<br>    <strong>mov<\/strong> ax,es<strong>:<\/strong>[di<strong>+<\/strong>0ah]<br>    <strong>mov<\/strong> dx,0<br>    <strong>call<\/strong> dtoc2<br>    <i>;\u5b57\u7b26\u4f4d\u4e8eds:10<\/i><i><br><\/i>    <i>;\u5c06\u4eba\u5747\u6536\u5165\u8f6c\u4e3a\u5b57\u7b26<\/i><i><br><\/i>    <strong>add<\/strong> si,6<br>    <strong>mov<\/strong> ax,es<strong>:<\/strong>[di<strong>+<\/strong>0dh]<br>    <strong>mov<\/strong> dx,0<br>    <strong>call<\/strong> dtoc2<br>    <br>    <strong>add<\/strong> si,6<br>    <strong>add<\/strong> di,16<br>    <strong>loop<\/strong> s2<br>    <br>    <strong>mov<\/strong> dh,2    <i>;\u884c\u53f7<\/i><i><br><\/i>    <strong>mov<\/strong> dl,28    <i>;\u5217\u53f7<\/i><i><br><\/i>    <strong>mov<\/strong> cx,21<br>    <strong>mov<\/strong> si,0<br>s3<strong>:<\/strong>    <i>;\u6253\u5370\u5b57\u7b26<\/i><i><br><\/i>    <strong>mov<\/strong> dl,28<br>    <strong>push<\/strong> cx<br>    <strong>mov<\/strong> cl,2<br>    <strong>call<\/strong> show_str<br>    <strong>pop<\/strong> cx<br>    <strong>add<\/strong> si,10<br>    <strong>add<\/strong> dl,10<br>    <strong>push<\/strong> cx<br>    <strong>mov<\/strong> cl,2<br>    <strong>call<\/strong> show_str<br>    <strong>pop<\/strong> cx<br>    <strong>add<\/strong> si,6<br>    <strong>add<\/strong> dl,6<br>    <strong>push<\/strong> cx<br>    <strong>mov<\/strong> cl,2<br>    <strong>call<\/strong> show_str<br>    <strong>pop<\/strong> cx<br>    <strong>add<\/strong> si,6<br>    <strong>add<\/strong> dl,6<br>    <strong>inc<\/strong> dh<br>    <strong>loop<\/strong> s3<br><br>    <strong>mov<\/strong> ax,4c00h<br>    <strong>int<\/strong> 21h<br>    <br>dtoc2<strong>:<\/strong><strong><br><\/strong><i>;void dtoc2(dword data=(dx)*65536+(ax),const char* str=(ds:si));<\/i><i><br><\/i>    <strong>push<\/strong> dx<br>    <strong>push<\/strong> cx<br>    <strong>push<\/strong> bx<br>    <strong>push<\/strong> ax<br>    <strong>push<\/strong> si<br>    <strong>push<\/strong> di<br>    <strong>mov<\/strong> di,si    <i>;si\u521d\u503c<\/i><i><br><\/i>    <br>    dt_l1<strong>:<\/strong><strong><br><\/strong>        <strong>mov<\/strong> cx,10<br>        <strong>call<\/strong> divdw<br>        <i>;dx*65536+ax=\u5546,cx=\u4f59\u6570<\/i><i><br><\/i>        <strong>add<\/strong> cl,<strong>'<\/strong>0<strong>'<\/strong>        <i>;cl+='0';<\/i><i><br><\/i>        <strong>mov<\/strong> [si],cl        <i>;ds:si=cl<\/i><i><br><\/i>        <strong>mov<\/strong> cx,dx<br>        <strong>jcxz<\/strong> dx_is_0    <i>;dx==0\u65f6\u7ee7\u7eed\u5224\u65adax\u662f\u5426\u4e3a0<\/i><i><br><\/i>        <strong>jmp<\/strong> dx_is_not_0 <i>;dx!=0\u65f6<\/i><i><br><\/i>    dx_is_0<strong>:<\/strong><strong><br><\/strong>        <strong>mov<\/strong> cx,ax<br>    dx_is_not_0<strong>:<\/strong>    <br>        <strong>inc<\/strong> si<br>        <strong>jcxz<\/strong> exit_dtoc    <i>;ax==0\u65f6\u5411\u5916\u8df3\u8f6c,\u5426\u5219\u5411\u4e0b        <\/i><i><br><\/i>        <strong>jmp<\/strong> dt_l1<br>    exit_dtoc<strong>:<\/strong><strong><br><\/strong>        <i>;\u53cd\u8f6c\u5b57\u7b26\u4e32<\/i><i><br><\/i>        <strong>mov<\/strong> ax,si<br>        <strong>sub<\/strong> ax,di    <i>;ax=si-di<\/i><i><br><\/i>        <strong>mov<\/strong> cx,ax    <i>;ax=\u5b57\u7b26\u6570<\/i><i><br><\/i>    reverse_str<strong>:<\/strong><strong><br><\/strong>        <i>;\u7531\u4e8epush\u548cpop\u64cd\u4f5c\u4e3a\u5b57\u64cd\u4f5c<\/i><i><br><\/i>        <i>;\u56e0\u6b64\u8981\u5c06\u6bcf\u4e2a\u5b57\u7b26\u4ece\u5b57\u8282\u8f6c\u4e3a\u5b57<\/i><i><br><\/i>        <strong>mov<\/strong> bx,[di]<br>        <strong>mov<\/strong> bh,0<br>        <strong>push<\/strong> bx<br>        <strong>inc<\/strong> di        <br>        <strong>loop<\/strong> reverse_str<br>        <strong>sub<\/strong> si,ax    <i>;\u5c06si\u6062\u590d\u4e3a\u521d\u59cb\u503c<\/i><i><br><\/i>        <strong>mov<\/strong> cx,ax<br>    copy_str<strong>:<\/strong><strong><br><\/strong>        <strong>pop<\/strong> bx<br>        <strong>mov<\/strong> [si],bl<br>        <strong>inc<\/strong> si<br>        <strong>loop<\/strong> copy_str<br>        <br>        <strong>pop<\/strong> di<br>        <strong>pop<\/strong> si<br>        <strong>pop<\/strong> ax<br>        <strong>pop<\/strong> bx<br>        <strong>pop<\/strong> cx<br>        <strong>pop<\/strong> dx<br>        <strong>ret<\/strong><strong><br><\/strong>    <br>show_str<strong>:<\/strong><strong><br><\/strong><i>;void show_str(byte row=(dh),byte line=(dl),<\/i><i><br><\/i><i>;byte color=(cl),const char* str =(ds:si));<\/i><i><br><\/i><i>;\u663e\u5b58\u504f\u79fb\u5730\u5740offset_display=row*160+line*2<\/i><i><br><\/i>    <strong>push<\/strong> ax<br>    <strong>push<\/strong> bx<br>    <strong>push<\/strong> cx<br>    <strong>push<\/strong> dx<br>    <strong>push<\/strong> si<br>    <strong>push<\/strong> di<br>    <strong>push<\/strong> es<br>    <br>    <strong>mov<\/strong> al,dh<br>    <strong>mov<\/strong> ah,160<br>    <strong>mul<\/strong> ah        <i>;AX=row*160<\/i><i><br><\/i>    <strong>mov<\/strong> bh,0    <br>    <strong>mov<\/strong> bl,dl    <i>;BX=(word)line<\/i><i><br><\/i>    <strong>add<\/strong> ax,bx<br>    <strong>add<\/strong> ax,bx    <i>;AX=offset_display=row*160+line*2<\/i><i><br><\/i>    <strong>mov<\/strong> di,ax    <i>;DI=offset_display<\/i><i><br><\/i>    <br>    <strong>mov<\/strong> ax,0b800h<br>    <strong>mov<\/strong> es,ax    <i>;ES=\u663e\u793a\u7f13\u51b2\u533a<\/i><i><br><\/i>    <strong>mov<\/strong> dl,cl    <i>;DL=color<\/i><i><br><\/i>    <i>;es:di \u6307\u5411\u663e\u5b58\u663e\u793a\u7f13\u51b2\u533a\u7684\u6307\u9488<\/i><i><br><\/i>    display<strong>:<\/strong><strong><br><\/strong>        <strong>mov<\/strong> ch,0<br>        <strong>mov<\/strong> cl,[si]    <i>;CX=(word)(DS:SI)<\/i><i><br><\/i>        <strong>jcxz<\/strong> ok        <i>;if((cx)==0) return;<\/i><i><br><\/i>        <strong>mov<\/strong> es<strong>:<\/strong>[di],cl    <i>;(ES:DI)=(DS:SI)<\/i><i><br><\/i>        <strong>mov<\/strong> es<strong>:<\/strong>[di<strong>+<\/strong>1],dl<i>;(ES:DI+1)=color<\/i><i><br><\/i>        <strong>add<\/strong> di,2<br>        <strong>add<\/strong> si,1<br>        <strong>jmp<\/strong> display<br>        <br>    ok<strong>:<\/strong>    <strong>pop<\/strong> es<br>        <strong>pop<\/strong> di<br>        <strong>pop<\/strong> si<br>        <strong>pop<\/strong> dx<br>        <strong>pop<\/strong> cx<br>        <strong>pop<\/strong> bx<br>        <strong>pop<\/strong> ax<br>        <strong>ret<\/strong><strong><br><\/strong>    <br>divdw<strong>:<\/strong><strong><br><\/strong>    <strong>push<\/strong> si<br>    <strong>mov<\/strong> si,0<br>    <i>;\u4e3a\u4e86\u9632\u6b62\u5f71\u54cd\u5230\u5176\u4ed6\u7a0b\u5e8f\u7684\u5185\u5b58,\u5c06\u4f7f\u7528\u7684\u5355\u5143\u5907\u4efd<\/i><i><br><\/i>    <i>;\u89e3\u51b3\u5185\u5b58\u51b2\u7a81\u7684\u65b9\u6cd5:<\/i><i><br><\/i>    <strong>push<\/strong> [si]<br>    <strong>push<\/strong> [si<strong>+<\/strong>2]<br>    <strong>push<\/strong> [si<strong>+<\/strong>4]<br>    <strong>push<\/strong> [si<strong>+<\/strong>6]<br>    <strong>push<\/strong> [si<strong>+<\/strong>8]<br>    <br>    <strong>mov<\/strong> [si],ax        <i>;ds:0=l<\/i><i><br><\/i>    <strong>mov<\/strong> [si<strong>+<\/strong>2],dx    <i>;ds:2=h<\/i><i><br><\/i>    <strong>mov<\/strong> [si<strong>+<\/strong>4],cx    <i>;ds:4=n<\/i><i><br><\/i>    <i>;x\/n=int(h\/n)*65536+[rem(h\/n)*65536+l]\/n<\/i><i><br><\/i>    <i>;\u8ba1\u7b97int(h\/n)<\/i><i><br><\/i>    <i>;\u4e0d\u8981\u4e58\u4ee565536!\u76f4\u63a5\u4f5c\u4e3a\u4e00\u4e2a\u53cc\u5b50\u6570\u636e\u9ad816\u4f4d\u5904\u7406<\/i><i><br><\/i>    <i>;int(h\/n)\u662f\u7ed3\u679c\u5f97\u9ad816\u4f4d<\/i><i><br><\/i>    <strong>mov<\/strong> ax,[si<strong>+<\/strong>2]<br>    <strong>mov<\/strong> dx,0<br>    <strong>div<\/strong> word ptr[si<strong>+<\/strong>4]<br>    <strong>mov<\/strong> [si<strong>+<\/strong>6],ax    <i>;int(h\/n) \u5546<\/i><i><br><\/i>    <strong>mov<\/strong> [si<strong>+<\/strong>8],dx    <i>;rem(h\/n) \u4f59\u6570<\/i><i><br><\/i>    <i>;\u8ba1\u7b97[rem(h\/n)*65536+l]\/n<\/i><i><br><\/i>    <strong>mov<\/strong> ax,[si]<br>    <i>;(dx*0FFFFh+ax)=rem(h\/n)*65536+l<\/i><i><br><\/i>    <strong>div<\/strong> word ptr[si<strong>+<\/strong>4]<br>    <i>;ax=[rem(h\/n)*65536+l]\/n,\u4e3a\u7ed3\u679c\u7684\u4f4e16\u4f4d<\/i><i><br><\/i>    <i>;dx\u4e3a\u4f59\u6570,\u79fb\u5165cx<\/i><i><br><\/i>    <strong>mov<\/strong> cx,dx<br>    <strong>mov<\/strong> dx,[si<strong>+<\/strong>6]    <br>    <br>    <strong>pop<\/strong> [si<strong>+<\/strong>8]<br>    <strong>pop<\/strong> [si<strong>+<\/strong>6]<br>    <strong>pop<\/strong> [si<strong>+<\/strong>4]<br>    <strong>pop<\/strong> [si<strong>+<\/strong>2]<br>    <strong>pop<\/strong> [si]<br>    <strong>pop<\/strong> si<br>    <strong>ret<\/strong><strong><br><\/strong>code ends<br>end start<\/code><\/pre>\n<p><strong>Program lesson-design-1-2 \u53c2\u8003\u89e3\u6cd5<\/strong><strong><\/strong><\/p>\n<pre><code>assume cs:code,ds:data,es:table\ntable segment\n    db '1975','1976','1977','1978','1979','1980','1981','1982','1983'\n    db '1984','1985','1986','1987','1988','1989','1990','1991','1992'\n    db '1993','1994','1995'\n    dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514\n    dd 345980,590827,803530,1183000,1843000,2795000,3753000,4649000,5937000\n    dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226\n    dw 11542,14430,15257,17800\n    dw 5,3,42,104,85,210,123,111,105,125,140,136,153,211,199,209,224,239\n    dw 260,304,333\ntable ends\ndata segment\n    db 32 dup (0)\ndata ends\ncode segment\nstart:mov ax,data\nmov ds,ax\nmov ax,table\nmov es,ax\nmov bx,0\nmov si,0\nmov di,0\nmov cx,21\nmov dh,2\nmov dl,30\ng:push cx\npush dx\nmov ax,es:[bx]\nmov [si],ax\nmov ax,es:[bx].2\nmov [si].2,ax;\u5e74\u4efd\u5165ds:si\nadd si,6\nmov ax,es:[bx].84\nmov dx,es:[bx].86\ncall dtoc2;\u6536\u5165\u8f6c\u6210\u5341\u8fdb\u5236\u5b57\u7b26\u5165ds:si\nadd si,10\nmov ax,es:[di].168\nmov dx,0\ncall dtoc2;\u4eba\u5458\u6570\u8f6c\u6210\u5341\u8fdb\u5236\u5b57\u7b26\u5165ds:si\nadd si,6\nmov ax,es:[di].210\nmov dx,0\ncall dtoc2;\u4eba\u5747\u6536\u5165\u8f6c\u6210\u5341\u8fdb\u5236\u5b57\u7b26\u5165ds:si\nmov si,0;\u8bbe\u7f6eds:si\u6307\u5411\u9700\u663e\u793a\u5b57\u7b26\u9996\u5730\u5740\nb:mov cx,29\nc:push cx\nmov cl,[si]<\/code><\/pre>\n<p>jcxz f;(ds:si)=0\u8f6c\u5230f\u6267\u884c<\/p>\n<pre><code>d:inc si\npop cx\nloop c\ninc si\nmov al,0\nmov [si],al;\u8bbe\u7f6e\u7ed3\u5c3e\u7b260\nmov si,0;\u8bbe\u7f6eds:si\u6307\u5411\u9700\u663e\u793a\u5b57\u7b26\u9996\u5730\u5740\npop dx\nmov cl,2\ncall show_str\nadd bx,4;dword\u6570\u636e\u6307\u5411\u4e0b\u4e00\u6570\u636e\u5355\u5143\nadd di,2;word\u6570\u636e\u6307\u5411\u4e0b\u4e00\u6570\u636e\u5355\u5143\nadd dh,1;\u6307\u5411\u663e\u5b58\u4e0b\u4e00\u884c\npop cx\nloop g\nmov ax,4c00h\nint 21h\nf:mov al,20h\nmov [si],al;(ds:si)=0\u7684\u6570\u636e\u6539\u6210\u7a7a\u683c\njmp d\ndtoc2:\npush ax\npush bx\npush cx\npush dx\npush si\npush di\nmov di,0\nd20:mov cx,10;\u9664\u6570\u4e3a10\ncall divdw\nadd cx,30h;\u4f59\u6570+30h\uff0c\u8f6c\u4e3a\u5b57\u7b26\npush cx;\u5b57\u7b26\u5165\u6808\ninc di;\u8bb0\u5f55\u5b57\u7b26\u4e2a\u6570\nmov cx,ax <\/code><\/pre>\n<p>jcxz d21;\u4f4e\u4f4d\u5546=0\u65f6\uff0c\u8f6c\u5230d21\u68c0\u6d4b\u9ad8\u4f4d\u5546<\/p>\n<pre><code>jmp d20\nd21:mov cx,dx<\/code><\/pre>\n<p>jcxz d22;\u9ad8\u4f4e\u4f4d\u5546\u5168=0\u65f6\uff0c\u8f6c\u5230d22\u6267\u884c<\/p>\n<pre><code>jmp d20\nd22:mov cx,di\nd23:pop ax;\u5b57\u7b26\u51fa\u6808\nmov [si],al\ninc si;ds:si\u6307\u5411\u4e0b\u4e00\u5355\u5143\nloop d23\nmov al,0\nmov [si],al;\u8bbe\u7f6e\u7ed3\u5c3e\u7b260\npop di\npop si\npop dx\npop cx\npop bx\npop ax\nret\ndivdw:\npush si\npush bx\npush ax\nmov ax,dx\nmov dx,0\ndiv cx;\u88ab\u9664\u6570\u7684\u9ad8\u4f4d\/cx\nmov si,ax\npop ax \ndiv cx;(\u88ab\u9664\u6570\u9ad8\u4f4d\u7684\u5546+\u4f4e\u4f4d)\/cx\nmov cx,dx;\u4f59\u6570\u5165cx\nmov dx,si;\u9ad8\u4f4d\u7684\u5546\u5165dx\npop bx\npop si\nret\nshow_str:\npush ax\npush bx\npush es\npush si\nmov ax,0b800h\nmov es,ax\nmov ax,160\nmul dh\nmov bx,ax;bx=160*dh\nmov ax,2\nmul dl;ax=dl*2\nadd bx,ax;mov bx,(160*dh+dl*2)\u8bbe\u7f6ees:bx\u6307\u5411\u663e\u5b58\u9996\u5730\u5740\nmov al,cl;\u628a\u989c\u8272cl\u8d4b\u503cal\nmov cl,0\nshow0:\nmov ch,[si]<\/code><\/pre>\n<p>jcxz show1;(ds:si)=0\u65f6\uff0c\u8f6c\u5230show1\u6267\u884c<\/p>\n<pre><code>mov es:[bx],ch\nmov es:[bx].1,al\ninc si;ds:si\u6307\u5411\u4e0b\u4e00\u4e2a\u5b57\u7b26\u5730\u5740\nadd bx,2;es:bx\u6307\u5411\u4e0b\u4e00\u4e2a\u663e\u5b58\u5730\u5740\njmp show0\nshow1:\npop si\npop es\npop bx\npop ax\nret\ncode ends\nend start<\/code><\/pre>\n<p><![if !supportLists]>\n    <\/div>\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u5341\u7ae0 CALL\u548cRET\u6307\u4ee4 &#038;#821 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18,9,8],"tags":[],"class_list":["post-504","post","type-post","status-publish","format-standard","hentry","category-assembly","category-9","category-8"],"_links":{"self":[{"href":"http:\/\/8.129.82.128\/index.php?rest_route=\/wp\/v2\/posts\/504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/8.129.82.128\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/8.129.82.128\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/8.129.82.128\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/8.129.82.128\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=504"}],"version-history":[{"count":1,"href":"http:\/\/8.129.82.128\/index.php?rest_route=\/wp\/v2\/posts\/504\/revisions"}],"predecessor-version":[{"id":505,"href":"http:\/\/8.129.82.128\/index.php?rest_route=\/wp\/v2\/posts\/504\/revisions\/505"}],"wp:attachment":[{"href":"http:\/\/8.129.82.128\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/8.129.82.128\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=504"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/8.129.82.128\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}