2676516085 发表于 2012-5-13 17:44:14

急!实验五第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,a
      mov ds,ax
   
   mov ax,b
   mov ss,ax
   mov sp,16
   
   mov bx,0
   mov cx,8
   
s:push
   add bx,2
   loop s
   
   mov ax,4c00h
   int 21h
code ends
end start
这是我写的,执行程序时,定义的栈段中,没推入数据时,内存空间都是0,
0c6b:0020      00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00
但推入一个数据后,前面也会有数据在里面,(我一直认为只推入了一个字型数据,前面应当还是保持0)
0c6b:0020      00 00 00 00 6D 0C 00 00 - 15 00 6E 0C 7B 06 01 00
这是为什么?(0c6b:0020--0c6b:30是cpu分配的栈段)
程序在执行时不会改变数据段的数据。

而且程序运行到当cx=3时,再执行add bx,2指令时,程序报错,但程序改动下可以执行,且不报错
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,0   (我多加了个0,栈段就改为32)
b ends
code segment
start:mov ax,a
      mov ds,ax
   
   mov ax,b
   mov ss,ax
   mov sp,32(改为32)
   mov bx,0
   mov cx,8
   
s:push
   add bx,2
   loop s
   
   mov ax,4c00h
   int 21h
code ends
end start

若程序改为下面这个,程序执行到cx=5,push ,推入数据后,会开始改变“0ah,0bh,0ch,0dh,0eh,0fh,0ffh”这些数据,这是为什么?

assume cs:code
code segment
dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh
dw 0,0,0,0,0,0,0,0
start:mov ax,cs
   mov ss,ax
   mov sp,48
   
   mov ds,ax
   
   mov bx,0
   mov cx,8
   
s:push
   add bx,2
   loop s
   
   mov ax,4c00h
   int 21h
code ends
end start


leebox 发表于 2012-5-14 22:55:16

栈顶都溢出了出什么问题 都有可能的   你申请了 16位的空间 栈指针指向48、32大于 你申请的空间 谁知道哪里有什么数据 。。。。。

莫名其妙 发表于 2012-5-15 09:27:45

楼上说的很对 栈空间的设置是个问题 还有就是在你单步调试的时候 会向栈中保存指令的cs ip 以便你在次执行-t指令时 能回到原来位置继续单步执行下一条指令.所以栈空间还是相应的大一点好!~:P
页: [1]
查看完整版本: 急!实验五第6题