实验五

实验1

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

先编译连接

然后进入debug调试

返回前data段中数据如图所示

根据代码段可知,cs值为076C,ss值为076B,ds值为076A。
data段的段地址为x-2,stack段的段地址为x-1。

实验2

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

编译后

返回前

 如图可以看到cs,ss,ds的值

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

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

 实验3

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段的段地址为x+3,stack段的段地址为x+4

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

 5.

start:
mov ax,a1
mov ds,ax
mov cx,8
mov bx,0
s: mov ax,[bx]
add ax,[bx+10h]
mov [bx+20h],ax
add bx,2
loop s
mov ax,4c00h
int 21h

 

 

 如图所示完成了相加

6.

start: 
12     mov ax,a1
13     mov ds,ax
14     mov cx,8
15     mov bx,0
16     mov ax,b1
17     mov ss,ax
18     mov sp,10h
19 s:  push [bx]
20     add bx,2
21     loop s

push操作执行前

操作执行之后

实验总结:编写代码段是要注意程序入口的使用,从实验2我们总结出一个段实际占用的空间=(段中字节数+15)/16。

实验1.2.3指出了三个寄存器cs,ss,ds段地址之间的关系。

 

 

posted @ 2018-11-25 16:17  胡泓彬  阅读(104)  评论(0编辑  收藏  举报