美文网首页
汇编语言(第三版)-- 检测点6.1

汇编语言(第三版)-- 检测点6.1

作者: Cichar | 来源:发表于2017-03-17 14:16 被阅读0次

下面的程序实现依次用内存0:0~0:15单元中的内容改写程序中的数据:

assume cs:codesg
codesg 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,[bx]       # 将ds:[bx]内存单元中的数据写入ax寄存器
       mov cs:[bx],ax    # 将ax寄存器中的数据写入cs:[bx]代码单元
       add bx,2          # 相邻两个字节单元为一个字单元,因此偏移2
       loop s

       mov ax,4c00h
       int 21h

codesg ends
end start

下面的程序实现依次用内存0:0~0:15单元中的内容改写程序中的数据,数据的传送用栈来进行。栈空间设置在程序内。

assume cs:codesg
codesg segment

    dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h  # 定义数据
    dw 0,0,0,0,0,0,0,0,0,0   # 10个字单元用作栈空间
start: mov ax,cs         # 定义代码段
       mov ss,ax         # 定义栈段
       mov sp,36h        # 定义栈底为36h (8*2 + 10*2)
       
       mov ax,0
       mov ds,ax         # 定义内存起始段
       mov bx,0          # 定义内存偏移
       mov cx,8          # 定义循环次数
       
    s: push [bx]         # 将ds:[bx]内存单元中的数据写入栈单元ss:sp(sp=36h) -> sp=36h - 2h = 34h
       pop cs:[bx]       # 将ss:sp(sp=34h)为栈顶的字单元中的数据写入cs:[bx]中 -> sp=34h + 2h = 36h
       add bx,2          # 相邻两个字节单元为一个字单元,因此偏移2
       loop s

       mov ax,4c00h
       int 21h

codesg ends
end start    

相关文章

网友评论

      本文标题:汇编语言(第三版)-- 检测点6.1

      本文链接:https://www.haomeiwen.com/subject/mzeenttx.html