检测点 6.1
(1)下面的程序实现依次用内存 0:0 ~ 0:15 单元中的内容改写程序中的数据,完成程序:
assume cs:codesg
codesg segment
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
start:
mov ax,0
mov ds,ax
mov bx,0
mov cx,8
s:mov ax,[bx]
mov cs:[bx],ax
add bx,2
loop s
mov ax,4c00h
int 21h
codesg ends
end start
(2)下面的程序实现依次用内存 0:0 ~ 0:15 单元中的内容改写程序中的数据,数据的传送用栈来进行。栈空间设置在程序内。完成程序:
assume cs:codesg
codesg segment
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
dw 0,0,0,0,0,0,0,0,0,0
start:
mov ax,cs
mov ss,ax
mov sp,24h
mov ax,0
mov ds,ax
mov bx,0
mov cx,8
s:push [bx]
pop cs:[bx]
add bx,2
loop s
mov ax,4c00h
int 21h
codesg ends
end start
以上(1)和(2)中的代码都存在一些问题,即将数据、栈和代码都放在了同一段中。
这样做主要会产生两个问题:其一,会使整个程序显得十分的混乱;其二,如果数据、栈和代码需要的空间超过64KB(因为8086 CPU的寄存器是16位。),就不能放在一个段中了。
因此,应该定义多个段来存放不同类型的内容,改进后的代码如下所示:
assume cs:codesg
data segment
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
data ends
stack segment
dw 0,0,0,0,0,0,0,0,0,0
stack ends
codesg segment
start:
mov ax,stack
mov ss,ax
mov sp,14h
mov ax,0
mov ds,ax
mov bx,0
mov cx,8
s:push [bx]
pop cs:[bx]
add bx,2
loop s
mov ax,4c00h
int 21h
codesg ends
end start