特目尔 發表於 2021-5-3 18:35:00

王爽汇编语言答案(5-8章)

<h1 id="王爽汇编语言答案5-8章">王爽汇编语言答案(5-8章)</h1>
<h2 id="检测点">检测点</h2>
<h3 id="chapter6">chapter6</h3>
<h4 id="检测点61">检测点6.1</h4>
<ol>
<li>下面的程序实现依次用内存0:0——0:15单元中的内容改写程序中的数据,完成程序:</li>
</ol>
<pre><code>assume cs:code
        code segment
                dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
                start:        mov ax,0
                                mov ds,ax
                                mov bx,0
                                mov cx,8
                                s:mov ax,
                                  mov cs:,ax
                                        add bx,2
                                        loop s
               
                                mov ax,4c00h
                                int 21h
        code ends
end start
</code></pre>
<ol start="2">
<li>下面的程序实现依次用内存0:0——0:15 单元中的内容改写程序中的数据,数据的传送用栈来进行。栈空间设置在程序内。完成程序:</li>
</ol>
<pre><code>assume cs:code
        code segment
                dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
                dw 0,0,0,0,0,0,0,0,0,0
                start:        mov ax,cs
                                mov ss,ax
                                mov sp,24h
                               
                                mov ax,0
                                mov ds,ax
                                mov bx,0
                                mov cx,8
                        s:push
                                pop cs:
                                add bx,2
                                loop s
                               
                                mov ax,4c00h
                                int 21h
        code ends
end start
</code></pre>
<h2 id="实验">实验</h2>
<h3 id="实验-4-bx和-loop-的使用">实验 4 和 loop 的使用</h3>
<ol>
<li>编程实现向内存0:200——0:23F依次传送数据063(3FH),最多使用9条指令,包括<code>mov ax,4c00h</code>和<code>int 21h</code>。</li>
</ol>
<pre><code>assume cs:code
        code segment
                mov ax,0020h
                mov ds,ax
               
                mov bx,0
                mov cx,64
               
                s:mov ,bl
                        inc bx
                        loop s
               
                mov ax,4c00h
                int 21h
        code ends
end
</code></pre>
<ol start="2">
<li>下面的程序的功能是将 " movax,4c00h"之前的指令复制到内存 0:200处,补全程序。上机调试,跟踪运行结果。</li>
</ol>
<pre><code>assume cs:code
code segment
        mov ax,__
        mov ds,ax
        mov ax,0020h
        mov es,ax
        mov bx,0
        mov cx,__
       
        s:mov al,
                mov es:,al
                inc bx
                loop s
        mov ax,4c00h
        int 21h
code ends
end
</code></pre>
<p>完整程序为</p>
<pre><code>assume cs:code
code segment
        mov ax,cs          ;需要把ds数据段指向指令段
        mov ds,ax
        mov ax,0020h
        mov es,ax
        mov bx,0
        mov cx,17h         ;通过debug -u命令可以查看
                                           ;mov ax,4c00h 的IP为 0017h
                                           ;也就是程序长度17h
        s:mov al,
                mov es:,al
                inc bx
                loop s
        mov ax,4c00h
        int 21h
code ends
end
</code></pre>
<h3 id="实验5">实验5</h3>
<pre><code>assume cs:code,ss:stack,ds:data
        data segment
                dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
        data ends
        stack segment
                dw 0,0,0,0,0,0,0,0
        stack ends
        code segment
                start:        mov ax,stack
                                mov ss,ax
                                mov sp,16
                               
                                mov ax,data
                                mov ds,ax
                               
                                push ds:
                                push ds:
                                pop ds:
                                pop ds:
                               
                                mov ax,4c00h
                                int 21h
        code ends
