583413088 发表于 2011-8-7 13:37:25

6.2在代码段中使用栈

程序6.3中用DW定义了16个字空间,知识将8个字倒叙排放,为什么要用到16个字的栈空间啊,谁能给我讲讲啊

??? 发表于 2011-8-7 13:46:14

那只是个栈,不是一定要和数据相等的。

parbbo 发表于 2011-8-7 14:36:21

这个主要是让你看起来比较舒服,排列整齐,在debug模式下刚好是一行

kill8716 发表于 2011-8-7 14:44:18

顶上~·顶上!~~

583413088 发表于 2011-8-7 15:14:17

我定义了八个怎么不行啊

583413088 发表于 2011-8-7 15:50:21

assume cs:codesg
codesg segment
        dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
        dw 0,0,0,0,0,0,0,0
start: mov ax, cs
           mov ss, ax
           mov sp, 32
           mov bx, 0
           mov cx, 8
        s:push cs:
        add bx, 2
        loop s
       
        mov bx, 0
        mov cx, 8
s0:pop cs:
   add bx, 2
       loop s0
       mov ax, 4c00h
       int 21h
codesg ends
end start

583413088 发表于 2011-8-7 15:50:53

这个代码不对吗怎么求不出来啊

583413088 发表于 2011-8-7 15:52:17

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:
           add bx, 2
           loop s
          
           mov bx, 0
           mov cx, 8
        s0:pop cs:
           add bx, 2
           loop s0
          
           mov ax, 4c00h
           int 21h
codesg ends
end start
这个代码可以啊

??? 发表于 2011-8-7 16:04:51

assume cs:codesg
codesg segment
      dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
      dw 0,0,0,0,0,0,0,0
start: mov ax, cs
         mov ss, ax
         mov sp, 32
         mov bx, 0
         mov cx, 8
      s:push cs:
      add bx, 2
      loop s
      
      mov bx, 0
      mov cx, 8
s0:pop cs:
   add bx, 2
         loop s0
         mov ax, 4c00h
         int 21h
codesg ends
end start



我的电脑可以运行。

parbbo 发表于 2011-8-7 16:14:22

仔细查找呗

臭乞丐 发表于 2011-8-11 00:29:19

??? 发表于 2011-8-7 16:04 static/image/common/back.gif
assume cs:codesg
codesg segment
      dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h


课本为什么是   mov sp, 30而小甲鱼的是    mov sp, 32      我来探讨下 dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
这里是 16个字型数据
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h   这里是 8个字型数据进栈 出栈 都是 8个字型数据

16个字型数据+进栈8个字型数据+出栈8个字型数据=32   那么push执行的步骤一. sp-2  二 . ss:sp  

那么来看下 检测点6.1 第2题小甲鱼 答安
(2)
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   ;cs为所填第一空
    mov ss,ax
    mov sp,24h    ;此条指令为所填第二空
    mov ax,0
    mov ds,ax
    mov bx,0
    mov cx,8
s:
    push
    pop cs:    ;此条指令为所填第三空
    add bx,2
    loop s
   
    mov ax,4c00h
    int 21h
codesg ends
end start


按照上面的分析dw 0,0,0,0,0,0,0,0,0,0这里是 10个字型数据
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h   这里是 8个字型数据进栈 出栈 都是 8个字型数据
10个字型数据+进栈8个字型数据+出栈8个字型数据=26
为什么小甲鱼这里不是 mov sp,26h   而是 mov sp,24h    ;此条指令为所填第二空  求解




habou 发表于 2011-8-12 17:26:11

楼上的算法错误。仔细研究吧。十进制与十六进制不要混淆了。(8+10)*2/16=?

张国祥 发表于 2011-8-12 18:43:59

栈太小可能会出错,具体我也不是很清楚

javanetwork 发表于 2011-8-13 15:32:10

据我研究,push的时候,不止sp指向的内存会改变,前面10个字节也会改变,至少debug下是这样的
上图了:
ss=0BB0 cx=0044
首先我用r修改sp,使sp=0010
0BB0:000051 00 00 B9 08 00 B8 B3-0B 8E D8 B8 B4 0B 8E D0
0BB0:0010BC 10 00 FF 37 43 43 E2-FA BB 00 00 B9 08 00 8F
这时候按t,执行push cx
再查看内存
0BB0:000051 00 00 B9 00 00 00 00-01 00 B0 0B 98 05 44 00
0BB0:0010BC 10 00 FF 37 43 43 E2-FA BB 00 00 B9 08 00 8F
可以看到从0BB0:0004~0BB0:000F共12个字节的数据发生了改变
这是为什么呢,有知道的告诉下

hj937733396 发表于 2011-8-13 15:41:02

你喜欢可以改为8个字啊,呵呵,
这只是申请一段内存空间,多少无所谓,够用就行了,
不知是不是,呵呵
页: [1]
查看完整版本: 6.2在代码段中使用栈