. : : Assembly Language : : .  |  首页  |  我提出的问题  |  我参与的问题  |  我的收藏  |  消息中心   |  游客  登录  | 
刷新 | 提问 | 未解决 | 已解决 | 精华区 | 搜索 |
  《汇编语言》论坛 ->包含多个段的程序
  管理员: assembly   [回复本贴] [收藏本贴] [管理本贴] [关闭窗口]
主题 : :  第6章 试验5.6实现代码  [待解决] 回复[ 4次 ]   点击[ 564次 ]  
ruder
[帖 主]   [ 发表时间:2013-05-05 11:07 ]   [引用]   [回复]   [ top ] 
荣誉值: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
[第1楼]   [ 回复时间:2013-05-05 11:23 ]   [引用]   [回复]   [ top ] 
荣誉值:0
信誉值:0
注册日期:2011-01-02 12:37
上面的程序,可以单步跟踪不会出错!
ruder
[第2楼]   [ 回复时间:2013-05-05 11:23 ]   [引用]   [回复]   [ top ] 
荣誉值: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
ruder
[第3楼]   [ 回复时间:2013-05-05 11:23 ]   [引用]   [回复]   [ top ] 
荣誉值:0
信誉值:0
注册日期:2011-01-02 12:37
这个程序,可以用P命令跟踪不会出错!
jumpbird
[第4楼]   [ 回复时间:2014-08-30 16:51 ]   [引用]   [回复]   [ top ] 
荣誉值:0
信誉值:0
注册日期:2014-08-29 19:48
以下调试通过:

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,10h

        mov bx,0
        mov cx,8

   s:   push [bx]
        add bx,2
        loop s

        mov bx,0
        mov cx,8

   s0:  pop [bx]
        add bx,2
        loop s0

        mov ax,4c00h
        int 21h

code ends

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