end start
</code></pre>
<ol>
<li>CPU执行程序,程序返回前,data段中的数据为多少?<br>
<code>0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h</code></li>
<li>CPU执行程序,程序返回前,cs=<code>076E</code>、ss=<code>076D</code>、ds=<code>076C</code></li>
<li>设程序加载后,code段的段地址为X,则data段的段地址为<code>X-2</code>,stack段的段地址为<code>X-1h</code></li>
</ol>
<hr>
<pre><code>assume cs:code,ss:stack,ds:data
        data segment
                dw 0123h,0456h
        data ends
        stack segment
                dw 0,0
        stack ends
        code segment
                start:        mov ax,stack
                                mov ss,ax
                                mov sp,16
                               
                                mov ax,data
                                mov ds,ax
                               
                                push ds:
                                push ds:
                                pop ds:
                                pop ds:
                               
                                mov ax,4c00h
                                int 21h
        code ends
end start
</code></pre>
<ol>
<li>CPU执行程序,程序返回前,data段中的数据为多少?<br>
<code>0123h,0456h,0000h,0000h,0000h,0000h,0000h,0000h</code></li>
<li>CPU执行程序,程序返回前,cs=<code>076E</code>、ss=<code>076D</code>、ds=<code>076C</code></li>
<li>设程序加载后,code段的段地址为X,则data段的段地址为<code>X-2</code>,stack段的段地址为<code>X-1h</code></li>
<li>如果段中的数据占N个字节,则程序加载后,该段实际占有的空间为<code>16的倍数且N小于等于该数</code>。</li>
</ol>
<hr>
<pre><code>assume cs:code,ss:stack,ds:data
        code segment
                start:        mov ax,stack
                                mov ss,ax
                                mov sp,16
                               
                                mov ax,data
                                mov ds,ax
                               
                                push ds:
                                push ds:
                                pop ds:
                                pop ds:
                               
                                mov ax,4c00h
                                int 21h
        code ends
        data segment
                dw 0123h,0456h
        data ends
        stack segment
                dw 0,0
        stack ends
end start
</code></pre>
<ol>
<li>CPU执行程序,程序返回前,data段中的数据为多少?<br>
<code>0123h,0456h,0000h,0000h,0000h,0000h,0000h,0000h</code></li>
<li>CPU执行程序,程序返回前,cs=<code>076C</code>、ss=<code>0770</code>、ds=<code>076F</code></li>
<li>设程序加载后,code段的段地址为X,则data段的段地址为<code>X+3</code>,stack段的段地址为<code>X+4h</code></li>
</ol>
<hr>
<p>如果将上面3个代码中的最后一条伪指令"end start"改为"end"(也就是说,不指明程序的入口),哪个可以正常运行</p>
<p><strong>第三个可以正常运行,前面2个找不到一条代码在哪里,会从IP=0开始运行,<br>
3恰好IP就是0。</strong></p>
<hr>
<p>程序如下,编写code段中的代码,将a段和b段中的数据依次相加,将结果存<br>
到c段中</p>
<pre><code>assume cs:code
        a segment
                db 1,2,3,4,5,6,7,8 ;实际占用空间16byte
        a ends
        b segment
                db 1,2,3,4,5,6,7,8 ;实际占用空间16byte
        b ends
        c segment
                db 0,0,0,0,0,0,0,0 ;实际占用空间16byte
        c ends
        code segment
                start:        mov ax,a
                                mov ds,ax
                               
                                mov bx,0
                                mov cx,8
                                mov ax,0
                          s:mov al,ds:
                                add al,ds:
                                mov ds:,al
                                inc bx
                                loop s
                               
                                mov ax,4c00h
                                int 21h
        code ends
end start
</code></pre>
<hr>
<p>程序如下,编写code段中的代码,用push指令将a段中的前8个字型数据,逆序存储到b段中</p>
<pre><code>assume cs:code
        a segment
                dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh
        a ends
        b segment
                dw 0,0,0,0,0,0,0,0
        b ends
        code segment
                start:        mov ax,a
                                mov ds,ax
                                mov ax,b
                                mov ss,ax
                                mov sp,16
                               
                                mov bx,0
                                mov cx,8
                          s:push
                                add bx,2
                                loop s
                               
                                mov ax,4c00h
                                int 21h
        code ends
