. : : Assembly Language : : .  |  首页  |  我提出的问题  |  我参与的问题  |  我的收藏  |  消息中心   |  游客  登录  | 
提问 | 未解决 | 已解决 | 精华区 | 搜索 |
  《汇编语言》论坛 ->包含多个段的程序
主题 : :  第6章 试验5.6实现代码  [待解决] 回复[ 4次 ]   点击[ 565次 ]  
ruder
[帖 主] [ 发表时间:2013-05-05 11:07 ] 
荣誉值:0
信誉值:0
注册日期:2011-01-02 12:37
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                ; 使ds指向a段
    mov ds, ax
    xor bx, bx               ; 设定好循环的基址和次数
    mov cx, 8
again_push:                  ; 使a段的字循环入栈
    push ds:[bx]
    inc bx                   ; 两个inc bx比add bx, 2高效
    inc bx
    loop again_push

    mov ax, b                ; 使ds指向b段
    mov ds, ax
    xor bx, bx               ; 设定好循环的基址和次数
    mov cx, 8
again_pop:                   ; 使栈里的数据循环出栈
    pop ds:[bx]
    inc bx
    inc bx
    loop again_pop

    mov ax, 4c00h            ; 程序退出
    int 21h
code ends

end start
ruder
[第2楼] [ 回复时间:2013-05-05 11:23 ] 
荣誉值:0
信誉值:0
注册日期:2011-01-02 12:37
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, b                ; 使b段成为堆栈段
    mov ss, ax
    mov sp, 10h

    mov ax, a                ; 压入a段的数据到堆栈段
    mov ds, ax
    xor bx, bx
    mov cx, 8
again:
    push ds:[bx]
    inc bx
    inc bx
    loop again

    mov ax, 4c00h            ; 程序退出
    int 21h
code ends

end start
需要登录后才能回帖 -->> 请单击此处登录
    Copyright © 2006-2024   ASMEDU.NET  All Rights Reserved