汇编语言(第四版)王爽第九章--实验8

实验8

1. 实践9.1节内容(p176页)

assume cs:codesg
codesg segment
  s:mov ax,bx        ;要复制的指令,机器码占两个字节
    mov si,offset s        ;s标记的指令是代码段中的第一条指令,偏移地址为0
    mov di,offset s0    ;s0标记要粘贴的地址,相当于mov di,0e
    mov ax,cs:[si]        ;指令的机器码通过ax传到要粘贴的地址
    mov cs:[di],ax
     s0:nop
    nop

    mov ax,4c00h
    int 21h
codesg ends
end s

用Debug查看指令

分析并回答下列问题

① s和s0处的指令所在的内存单元的地址是多少?

s: cs:offset s s0: cs:offset s0

② 将s处的指令复制到s0处,就是将cs:offset s处的数据复制到cs:offset s0处吗?

③ 要复制数据有多长? 2个字节

2. 实践9.3节内容(p177~178页)

(1)编辑、编译、连接程序9.1

assume cs:codesg
codesg segment
  start:mov ax,0    ;初始化ax
      jmp short s    ;指令跳转到s标号对应的指令
    add ax,1
      s:inc ax

          mov ax,4c00h
    int 21h
codesg ends
end start

用Debug查看程序9.1指令

(2)编辑、编译、连接程序9.2

assume cs:codesg
codesg segment
  start:mov ax,0
       mov bx,0
    jmp short s    ;指令跳转到s标号对应的指令
    add ax,1
      s:inc ax

          mov ax,4c00h
    int 21h
codesg ends
end start

用Debug查看程序9.2指令

3. 实践9.4节内容(p180~181页)

编辑、编译、连接程序9.3

assume cs:codesg
codesg segment
  start:mov ax,0
       mov bx,0
    jmp far ptr s    ;远转移指令跳转到s标号对应的指令
    db 256 dup(0)

      s:add ax,1
    inc ax

          mov ax,4c00h
    int 21h
codesg ends
end start

用Debug查看程序9.3指令

4. 实践9.6节内容(p183~184页)

(1)补全检测点9.1中程序1

assume cs:code

data segment
    db 8 dup(0) 
data ends

code segment
  start:mov ax,data
    mov ds,ax
    mov bx,0
    jmp word ptr [bx+1]    ;执行后(ip)=(ds:[bx+1])即(ip)=(ds:[1])
code ends
end start

用Debug查看检测点9.1程序1

可以看到程序执行完jmp word ptr [bx+1]后ip跳转到0000h,对应的指令为mov ax,076ah

(2)补全检测点9.1中程序2

data segment
    dd 12345678H
data ends
 
code segment
    start:
        mov ax, data
        mov ds, ax
        mov bx, 0
        mov [bx], bx        ;使得(ds:[bx])=(bx),即(ds:[0])=0
        mov [bx+2], cs        ;使得(ds:[bx+2])=(cs),即(ds:[2])=指令段地址的值
        jmp dword ptr ds:[0]    ;执行后(ip)=(ds:[0000h])=0,(cs)=(ds:[0002h])
 
code ends
end start

用Debug查看检测点9.1程序2

5. 实践9.7节内容(p184~185页)

(1)补全检测点9.2中程序

assume cs:code
code segment
start: mov ax,2000H
       mov ds,ax
       mov bx,0

    s: mov cl,[bx]    ;(cl)=(ds:[0])
       mov ch,0
       jcxz ok        ;当cx=0跳转到ok
       inc bx        ;没有跳转执行下面代码
       jmp short s

   ok: mov dx,bx

       mov ax,4c00h
       int 21h
code ends
end start

用Debug查看检查点9.2程序

6. 实践9.8节内容(p185~186页)

补全检查点9.3中程序

assume cs:code
 
code segment
 
    start:
        mov ax,2000h
        mov ds,ax
        mov bx,0

      s:mov cl,[bx]    ;(cl)=(ds:[bx])
        mov ch,0    ;(ch)=0
        inc cx        ;(cx)+1
        inc bx        ;偏移地址+1
        loop s
     ok:dec bx          ;(bx)-1,得到2000H段 中第一个值为0的字节
        mov dx,bx    ;将存在bx中的结果存到dx中

        mov ax,4c00h
        int 21h
 
code ends
end start

用Debug查看检查点9.3程序

7. 实验8 分析一个奇怪的程序(p187页)

用Debug查看程序

执行程序后指令机器码。可见由于复制的是指令的机器码,在cs:[0020],jmp short s1 指令机器码为EBF6,F6指(ip)=(ip)-10,在cs:[0020]跳转到s段,而在cs:[0008]跳转到cs:[0000]直接执行中断指令。

8. 实验9 根据材料编程(p187~p198页)

assume cs:code,ds:data,ss:stack
data segment
    db 'welcome to masm!'    ;ds:[si]
    db 00000010B        ;绿色    ds:[bx]
    db 00100100B        ;绿底红字
    db 01110001B        ;白底蓝字
data ends

stack segment
    db 128 dup(0)
stack ends

code segment
  start:mov ax,stack
       mov ss,ax
    mov sp,128        ;指向空栈栈顶

    mov ax,data
    mov ds,ax
    mov bx,0B830H        
    mov es,bx        ;数据传到显示缓冲区es:[di]

    mov si,0        ;定位数据段中字符ASCII码的偏移地址
    mov di,160*10+30*2
    mov bx,0010h        ;定位数据段中字符属性的偏移地址
    mov dx,0

    mov cx,3        ;三行外循环三次
     s0:push cx            ;压栈保存
    push si
    push di

    mov cx,16        ;16个字符内循环16次
    mov dh,ds:[bx]        ;长度为一个字的寄存器暂存字符的ASCII码和属性,高地址存放属性
      s:mov dl,ds:[si]        ;低地址存放对应ASCII码
    mov es:[di],dx        ;把暂存在dx中的字符传到显示缓冲区
    add di,2        ;移动到下一个字符对应的显示缓冲区
    inc si            ;移动到数据段下一个字符
    loop s

    pop di
    pop si
    pop cx
    add di,160        ;移动到下一行字符对应的显示缓冲区
    inc bx            ;移动到数据段中存放下一行字符属性的内存单元
    loop s0

    mov ax,4c00h
    int 21h
code ends
end start

用Debug查看程序

  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值