end start
</code></pre>
<h3 id="实验6-双层循环处理字符串">实验6 双层循环处理字符串</h3>
<p>编程,将data段中每个单词的前4个字母改为大写字母</p>
<pre><code>assume cs:code,ss:stack,ds:data
        data segment
                db '1. display      '
                db '2. brows      '
                db '3. replace      '
                db '4. modify       '
        data ends
        stack segment
                dw 0,0,0,0,0,0,0,0
        stack ends
        code segment
                start:        mov ax,stack
                                mov ss,ax
                                mov sp,60h
                               
                                mov ax,data
                                mov ds,ax
                               
                                mov bx,0
                                mov cx,4
                        s:push cx
                                mov cx,4
                                mov si,0
                               
                        s1: mov al,
                                and al,11011111B
                                mov ,al
                                inc si
                                loop s1
                               
                                add bx,16
                                pop cx
                                loop s
                               
                                mov ax,4c00h
                                int 21h
        code ends
end start
</code></pre>
<h3 id="实验7-寻址方式在结构化数据访问中的应用">实验7 寻址方式在结构化数据访问中的应用</h3>
<pre><code>Poweridea 公司从1975年成立一直到1995年的基本情况如下

年份   收入(千美)元   雇员(人)   人均收入(千美元)
1975          16            3            ?      
1976   22            7            ?
1977   382             9            ?      
1978   1356            13         ?   
1979   2390            28         ?
.      
.
.
1980   8000            38         ?
1995   5937000         17800      ?
</code></pre>
<p>下面的程序中,已经定义好了这些数据:</p>
<pre><code>data segment
                db'1975','1976','1977','1978','1979','1980','1981','1982','1983'
                db'1984','1985','1986','1987','1988','1989','1990','1991','1992'
                db'1993','1994','1995'
                ;以上是表示21年的21个字符串

                dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
                dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
                ;以上是表示21年公司总收入的21个dword型数据

                dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
                dw 11542,14430,15257,17800
                ;以上是表示21年公司雇员人数的21个word型数据
        data ends
       
        table segment
                db 21dup('year summ ne ?? ')
        table ends
</code></pre>
<p>编程,将data段中的数据按如下格式写入到table段中,并计算21年中的人均收入(取整),结果也按照下面的格式保存在table段中。</p>
<pre><code>assume cs:codesg
        data segment
                db'1975','1976','1977','1978','1979','1980','1981','1982','1983'
                db'1984','1985','1986','1987','1988','1989','1990','1991','1992'
                db'1993','1994','1995'
                ;以上是表示21年的21个字符串

                dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
                dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
                ;以上是表示21年公司总收入的21个dword型数据

                dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
                dw 11542,14430,15257,17800
                ;以上是表示21年公司雇员人数的21个word型数据
        data ends
       
        table segment
                db 21 dup('year summ ne ?? ')
        table ends
       
        codesg segment
               start: mov ax,data
                                mov ds,ax
                               
                                mov si,0
                                mov bx,0
                                mov cx,21
                                mov ax,table
                                mov es,ax
                                mov di,0
                               
                          s:mov ax,
                                mov es:,ax
                                mov ax,
                                mov es:,ax
                                ;copy year
                                mov ax,
                                mov dx,
                                mov es:,ax
                                mov es:,dx
                                div word ptr
                                mov es:,ax
                                ;copy sum and per income
                                mov ax,
                                mov es:,ax
                                ;copy people
                                add di,16
                                add bx,4
                                add si,2
                                loop s
                               
                                mov ax,4c00h
                                int 21h
        codesg ends
end start
</code></pre><br><br>
来源:https://www.cnblogs.com/cs-Miscellaneous/p/14727960.html
頁: [1]
查看完整版本: 王爽汇编语言答案(5-8章)