且看王爽老师《汇编语言》第二版程序6.3,先完整抄录如下:
;实现0123h, 0456h, 0789h, 0abch, 0defh, 0fedh, 0cbah, 0987h的逆序存储
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, 0, 0, 0, 0, 0, 0
start:
mov ax, cs
mov ss, ax
mov sp, 30h
mov bx,0
mov cx,8
s: push cs:[bx]
add bx,2
loop s
mov bx,0
mov cx,8
s0: pop cs:[bx]
add bx,2
loop s0
mov ax,4c00h
int 21h
codesg ends
end start
注意程序申请了内存空间,共32个字节(值全为0),用来作为临时空间。程序本身没有什么问题,内存的动作也合情合理。
但是,如果临时内存空间改为16个字节,问题就来了!用debug.exe单步执行的话,会发现在执行 mov ss, ax后,存储数据的内存空间被神奇修改,甚是诡异。照理说,ss的赋值和内存没有联系。原因没想清楚,先占个坑,后头再来想吧。莫非是数据保护,或是字节对齐???望达人赐教!
内存变为16字节后:
dw 0123h, 0456h, 0789h, 0abch, 0defh, 0fedh, 0cbah, 0987h
dw 0, 0, 0, 0, 0, 0, 0, 0
mov ax, cs
mov ss, ax
mov sp, 20h
执行情况
mov ax, cs
mov ss, ax
的内存情况见图1,2。
图1 执行mov ss,ax前
图2 执行mov ss,ax后