(1)
输入以下程序
assume cs:code,ds:data,ss:stack
data segment
dw 0123h,0456h,0789h,0abch,0defh,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
1)data段中的数据是多少?
显然,data 里面的数据没有发生变化
data:0123h,0456h,0789h,0abch,0defh,0cbah,0987h
2)求CS,SS,DS
还是上面的图
CS=076C,SS=076B,DS=076A
3)假设code段地址为X,则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
和之前的程序相比,data 和stack段的数据长度变小了,那么我们来看一下内存的占用吧
可见,CS没有发生变化,这里类似于数据对齐,一个段的开头一定是X:0的形式
1)data段中的数据是多少?
data:0123h,0456h
2)求CS,SS,DS
还是上面的图
CS=076C,SS=076B,DS=076A
3)假设code段地址为X,则data段地址为X-2,stack段地址为X-1
4)对于如下定义的段
name segment
...
name ends
如果段中占用N个字节,啧程序加载后,实际占有空间为
⌈
N
16
⌉
×
16
\lceil \frac{N}{16} \rceil\times16
⌈16N⌉×16 (说白点就是向上凑够16个)
(3)再换一段程序
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
1)data段中的数据是多少?
data:0123h,0456h
2)求CS,SS,DS
CS=076A,SS=076E,DS=076D
3)假设code段地址为X,则data段地址为X+4,stack段地址为X+5
(4)不指明程序入口,那么程序会直接从最开始运行,所以只有(3)可以正常运行
(5)写一段程序让a,b中的数据求和到c中
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 cx,8
mov bx,0
s:
mov ax,ds:[bx]
add bx,20h
mov ds:[bx],ax
sub bx,10h
mov ax,ds:[bx]
add bx,10h
add ax,ds:[bx]
mov ds:[bx],ax
sub bx,20h
inc bx
loop s
code ends
end start
运行情况如下:
当学习了7.5之后,我们可以利用[bx+idate]的方式来访问内存,可以化简我们的程序
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 cx,8
mov bx,0
s:
mov ax,ds:[bx]
mov ds:20h[bx],ax
mov ax,ds:10h[bx]
add ax,ds:20h[bx]
mov ds:20h[bx],ax
inc bx
loop s
code ends
end start
(6)
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
mov ss,ax
mov ax,a
mov ds,ax
mov sp,10h
mov cx,8
mov bx,0
s:
push ds:[bx]
add bx,2
loop s
code ends
end start
运行结果
其他实验题答案:实验题答案合集