//目录

汇编试验五:编写、调试具有多个段的程序

ds 数据段放入数据正确;

 

两次push 操作后,ss栈段正确;

由于pop 操作顺序,ds数据段并没有发生改变;

 Source Code:

assume cs:code, ds:data, ss:stack

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:[0]
    push ds:[2]
    pop ds:[2]
    pop ds:[0]

    mov ax,4c00H
    int 21H

code ends
end start
View Code

 

(2)程序加载后,数据段和栈段加载后,实际占据的空间是以16个字节为单位。程序中只给出了前两个字,其他空间都是补充0;

Source Code:

assume cs:code , ds:data , ss:stack

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:[0]
    push ds:[2]
    pop ds:[2]
    pop ds:[0]

    mov ax,4c00H
    int 21H
code ends
end start
View Code

 

(3)

Source Code:

assume cs:code ,ds:data, ss:stack

code segment
start:
    mov ax,stack
    mov ss,ax
    mov sp,16

    mov ax,data
    mov ds,ax

    push ds:[0]
    push ds:[2]
    pop ds:[2]
    pop ds:[0]

    mov ax,4c00H
    int 21H
code ends


data segment
    dw 0123H,0456H
data ends

stack segment
    dw 0,0
stack ends

end start
View Code

相比之前,三个段的顺序发生改变,数据没有改变,但是三个段的入口地址肯定变了;

具体差别:

代码段标号减小;

 

 

(5) a 段 + b 段 的和,放到 c 段;

(栈段也可以用 段地址+偏移地址访问)

Source Code:

assume cs:code

    a segment
        db 1,2,3,4,5,6,7,8
    a ends

    b segment
        db 1,2,3,4,5,6,7,8
    b ends

    c segment
        db 0,0,0,0,0,0,0,0
    c ends

code segment
    start:
        mov ax,a
        mov ds,ax

        mov ax,b
        mov ss,ax   ;栈段

        mov ax,c
        mov es,ax

        mov bx,0
        mov cx,8

    s:
        mov al,ds:[bx]
        add al,ss:[bx]  ;栈段也段地址+偏移地址访问
        mov es:[bx],al

        inc bx
        loop s

        mov ax,4c00H
        int 21H
code ends
end start
View Code

 

 

(6)将a段的前8个字,逆序放到 b 段中;

入栈的方式,即为逆序;

Source 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,10H

    mov bx,0
    mov cx,8

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

        loop s

    mov ax,4c00H
    int 21H


code ends
end start
View Code

 

posted @ 2017-05-30 17:31  小草的大树梦  阅读(583)  评论(0编辑  收藏  举报