实验5

1.将ex5_1进行编译,连接,用debug加载,追踪。

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

 

使用r命令观察,发现DS=075A,所以程序从076A:0开始存放。

以下即为程序返回前data的值。

用u反汇编,data段的段地址为x-2,stack段的段地址为x-1。再用g命令回到上一步,得到程序返回前cs,ss,ds的值。

 

 2.将ex5_2进行编译,连接,用debug加载,追踪。

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

按照练习一,程序返回前data的数据:

按照练习一,cs,ss,ds值:

data段的段地址为x-2,stack段的段地址为x-1。

实际占用的空间为(N/16+1)*16。

3.将ex5_3进行编译,连接,用debug加载,追踪。

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

 

data段的段地址为x+3,stack段的段地址为x+4。

 4.4.只有3可正确执行,因为去掉start后就不指明程序入口,程序从头开始执行,而1,2,是以数据段开头,只有3是命令段,能正确运行下去。

 

 5.

编译连接后观察ss后8字节

 总结:编写代码段是要注意程序入口

posted @ 2018-11-25 23:20  1042004503  阅读(99)  评论(0编辑  收藏  举报