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
为啥 mov sp,16
栈段定义8个字型数据和定义2个字型数据都是mov sp,16?
---------------------------------------------------------------------------------
对于这个程序不会出错。因为段对齐的原因,编译器会留16的整数倍的地址,但是只会将前四个字节初始化为0.
最好还是这样,
stack segment
dw 0,0,0,0,0,0,0,0
stack ends
要用多少栈就初始化多少,否则容易出错。
比如上面的程序,如果mov sp,32,就会出错。把代码段给覆盖了。
|