小甲鱼汇编教程中出现的两个疑问【至今还未解决】
本帖最后由 siqisiyao 于 2015-11-26 21:30 编辑代码在一楼,调试在二楼。编译、链接后,得到1.exe文件,然后debug。
--------------------------------------------------------------------------------------------
问题一:
C:\huibian>debug 1.exe
-r
AX=0000BX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B2DES=0B2DSS=0B3ECS=0B40IP=0000 NV UP EI PL NZ NA PO NC
0B40:0000 B83E0B MOV AX,0B3E
1、DS中存放的是PSP的段地址,PSP的偏移地址为0,所以程序的地址就是:DS+10H:0
2、从本例中可以看到:DS=0B2D,所以程序的地址就应该在:DS+10H = 0B2D + 10H = 0B3D
3、在本程序中CS的值就应是0B3D,但实际上却是0B40,这是为什么呢?
-----------------------------------------------------------------------------------------------
问题二:
code segment
start: mov ax,stack
mov ss,ax
mov sp,20h
mov ax,data
mov ds,ax
-t
AX=0B3EBX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B2DES=0B2DSS=0B3ECS=0B40IP=0003 NV UP EI PL NZ NA PO NC
0B40:0003 8ED0 MOV SS,AX
-t
AX=0B3EBX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B2DES=0B2DSS=0B3ECS=0B40IP=0008 NV UP EI PL NZ NA PO NC
0B40:0008 B83D0B MOV AX,0B3D
-t
从三楼的调试内容看,单步调试时,源程序中的move sp,20h却并没有执行,怎么会多出一个字节来,这是为什么呢?
------------------------------------------------------------------------------------------------ 本帖最后由 siqisiyao 于 2015-11-26 22:05 编辑
assume cs:code, ds:data, ss:stack
data segment
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h ;8*2字节=16个字节
data ends
stack segment stack
dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;16*2字节=32个字节
stack ends
code segment
start: mov ax,stack
mov ss,ax
mov sp,20h
mov ax,data
mov ds,ax
mov bx,0
mov cx,8
s:push
add bx,2
loop s
mov bx,0
mov cx,8
s0:pop
add bx,2
loop s0
mov ax,4c00h
int 21h
code ends
end start
本帖最后由 siqisiyao 于 2015-11-3 16:23 编辑
C:\huibian>ml 1.asm
Microsoft (R) Macro Assembler Version 6.15.8803
Patched for you by promethee in the year 2001 - enjoy
Copyright (C) Microsoft Corp 1981-2000.All rights reserved.
Assembling: 1.asm
Microsoft (R) Segmented Executable LinkerVersion 5.60.339 Dec5 1994
Copyright (C) Microsoft Corp 1984-1993.All rights reserved.
Object Modules [.obj]: 1.obj
Run File : "1.exe"
List File : NUL
Libraries [.lib]:
Definitions File :
C:\huibian>
C:\huibian>debug 1.exe
-r
AX=0000BX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B2DES=0B2DSS=0B3ECS=0B40IP=0000 NV UP EI PL NZ NA PO NC
0B40:0000 B83E0B MOV AX,0B3E
-t
AX=0B3EBX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B2DES=0B2DSS=0B3ECS=0B40IP=0003 NV UP EI PL NZ NA PO NC
0B40:0003 8ED0 MOV SS,AX
-t
AX=0B3EBX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B2DES=0B2DSS=0B3ECS=0B40IP=0008 NV UP EI PL NZ NA PO NC
0B40:0008 B83D0B MOV AX,0B3D
-t
AX=0B3DBX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B2DES=0B2DSS=0B3ECS=0B40IP=000B NV UP EI PL NZ NA PO NC
0B40:000B 8ED8 MOV DS,AX
-t
AX=0B3DBX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B3DES=0B2DSS=0B3ECS=0B40IP=000D NV UP EI PL NZ NA PO NC
0B40:000D BB0000 MOV BX,0000
-t
AX=0B3DBX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B3DES=0B2DSS=0B3ECS=0B40IP=0010 NV UP EI PL NZ NA PO NC
0B40:0010 B90800 MOV CX,0008
-t
AX=0B3DBX=0000CX=0008DX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B3DES=0B2DSS=0B3ECS=0B40IP=0013 NV UP EI PL NZ NA PO NC
0B40:0013 FF37 PUSH DS:0000=0123
-t
AX=0B3DBX=0000CX=0008DX=0000SP=001EBP=0000SI=0000DI=0000
DS=0B3DES=0B2DSS=0B3ECS=0B40IP=0015 NV UP EI PL NZ NA PO NC
0B40:0015 83C302 ADD BX,+02
-t
AX=0B3DBX=0002CX=0008DX=0000SP=001EBP=0000SI=0000DI=0000
DS=0B3DES=0B2DSS=0B3ECS=0B40IP=0018 NV UP EI PL NZ NA PO NC
0B40:0018 E2F9 LOOP 0013
-t
AX=0B3DBX=0002CX=0007DX=0000SP=001EBP=0000SI=0000DI=0000
DS=0B3DES=0B2DSS=0B3ECS=0B40IP=0013 NV UP EI PL NZ NA PO NC
0B40:0013 FF37 PUSH DS:0002=0456
-t
AX=0B3DBX=0002CX=0007DX=0000SP=001CBP=0000SI=0000DI=0000
DS=0B3DES=0B2DSS=0B3ECS=0B40IP=0015 NV UP EI PL NZ NA PO NC
0B40:0015 83C302 ADD BX,+02
-t
AX=0B3DBX=0004CX=0007DX=0000SP=001CBP=0000SI=0000DI=0000
DS=0B3DES=0B2DSS=0B3ECS=0B40IP=0018 NV UP EI PL NZ NA PO NC
0B40:0018 E2F9 LOOP 0013
- 怎么论坛里没有人能帮助解决一下呢? 问题一的答案: 问题二的答案: 以后会懂的啦。。。 确实,慢慢来,学习多点就懂了 问题一:
C:\huibian>debug 1.exe
-r
AX=0000BX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B2DES=0B2DSS=0B3ECS=0B40IP=0000 NV UP EI PL NZ NA PO NC
0B40:0000 B83E0B MOV AX,0B3E
1、DS中存放的是PSP的段地址,PSP的偏移地址为0,所以程序的地址就是:DS+10H:0
2、从本例中可以看到:DS=0B2D,所以程序的地址就应该在:DS+10H = 0B2D + 10H = 0B3D
3、在本程序中CS的值就应是0B3D,但实际上却是0B40,这是为什么呢?
PSP的大小为256字节也就是100H
DS为程序开始的段地址0B2D,物理地址为0B20H*16(SA)+0H(EA)=0B2D0H
PSP的物理地址为 0B2D0H到 0B3D0 (0B2D0H+100H)
data segment
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h ;8*2字节=16个字节
data ends
stack segment
dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;16*2字节=32个字节
stack ends
也就是说data segment 和stack segment 占了48字节(16+32)= 十六进制30H
程序从
code segment
start: 。。。。。
开始执行 物理地址是 0B3D0H + 30H = 0B400H
CS=0B40IP=0000 它的物理地址就是(0B40 H )*16+0000H=0B400H
总结:
DS为数据开始的段地址
CS为程序开始的段地址
PSP占DS*16 ~ (DS+10)*16 =空间
因为你这个程序有 data segment 和stack segment 所以程序开始的地方要在加上data segment 和stack segment 所占的空间 问题二:
code segment
start: mov ax,stack
mov ss,ax
mov sp,20h
mov ax,data
mov ds,ax
-t
AX=0B3EBX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B2DES=0B2DSS=0B3ECS=0B40IP=0003 NV UP EI PL NZ NA PO NC
0B40:0003 8ED0 MOV SS,AX
-t
AX=0B3EBX=0000CX=005CDX=0000SP=0020BP=0000SI=0000DI=0000
DS=0B2DES=0B2DSS=0B3ECS=0B40IP=0008 NV UP EI PL NZ NA PO NC
0B40:0008 B83D0B MOV AX,0B3D
-t
从三楼的调试内容看,单步调试时,源程序中的move sp,20h却并没有执行,怎么会多出一个字节来,这是为什么呢?
请学习下第12章 内中断
12.12 响应中断的特殊情况
就是来顶 支持
页:
[1]