『第 16 楼』:
debug
使用 LLM 解释/回答一下
debug命令 免费编辑 添加义项名
B 添加义项 ?
所属类别 : 其他
DEBUG是一个DOS实用程序,是供程序员使用的程序调试工具,可以用它检查内存中任何地方的字节以及修改任何地方的字节。它可以用于逐指令执行某个程序以验证程序运行的正确性,也可以追踪执行过程、比较一个指令执行前后的值以及比较与移动内存中数据的范围,读写文件与磁盘扇区。
词条 百科 精彩信息一览无遗
基本信息
中文名称
debug命令
性质
DOS实用程序
作用
供程序员使用的程序调试工具
优点
检查内存字节
目录
1命令介绍
2命令功能
3实际应用
折叠编辑本段命令介绍
它的功能包括以下几个方面。
⒈ 直接输入,更改,跟踪,运行汇编语言源程序;
⒉ 观察操作系统的内容;3.查看ROM BIOS的内容;
⒋观察更改RAM内部的设置值;
⒌以扇区或文件的方式读写软盘数据
DEBUG把所有数据都作为字节序列处理。因此它可以读任何类型的文件。DEBUG可以识别两种数据: 十六进制数据和ASCⅡ码字符。它的显示格式是各个字节的十六进制值以及值在32与126之间的字节的相应ASCⅡ码字符。
在DEBUG中输入数据有两种方法: 提示方法和非提示方法。在用提示方法时,用户可以输入要求输入数据的命令,后跟数据所要输入的地址。然后用户就可以看到该地址中已有内容及一个冒号提示符。此时用户可以在提示符下输入一个新的值或者按下回车键或CTRL+C回到短横(-)提示符。在运用非提示方法时,用户可以输入要输入数据的内存地址以及要输入的字节。但与使用字处理程序或正文编辑程序时不一样,在使用DEBUG时,用户不能直接移动光标到一入口点输入或修改数据,而要一次输入一个或几个字节。
在使用DEBUG时可以只涉及内存中的数据,从而一般都要指定所要处理的内存地址,地址的输入格式是: : 。如果没有输入地址,DEBUG将假定为当前内存段,从位于地址100H的字节开始。前100H字节保留给程序段前缀使用,这一专用区域用于建立DOS与程序之间的联系。DEBUG总是用四位十六进制数表示地址。用两位数表示十六进制数据。
讲到这里大家应该对DEBUG有了初步的了解,但是光知道这些可不够,接下来我来讲讲DEBUG的命令格式和命令。当输入
DEBUG
调用了DEBUG程序,就会出现一个短横提示符,用户就可以在这一短横后输入DEBUG程序的命令。有些DEBUG命令会显示一个内存地址并产生一个作为提示符的冒号。在这些提示符后,用户可以输入一个新值以改变所显示位置原来的值。如果用户不输入一个新值而是按下回车或CTRL+C,那么原来的值不会改变。
一般用不着把地址和命令名字分开。例如,用转储命令D察看100号地址的数据,那么这个命令可以用以下任一种形式输入:
D100
D,100
D 100
如果输入的命令中出现了错误,DEBUG将在下一行对着错误的位置标记出来,例如:
-s100 d 12
^Error
折叠编辑本段命令功能
折叠A汇编命令
功能: 将指令直接汇编成机器码输入到内存中。
说明: 用于小段程序的汇编及修改目标程序,所有输入的数字均采用十六进制, 用户装入内存的汇编语句是连续存放的,若没有指定地址,并且前面没有使用汇编命令,该语句被汇编到 CS:0100区域。
例A:>DEBUG
-a 0100
08F1:0100 MOV AH,09
08F1:0102 MOV DX,109
08F1:0105 INT 21H;
08F1:0107 INT 21H;<-XP下运行cmd debug时,应该是INT 20H,21H会出遇无效指令错误
08F1:0109 db 'May I help you $'
08F1:0115←离开a状态
-g ←运行
May I help you 运行结果
Program terminated normally表示运行正常
折叠C比较命令
功能: 比较两内存区域中的内容是否相同,若不同则显示其地址和内容。
如:C4000:0 3F 100
就是用来比较4000:0000-4000:003F与DS:0100-DS:013F之间的内容:其显示格式如下:
内存地址1内含值1内含值2内存地址2
例:比较4000:0 3F 100内容的差异
-C4000:0 3F 100
4000:0000 64 43 08F1:0100
4000:0001 3E 69 08F1:0101 显示内容的差异处
4000:0002 78 FF 08F1:0102
……………………………………
如果要比较的范围在DS内,则段地址不必指出:
如:-C 0 4 100;比较DS:0---DS:4与DS:100---DS:104
C命令的另一种格式如下:C地址1 L 长度 地址2
如:-C000:0 L4 0;由0000:0与与DS:0开始比较它同-C0000:0 3 0命令相等,显示结果如下:
0000:0000 8A C0 08F1:0000
0000:0001 10 20 08F1:0001 它们都比较4个字节
0000:0002 1C 00 08F1:0002
0000:0003 49 7F 08F1:0003
折叠转储命令
* D 或D 转储命令
功能: 以内存映象方式显示内存中的信息。
说明: 转储用左右两部分显示内存映象内容,左边以十六进制,右边以ASCⅡ字符显示,所有不可打印字符用句号(。)表示。每行显示16个字节的内容,在第八和第九个字节之间有一个连字符 - 此命令隐含的段地址为DS的值。若未指定起始地址,则D命令从显示的最后一个单元的下一个单元开始显示,若以前没有使用给D命令, 则从初使化的段寄存器的内容,加上地址偏移量 0100H 开始显示。
例:-d10,4f即为显示DS:4f的内容在D命令中如不指出段地址,则其默认为DS段。
如指明段地址,则从指明的段地址列出指定的范围
如:-dfff:00:0f
我们也可以指定长度来列出所需要内存内容
如:-d 100 L20即为显示由DS:100-DS:11F的内容,共20H个字节:
* E
⑴用给定内容代替指定范围的单元内容
-E地址 内容表
例:-E100 41 42 43 44 48 47 46 45
-D 100,L08
08F1:0100 41 42 43 44 48 47 46 45 ABCDHGFE…
⑵逐个内存内容
例:-E 100:
08F1:0100 76 42 :42是操作员键入
此命令是将原100号内存内容76修改为42,用D命令可察看。
* F 填写命令
功能: 将要填写的字节或字节串填入由地址范围指定的存储器中。
例:-f100 120 61 62 63 64
-d100 11f
08F1:0100 61 62 63 64 61 62 63 64 -61 62 63 64 61 62 63 abcd abcd abcd abcd
08F1:0110 13 67 98 E3 C8 2E B3 B6 -03 21 AC 19 3121 4E 96 g……1…
如果数据行超出指定的范围,则填不下的数值会被忽略。
例:-f 100 107 41 43 43 44 45 46 47 48 49 4A 4B 4C 4D -d 100,lof
08F1:0100 41 42 43 44 45 46 47 64 -61 62 63 64 ABCDEFGdabcdabcd
由上例可看出,超出范围的数据被忽略
另外,F和E命令都可填入字符串:
如:-F 100 105 "MSDOS"
-d 100 l0f
08F1:0100 4D 53 44 4F 53 46 47 64 -61 62 63 64 MS DOS FGabcd abcd
折叠G执行命令
功能: 执行正在调试的程序,当达到断点时停止执行, 并且显示寄存器标志和下一条要执行的命令。
说明: 如果没有指定起始地址,那么当前指令地址由CS,IP寄存器的内容来决定,如果用户指定起始地址就从指定的起始地址开始执行。如果指定断点,当指令到达指令地址时停止执行,并显示各寄存器标志位的内容和下一条要执行的命令,最多允许用户设定10个断点。
例:A:\>debug tan.exe
-u:反编译成汇编语言程码
…………
. .
-g 100 指定中断点
Program terminated normally:
另外:我们在DEBUG下可运行一个文件.EXE
如:A:\>debug tan.exe
-g
即可开始运行此程序,和在DOS下完全一样:
* H 十六进制算术运算命令
功能: 分别显示两个十六进制数相加的和以及第一个数减去第二个数的差。
说明: 替用户完成简单的十六进制数的运算。
例:-h4538 5623
9B5B EF15
折叠I命令
功能: 从指定的端口输入并显示(用十六进制)的一个字节。
例:-i70
F9;显示70端口的内容为F9
I命令可由80X86的64K个端口取数据
折叠L命令
功能: 将一个文件或盘的绝对扇区装入存储器。
说明: 单个L命令能够装入的最大扇区数是 80H,其中盘号 0,1,2,3……分别代表 A,B,C,……出现读盘错,显示错误信息。
⑴格式1.L装入地址 驱动器名 起始扇区/扇区数
这种方式可把磁盘上指定扇区范围的内容装入到存储器从指定地址开始的区域中,在此外扇区编号引用逻辑/扇区的方式。
例:-L 100 0 01,将A驱的0扇区装至CS:100上
-d 100 10f
08F1:0100 EB 3C 90 3C 53 44 4F 53 -36 2E 32 32 02 01 01 00.L,MSDOS 6.22……
⑵格式2:L装入地址
这种方式可把指定文件装入内存,装入的文件可在进入DEBUG时指定亦可用N命令建立,格式为-n文件名:
例1 DEBUG tan.pas
-L 100
例2 DEBUG
-n tan.pas
-L 100
须知:L命令只能读取逻辑扇区,不能读取硬盘分区表
L命令中所用的磁盘代码A=00,B=01,C=02……
折叠M数据命令
功能: 把地址范围内的存储器单元的内容移到起始地址的指定地址中
说明: 传送期间,源区和目标区可以部分重叠;传送后源区域数据保持不变。
例:-e100 41 42 43 44 45
-d100 10f
08F1:0100 41 42 43 44 45 62 62 63 64 -61 62 63 64 61 62 63 64 ABCDEBCDABCDABCD
-M 100 104 110
-d110 L1F
08F1:0100 41 42 43 45 0A 21 19-20 01 01 20 07 96 87 9F ABCDE……
* N
功能: 定义操作文件名。
说明: 可同时定义两个操作文件,并将形成的文件控制块相应的设置在内存 CS:5C和CS:6C上,供以后的L和W命令操作之用。我们在运行程序侦错时,在启动DEBUG时在其后加文件程序名以及该程序的参数或运行文件,但当我们侦错一段后,可能装入其它文件来测试,这时我们可利用N命令来设置而无需退出DEBUG。
例:A:\>DEBUG tan.exe
-n youg.pas
当程序侦错一段时间后,若要把tan.exe装入tan1.pas则-ntanl.pas
折叠O输出命令
功能: 发送字节到指定的输出端口。
例:当我们遇到开机要求输入口令时,可用如下方式取消
-O 70 10
_O 71 00
折叠P进程命令
功能: 将一个子程序调用指令,循环指令,中断指令或一个重复字符串指令,停止在下一条指令上。
说明: 在执行一条子程序调用指令,循环指令,中断指令或一个重复字符串指令时,发出P命令去执行有关指令,并且返回到要执行的下一条指令。P命令和T一样选用来跟踪程序运行过程用的命令,我们可以在P命令中指定程序运行的起始地址,指令个数,如未指定则CS:IP所指定程序的地址开始一次运行一条令。
P与T命令的差别在于P命令把CALL/INT当成一条指令来执行,简化了跟踪过程,P命令只运行RAM内存的命令,而T命令则可运行RAM和ROM里的程序。
折叠R寄存器命令
功能: 一,显示单个寄存器的内容,并提供修改功能。二,显示所有寄存器内容, 再加上字母标志位状态以及要执行的下一条指令。三,显示8个标志位状态, 并提供修改功能。若不想改变则回车即可。
例:-r bx
bx 0050
:51
-r
AX=0000 BX=0051 CX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0003 ES=0CD3 SS=0CD3 IP=0100 NV UP EI PL NZ NA PO NC
0CD3:0100 0F DB OF
若想改变标志寄存器,用-RF回车,则DEBUG会将标志内容显示出来,若想改变任一标志,只要输入该标志的名称即可。
标志名称 设置 未设置 标志名称 设置 未设置
滋出 OV(溢出) NV(未溢出) 零位 ZR NZ(不等于零)
方向 DN(减少) UP(增加) 辅助进位 AC NA(无进位)
中断 EI(许可) DI(禁止) 奇偶标志 PE(偶) PO(奇)
符号 NG(负) PL(正) 进位 CY NC(清除进位)
例:-Rf
NV UP EI PL NZ NA PO NC :-OV DI← 输入值
折叠S命令
功能: 在指定的地址范围内查找给定的字符串。
说明: 用来指定在地址范围内查找一个字符串,若找到则显示其地址, 否则直接显示DEBUG提示符。隐含地址为DS段值。
在此内存可以用(起始地址)(终止地址)或(起始地址)L(长度)的方式来表示,而字符串与数据行则可混合使用:如:02.76"BC"。
例:-d100 lof
08F1:0100 OF 2A 41 43 0B 31 42 96 -FF F0 B9 8A F3 00 B1.. AC,1B...
-S 100 lof"AC"
08F1:0102← 表示找到,由0102开始,
折叠T跟踪命令
功能: 逐条跟踪程序的执行,每条指令执行后都将显示各寄存器的内容。
说明: 通常采用跟踪一条指令,但用户也可以用指令条数设定一次跟踪多条指令, 每执行一条指令之后,显示所有寄存器的内容和标志状态。
逐条指令跟踪 -T
从指定地址起执行一条指令后停下来,显示所有寄存器内容及标志位的值,如来指定地址则从当前CS:IP开始执行。
A:\>DEBUG
-A
08F1:0100 MOV DL,03H
08F1:0102 MOV AH,02H
08F1:0104 INT 21H
08F1:0106 INT 20H
08F1:0108
-T
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=08F1 ES=08F1 SS=08F1 CS=08F1 1P=0105 NV UP EI PL NZ PO CY
09F1:0102 B402 MOV AH,02
若指定起始地址,则T命令会从指定的地址开始跟踪,我们还可以指定跟踪一次所运行指令的个数,用Ctrl+S暂停屏幕的显示,以便观察。
-t=100 10;由CS:100开始跟踪10条指令
折叠U地址命令
功能: 将内存中的内容转换为汇编语句。
说明: 反汇编的字节数取决与用户的系统显示形式,以及在U命令中使用的可选项。
⑴从指定地址开始编译,反汇编32个字节
-U←从CS:100开始,其反汇编32个字节
如果地址被省略,则从一个U命令的最后一条指令的下一条单元开始汇编32个字节。
⑵对指定的存贮范围进行反汇编
-u起始地址 终止地址(L 长度)
例:-U 100 109
08F1:0100 CD20 INT 20
08F1:0102 FF9F009A CALL FA12
08F1:0106 F0 LOCK
08F1:0107 FE1D CALL FAR
08F1:0109 F0 LOCK
说明:如指定了范围则整个范围全都会被反编译
折叠W写盘命令
* W 写盘命令
功能: 将修改过的数据写到磁盘上。
说明: 可以将指定内存地址开始的数据写在磁盘上,可以在没有指定参数, 或指定地址参数的情况下,将调试文件写在磁盘上。
在运行W时需设置文件的大小CX或BX寄存器
⑴把数据写入磁盘的指定扇区
-W 起始地址 驱动器名 起始扇区 扇区数
⑵把数据写入指定文件中
-W 起始地址
例A:\>DEBUG
-A
08f1:0100....
. 写入程序段
08F1: 012A....
-R CX
CX:0000
:2A←写入字节数,即为程序结尾地址减起始地址
-n tan.com←设置文件名,需后缀为com
-w
Wring 002A bytes
-q
A:\>TAN←即可执行此程序
* "XD"命令:释放EMS内存
例:-XD 0001
handle 0001 deallocatel←释放了
利用XD释放后可再分配
*"XM"命令;把扩充内存上的内存页区映射到主内存区
格式:XM RAM 长页码 主内存页码句柄
例:-XM3 2 0001←把0001号句柄的第3号逻辑页区映射到2号真实页区
Logical page 03 mapped to physical page 02
*"XS"命令:显示当前EMS使用情况。
格式 -XS
折叠编辑本段实际应用
⒈ 非物理0磁道坏软盘的修复
此种损坏从软盘盘面上来看并没有明显的划伤和霉变。一般可以恢复其数据,也可使软盘重新在利用。
处理方法如下:
Ⅰ. 进入debug
Ⅱ. 取一张引导区没有损坏的好磁盘,插入软驱
-l 100 0 0 1
Ⅲ. 插入损坏的磁盘到软驱
-w 100 0 0 1
-q
注意:好盘与坏盘容量必须相同
⒉ 物理0磁道坏软盘中的数据读取
对于0磁道损坏的磁盘,一般来说是应该抛弃了,当你也不妨试一试已下方法:
磁化处理:用较强的磁铁在靠近坏磁盘的表面处反复移动,切不可碰到磁盘介质,以免划伤表面,然后在试试格式化。
软盘换面:小心的将磁盘打开,坚磁片与金属芯片分开,翻面后再按原来的方法粘在一起即可,在重新格式化。
diskfix:对于diskfix想必大家都用的比较多了,里面的磁盘修复功能很好用的。能修复大多数磁盘表面错误。
⒊ 硬盘启动失败处理
在正常机上格式化一张软盘,无其它数据
进入debug
-l 0 2 0 1
-w 0 0 0 1
-q
用系统盘启动故障机后
在进入debug
-l 0 0 0 1
-w 0 2 0 1
-q
⒋ 软盘不能正确读取解决方法
如果使用软盘时出现如下提示
general failure error reading drive a
可以用以下方法解决:
将一张好盘插入软驱
进入debug
-a 100
****:*100 mov al,0
****:**** mov cx,1
****:**** mov dx,0
****:**** mov bx,1000
****:**** int 25
****:**** int 20
回车
-g=0100
插入坏盘并进入debug
-a 200
****:*100 mov al,1
****:**** mov cx,1
****:**** mov dx,0
****:**** mov bx,1000
****:**** int 26
****:**** int 20
回车
-g=200
⒌ cmos 数据的保存,恢复
cmosram的'地址口'的口地址为 70h '数据口'的口地址为 71h 读取时只需将读的cmosram的地址送到70h,随后就可以从71 h中得到所需数据。
⑴读取cmos数据 进入debug
-a 100
****:*100 mov bx,1000
****:**** mov cx,0040
****:**** mov ax,0000
****:0109 mov dx,cx
****:**** mov cx,0005
****:010e loop 010e
****:**** out 70,al
****:**** mov cx,0005
****:0115 loop 0115
****:**** in al,71
****:**** mov 【bx】,al
****:**** cmp ah,0e
****:**** jb 0123
****:**** add ah,80
****:0123 inc ah
****:**** inc bx
****:**** mov cx,dx
****:**** mov al,ah
****:**** loop 0109
****:**** mov ah,3c
****:**** mov dx,0150
****:**** mov cx,0020
****:**** int 21
****:**** mov bx,ax
****:**** mov dx,1000
****:**** mov cx,0040
****:**** mov ah,40
****:**** int 21
****:**** mov ah,4c
****:**** int 21
-a 150
****:0150 db "cmos.dat",0
****:0159
-r cx
cx 0000
:60
-n save cmos.com
-w
-q
-w 100 2 0 1
-q
⑵恢复cmos数据 进入debug
-a 100
****:*100 mov cx,0150
****:**** mov ah,3d
****:**** mov al,00
****:**** int 21
****:**** mov dx,1000
****:**** mov bx,ax
****:**** mov cx,0040
****:**** mov ah,3f
****:**** int 21
****:**** mov ax,0000
****:**** mov bx,dx
****:**** mov dx,cx
****:**** mov cx,0005
****:**** loop 011f
****:**** mov al,ah
****:**** out 70,al
****:**** mov cx,0005
****:**** loop 0128
****:**** mov al,【bx】
****:**** out 71,al
****:**** jb 0136
****:**** add ah,80
****:**** inc ah
****:**** inc bx
****:**** mov cx,dx
****:**** loop 011a
****:**** mov ax,0040
****:**** mov ds,ax
****:**** mov ax,1234
****:**** mov 【0072】,ax
****:**** jmp ffff:0000
-a 150
****:0150 db "cmos.dat",0
****:0159
-r cx
cx 0000
:60
-n write cmos.com
-w
-q
⒍ dos 引导扇区数据的保存与恢复
dos引导程序是被读到内存0000:7c00初开始执行的
获得正常的引导程序
进入debug
-l 100 2 0 1
-n a:dosboot.com
-r cx
:200
-w
-q
装入引导程序
进入debug
-n a:dosboot.com
-l
-r cx
:200
-w 100 2 0 1
-q
⒎ 硬盘主引导扇区数据的保存与恢复
硬盘工作正常时读取主引导扇区信息
注意:当分区改变时不能用此数据恢复
保存主引导扇区数据进入debug
-a 100
mov ax,0201
mov bx,0110
mov cx,0001
mov dx,0080
int 13
int 3
-g=100
-e 102 3
-e 10e c3
-r bx
bx 0110
:0
-r cx
cx 0001
:210
-n a:rboot.com
-w
-q
恢复主引导扇区数据:只需运行a盘的rboot.com
⒏ 硬盘非分配表备份与恢复
计算机运行正常时分配表备份
进入debug
-l 100 2 0 1
-n a:dbrup.dat
-r cx
:200
-w
恢复
进入debug
-n a:dbrup.dat
-l
-w 100 2 0 1
-q
⒐ 硬盘保护卡内幕
对于经常在外边上机的人来说,计算机维护人员一旦设置硬盘保护卡,自己作一些事来特别麻烦,想不想屏蔽掉硬盘保护卡,用以下方法或许可以借鉴:
进入debug
-a 100
mov ah,0
mov dl,0
int 13
-t
一直按t知道找到 cs=f000 记下此时 ds 的值 如:1234
-e e0:4c
34 12 00 f0
-q
⒑ 用debug作硬盘低级格式化
硬盘低级格式化一般用dm,但debug也可以低级格式化硬盘
进入debug
-a 100
mov ax,500
mov bx,180
mov cx,0
mov dx,80
int 13
int 3
-e 180 0 0 0 2
-q
⒒ 冷启动与热启动
用debug实现系统冷启动与热启动程序
冷启动:
-a 100
jmp ffff:0
int 20
-n a:reset.com
-r cx
:0007
-w
-q
热启动:
-a 100
mov ax,0040
mov ds,ax
mov ax,1234
mov si,0072
mov (si),ax
jmp ffff:0
-n a:rset.com
-r cx
:0014
-w
-q
⒓ dos内部命令加密
如加密 dir
用pctools或diskedit找 c:下的command.com文件
编辑该文件
pctools中:f-----f1 然后找所有03 44 49 52 找到后按f5修改成你所要的值 如:foo 以后只有输入foo 才能列出文件或文件目录。
diskfix 有良好的界面,操作起来和pctools差不多。
注意:如果不能修改,则解开文件的锁定 luck
其它命令代码
type 04 54 59 50 45
cd 02 43 44
del 03 44 45 44
copy 04 43 49 50 59
Last edited by zzz19760225 on 2017-11-13 at 14:06 ]
### debug Command
##### Free Edit Add Item
B Add Item?
---
Belongs to: Other
DEBUG is a DOS utility program, a program debugging tool for programmers. It can be used to check bytes anywhere in memory and modify bytes anywhere. It can be used to execute a program instruction by instruction to verify the correctness of the program operation, as well as to track the execution process, compare the values before and after an instruction is executed, and compare and move the range of data in memory, read and write files and disk sectors.
#### Entry Encyclopedia
Essential information at a glance
### Basic Information
- **Chinese Name**: debug command
- **Nature**: DOS utility program
### Function
- **For programmers**: Program debugging tool
- **Advantages**: Check memory bytes
### Table of Contents
1. Command Introduction
2. Command Function
3. Practical Application
#### Fold Edit Section: Command Introduction
Its functions include the following aspects.
1. Directly input, change, track, and run assembly language source programs;
2. Observe the content of the operating system;
3. View the content of ROM BIOS;
4. Observe and change the settings in RAM;
5. Read and write floppy disk data in sectors or files.
DEBUG treats all data as a sequence of bytes. Therefore, it can read any type of file. DEBUG can recognize two types of data: hexadecimal data and ASCII code characters. Its display format is the hexadecimal value of each byte and the corresponding ASCII code character of the byte whose value is between 32 and 126.
There are two methods to input data in DEBUG: prompt method and non-prompt method. When using the prompt method, the user can input the command to input data, followed by the address where the data is to be input. Then the user can see the existing content in that address and a colon prompt. At this time, the user can input a new value under the prompt or press Enter or CTRL+C to return to the hyphen (-) prompt. When using the non-prompt method, the user can input the memory address where the data is to be input and the bytes to be input. But unlike when using a word processing program or text editor, when using DEBUG, the user cannot directly move the cursor to an entry point to input or modify data, but has to input one or several bytes at a time.
When using DEBUG, one generally has to specify the memory address to be processed, and the input format of the address is: : . If no address is input, DEBUG will assume the current memory segment and start from the byte at address 100H. The first 100H bytes are reserved for the program segment prefix, and this dedicated area is used to establish the connection between DOS and the program. DEBUG always represents addresses with four hexadecimal numbers and hexadecimal data with two digits.
By now, everyone should have a preliminary understanding of DEBUG, but just knowing these is not enough. Next, I will talk about the command format and commands of DEBUG. When entering
```
DEBUG
```
the DEBUG program is called, and a hyphen prompt will appear. The user can input the command of the DEBUG program after this hyphen. Some DEBUG commands will display a memory address and generate a colon as a prompt. After these prompts, the user can input a new value to change the original value at the displayed position. If the user does not input a new value but presses Enter or CTRL+C, the original value will not change.
Generally, there is no need to separate the address and the command name. For example, to use the dump command D to view the data at address 100, this command can be input in any of the following forms:
```
D100
D,100
D 100
```
If there is an error in the input command, DEBUG will mark it at the wrong position in the next line, for example:
```
-s100 d 12
^Error
```
#### Fold Edit Section: Command Function
##### Fold A Assembly Command
- **Function**: Directly assemble instructions into machine code and input them into memory.
- **Description**: Used for assembling and modifying target programs for small segments. All input numbers are in hexadecimal. The assembled assembly statements that the user loads into memory are stored continuously. If no address is specified and no assembly command has been used before, the statement will be assembled into the CS:0100 area.
- **Example**:
```
A:>DEBUG
-a 0100
08F1:0100 MOV AH,09
08F1:0102 MOV DX,109
08F1:0105 INT 21H;
08F1:0107 INT 21H; <- When running cmd debug under XP, it should be INT 20H, and INT 21H will encounter an invalid instruction error
08F1:0109 db 'May I help you $'
08F1:0115←Leave the a state
-g ←Run
May I help you 运行结果
Program terminated normally表示运行正常
```
##### Fold C Comparison Command
- **Function**: Compare whether the contents in two memory areas are the same. If they are different, display their address and content.
- **Example**: For example, `C4000:0 3F 100` is used to compare the contents from 4000:0000-4000:003F and DS:0100-DS:013F. The display format is as follows:
```
Memory address 1 contains value 1 contains value 2 Memory address 2
```
- **Example**: Compare the differences in the contents of 4000:0 3F 100
```
-C4000:0 3F 100
4000:0000 64 43 08F1:0100
4000:0001 3E 69 08F1:0101 显示内容的差异处
4000:0002 78 FF 08F1:0102
……………………………………
```
If the range to be compared is within DS, the segment address does not need to be pointed out:
```
如:-C 0 4 100; Compare DS:0---DS:4 and DS:100---DS:104
```
Another format of the C command is as follows: `C address 1 L length address 2`
```
如:-C000:0 L4 0; Compare 0000:0 and DS:0, which is equal to the -C0000:0 3 0 command. The display result is as follows:
0000:0000 8A C0 08F1:0000
0000:0001 10 20 08F1:0001 它们都比较4个字节
0000:0002 1C 00 08F1:0002
0000:0003 49 7F 08F1:0003
```
##### Dump Command
- **`D` or `D` Dump command**
- **Function**: Display the information in memory in the form of memory mapping.
- **Description**: The dump displays the memory mapping content in two parts, the left part in hexadecimal and the right part in ASCII characters. All non-printable characters are represented by a period (.). Each line displays the content of 16 bytes, and there is a hyphen - between the eighth and ninth bytes. The implied segment address of this command is the value of DS. If the start address is not specified, the D command starts displaying from the next unit of the last displayed unit. If the D command has not been used before, it starts displaying from the content of the initialized segment register plus the address offset 0100H.
- **Example**: `-d10,4f` is to display the content of DS:4f. In the D command, if the segment address is not pointed out, it defaults to the DS segment.
- **Example**: If the segment address is specified, the specified range is listed from the specified segment address
```
如:-dfff:00:0f
```
- **Example**: We can also specify the length to list the required memory content
```
如:-d 100 L20 is to display the content from DS:100-DS:11F, a total of 20H bytes:
```
##### `E ` Modify Memory Command
- **Function**: Modify the memory value starting from the specified address.
- **Format**: `E start address `
- (1) Replace the unit content of the specified range with the given content
```
-E address content table
```
- **Example**:
```
-E100 41 42 43 44 48 47 46 45
-D 100,L08
08F1:0100 41 42 43 44 48 47 46 45 ABCDHGFE…
```
- (2) Modify memory content one by one
```
-E 100:
08F1:0100 76 42 :42 is typed by the operator
```
This command modifies the original memory content at address 100 from 76 to 42, which can be viewed using the D command.
##### `F ` Fill Command
- **Function**: Fill the bytes or byte string to be filled into the memory specified by the address range.
- **Example**:
```
-f100 120 61 62 63 64
-d100 11f
08F1:0100 61 62 63 64 61 62 63 64 -61 62 63 64 61 62 63 abcd abcd abcd abcd
08F1:0110 13 67 98 E3 C8 2E B3 B6 -03 21 AC 19 3121 4E 96 g……1…
```
If the data line exceeds the specified range, the unplaced values will be ignored.
- **Example**:
```
-f 100 107 41 43 43 44 45 46 47 48 49 4A 4B 4C 4D -d 100,lof
08F1:0100 41 42 43 44 45 46 47 64 -61 62 63 64 ABCDEFGdabcdabcd
```
It can be seen from the above example that the data beyond the range is ignored.
In addition, both the F and E commands can fill in strings:
```
如:-F 100 105 "MSDOS"
-d 100 l0f
08F1:0100 4D 53 44 4F 53 46 47 64 -61 62 63 64 MS DOS FGabcd abcd
```
##### G Execute Command
- **Function**: Execute the program being debugged. When reaching a breakpoint, stop executing and display the register flags and the next command to be executed.
- **Description**: If the start address is not specified, then the current instruction address is determined by the contents of the CS and IP registers. If the user specifies the start address, it starts executing from the specified start address. If a breakpoint is specified, it stops executing when the instruction reaches the instruction address, and displays the content of each register flag and the next command to be executed. Up to 10 breakpoints can be set by the user.
- **Example**:
```
A:\>debug tan.exe
-u: Disassemble into assembly language code
…………
. .
-g 100 指定中断点
Program terminated normally:
```
In addition: We can run a file.EXE under DEBUG
```
如:A:\>debug tan.exe
-g
即可开始运行此程序,和在DOS下完全一样:
```
##### H Hexadecimal Arithmetic Operation Command
- **Function**: Display the sum of two hexadecimal numbers added respectively and the difference of the first number minus the second number.
- **Description**: Complete simple hexadecimal number operations for the user.
- **Example**:
```
-h4538 5623
9B5B EF15
```
##### I Command
- **Function**: Input a byte from the specified port and display it (in hexadecimal).
- **Example**:
```
-i70
F9; Display the content of port 70 as F9
```
The I command can take data from 64K ports of 80X86.
##### L Command
- **Function**: Load a file or absolute sector of a disk into the memory.
- **Description**: The maximum number of sectors that a single L command can load is 80H. The disk numbers 0, 1, 2, 3…… respectively represent A, B, C,…… If a disk reading error occurs, an error message is displayed.
- (1) Format 1. `L load address drive name start sector/sector number`
- This method can load the content of the specified sector range on the disk into the area starting from the specified address in the memory. Here, the sector number is referenced in the logical/sector way.
- **Example**: `-L 100 0 01`, load sector 0 of drive A to CS:100
```
-d 100 10f
08F1:0100 EB 3C 90 3C 53 44 4F 53 -36 2E 32 32 02 01 01 00.L,MSDOS 6.22……
```
- (2) Format 2. `L load address`
- This method can load the specified file into the memory. The loaded file can be specified when entering DEBUG or can be established using the N command. The format is `-n file name:`
- **Example 1**: `DEBUG tan.pas`
```
-L 100
```
- **Example 2**: `DEBUG`
```
-n tan.pas
-L 100
```
- **Note**: The L command can only read logical sectors and cannot read the hard disk partition table.
- **Disk code used in the L command**: A=00, B=01, C=02……
##### M Data Command
- **Function**: Move the content of the memory unit in the address range to the specified address of the start address.
- **Description**: During the transfer, the source area and the target area can partially overlap; the data in the source area remains unchanged after the transfer.
- **Example**:
```
-e100 41 42 43 44 45
-d100 10f
08F1:0100 41 42 43 44 45 62 62 63 64 -61 62 63 64 61 62 63 ABCDEBCDABCDABCD
-M 100 104 110
-d110 L1F
08F1:0100 41 42 43 45 0A 21 19-20 01 01 20 07 96 87 9F ABCDE……
```
##### `N `
- **Function**: Define the operating file name.
- **Description**: Two operating files can be defined at the same time, and the formed file control block is set in the memory CS:5C and CS:6C respectively, for the subsequent operations of the L and W commands. When we are debugging a program, when starting DEBUG, we can add the file program name and its parameters or run the file after it. But when we debug for a period of time, we may load other files for testing. At this time, we can use the N command to set it without exiting DEBUG.
- **Example**:
```
A:\>DEBUG tan.exe
-n youg.pas
```
When the program has been debugged for a period of time, if you want to load tan.exe into tan1.pas, then `-ntanl.pas`
##### O Output Command
- **Function**: Send a byte to the specified output port.
- **Example**: When we encounter the requirement to enter a password when booting, we can use the following method to cancel
```
-O 70 10
_O 71 00
```
##### P Process Command
- **Function**: Stop at the next instruction for a subroutine call instruction, loop instruction, interrupt instruction, or a repeated string instruction.
- **Description**: When executing a subroutine call instruction, loop instruction, interrupt instruction, or a repeated string instruction, issue the P command to execute the relevant instruction and return to the next instruction to be executed. The P command and T are both selected as commands for tracking the program running process. We can specify the start address and the number of instructions of the program running in the P command. If not specified, it starts running one instruction at a time from the address of the program specified by CS:IP.
- **Difference between P and T commands**: The P command treats CALL/INT as one instruction to execute, simplifying the tracking process. The P command only runs the commands in RAM, while the T command can run the programs in both RAM and ROM.
##### R Register Command
- **Function**: 1. Display the content of a single register and provide a modification function. 2. Display the content of all registers, plus the status of the letter flags and the next instruction to be executed. 3. Display the status of 8 flag bits and provide a modification function. If you don't want to change, just press Enter.
- **Example**:
```
-r bx
bx 0050
:51
-r
AX=0000 BX=0051 CX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0003 ES=0CD3 SS=0CD3 IP=0100 NV UP EI PL NZ NA PO NC
0CD3:0100 0F DB OF
```
If you want to change the flag register, use `-RF` and press Enter, then DEBUG will display the flag content. If you want to change any flag, just input the name of the flag.
- **Flag names**:
- Overflow: OV (overflow), NV (no overflow)
- Direction: DN (decrease), UP (increase)
- Interrupt: EI (enable), DI (disable)
- Zero bit: ZR, NZ (not equal to zero)
- Auxiliary carry: AC, NA (no carry)
- Parity flag: PE (even), PO (odd)
- Sign: NG (negative), PL (positive)
- Carry: CY, NC (clear carry)
- **Example**:
```
-Rf
NV UP EI PL NZ NA PO NC :-OV DI← Input value
```
##### S Command
- **Function**: Find the given string in the specified address range.
- **Description**: Used to specify to find a string in the address range. If found, display its address; otherwise, directly display the DEBUG prompt. The implied address is the value of DS segment.
- **Example**:
```
-d100 lof
08F1:0100 OF 2A 41 43 0B 31 42 96 -FF F0 B9 8A F3 00 B1.. AC,1B...
-S 100 lof"AC"
08F1:0102← Indicates found, starting from 0102
```
##### T Trace Command
- **Function**: Track the execution of the program instruction by instruction. After each instruction is executed, the content of each register will be displayed.
- **Description**: Usually track one instruction, but the user can also use the number of instructions to set to track multiple instructions at a time. After each instruction is executed, the content of all registers and the flag status will be displayed.
- Track instruction by instruction `-T`
- Execute one instruction from the specified address and then stop. Display the content of all registers and the value of the flag bits. If no address is specified, execute from the current CS:IP.
```
A:\>DEBUG
-A
08F1:0100 MOV DL,03H
08F1:0102 MOV AH,02H
08F1:0104 INT 21H
08F1:0106 INT 20H
08F1:0108
-T
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=08F1 ES=08F1 SS=08F1 CS=08F1 1P=0105 NV UP EI PL NZ PO CY
09F1:0102 B402 MOV AH,02
```
- If the start address is specified, the T command will start tracking from the specified address. We can also specify the number of instructions to run at one time in the T command, and use Ctrl+S to pause the screen display for observation.
```
-t=100 10; Track 10 instructions starting from CS:100
```
##### U Address Command
- **Function**: Convert the content in memory into assembly statements.
- **Description**: The number of bytes disassembled depends on the system display form and the optional items used in the U command.
- (1) Compile and disassemble 32 bytes starting from the specified address
```
-U← Disassemble 32 bytes starting from CS:100
```
- If the address is omitted, it starts disassembling 32 bytes from the next unit of the last instruction of a U command.
- (2) Disassemble the specified storage range
```
-u start address end address(L length)
```
- **Example**:
```
-U 100 109
08F1:0100 CD20 INT 20
08F1:0102 FF9F009A CALL FA12
08F1:0106 F0 LOCK
08F1:0107 FE1D CALL FAR
08F1:0109 F0 LOCK
```
- **Description**: If the range is specified, the entire range will be disassembled.
##### W Write Disk Command
- **`W ` Write disk command**
- **Function**: Write the modified data to the disk.
- **Description**: The data starting from the specified memory address can be written on the disk. It can be written on the disk without specifying parameters or with the specified address parameter.
- **When running W, the size of the file needs to be set in the CX or BX register**
- (1) Write data to the specified sector of the disk
```
-W start address drive name start sector sector number
```
- (2) Write data to the specified file
```
-W start address
```
- **Example**:
```
A:\>DEBUG
-A
08f1:0100....
. 写入程序段
08F1: 012A....
-R CX
CX:0000
:2A← Number of bytes written, which is the end address of the program minus the start address
-n tan.com← Set file name, need to have the suffix com
-w
Wring 002A bytes
-q
A:\>TAN←即可执行此程序
```
- **"XD" command: Release EMS memory**
```
例:-XD 0001
handle 0001 deallocatel←释放了
利用XD释放后可再分配
```
- **"XM" command: Map the memory page area on the expanded memory to the main memory area**
```
格式:XM RAM 长页码 主内存页码句柄
例:-XM3 2 0001←把0001号句柄的第3号逻辑页区映射到2号真实页区
Logical page 03 mapped to physical page 02
```
- **"XS" command: Display the current EMS usage**
```
格式 -XS
```
#### Fold Edit Section: Practical Application
##### 1. Repair of non-physical track 0 bad floppy disks
Such damage does not have obvious scratches and mildew on the floppy disk surface. Generally, its data can be recovered, and the floppy disk can also be reused.
- **Processing method**:
- Ⅰ. Enter debug
- Ⅱ. Take a good disk with an undamaged boot area and insert it into the floppy drive
```
-l 100 0 0 1
```
- Ⅲ. Insert the damaged disk into the floppy drive
```
-w 100 0 0 1
-q
```
- **Note**: The capacities of the good disk and the bad disk must be the same.
##### 2. Reading data in a physical track 0 bad floppy disk
For a disk with track 0 damage, generally, it should be discarded. But you can also try the following methods:
- **Magnetization treatment**: Use a strong magnet to move back and forth near the surface of the bad disk. Do not touch the disk medium to avoid scratching the surface, and then try formatting.
- **Floppy disk turning**: Carefully open the disk, separate the magnetic sheet from the metal chip, turn the disk over, and then stick it together according to the original method, and then reformat.
- **diskfix**: I believe everyone uses diskfix more. The disk repair function in it is very useful. It can repair most disk surface errors.
##### 3. Hard disk boot failure handling
- **Format a floppy disk on a normal machine with no other data**
```
进入debug
-l 0 2 0 1
-w 0 0 0 1
-q
```
- **Boot the faulty machine with the system disk**
```
在进入debug
-l 0 0 0 1
-w 0 2 0 1
-q
```
##### 4. Solution to the problem that the floppy disk cannot be read correctly
If the following prompt appears when using the floppy disk
```
general failure error reading drive a
```
The following method can be used to solve it:
- **Insert a good disk into the floppy drive**
```
进入debug
-a 100
****:*100 mov al,0
****:**** mov cx,1
****:**** mov dx,0
****:**** mov bx,1000
****:**** int 25
****:**** int 20
回车
-g=0100
```
- **Insert the bad disk and enter debug**
```
-a 200
****:*100 mov al,1
****:**** mov cx,1
****:**** mov dx,0
****:**** mov bx,1000
****:**** int 26
****:**** int 20
回车
-g=200
```
##### 5. Saving and restoring CMOS data
The 'address port' of the cmosram has an address of 70h, and the 'data port' has an address of 71h. When reading, just send the address of the read cmosram to 70h, and then you can get the required data from 71h.
- **(1) Read CMOS data** Enter debug
```
-a 100
****:*100 mov bx,1000
****:**** mov cx,0040
****:**** mov ax,0000
****:0109 mov dx,cx
****:**** mov cx,0005
****:010e loop 010e
****:**** out 70,al
****:**** mov cx,0005
****:0115 loop 0115
****:**** in al,71
****:**** mov 【bx】,al
****:**** cmp ah,0e
****:**** jb 0123
****:**** add ah,80
****:0123 inc ah
****:**** inc bx
****:**** mov cx,dx
****:**** mov al,ah
****:**** loop 0109
****:**** mov ah,3c
****:**** mov dx,0150
****:**** mov cx,0020
****:**** int 21
****:**** mov bx,ax
****:**** mov dx,1000
****:**** mov cx,0040
****:**** mov ah,40
****:**** int 21
****:**** mov ah,4c
****:**** int 21
-a 150
****:0150 db "cmos.dat",0
****:0159
-r cx
cx 0000
:60
-n save cmos.com
-w
-q
-w 100 2 0 1
-q
```
- **(2) Restore CMOS data** Enter debug
```
-a 100
****:*100 mov cx,0150
****:**** mov ah,3d
****:**** mov al,00
****:**** int 21
****:**** mov dx,1000
****:**** mov bx,ax
****:**** mov cx,0040
****:**** mov ah,3f
****:**** int 21
****:**** mov ax,0000
****:**** mov bx,dx
****:**** mov dx,cx
****:**** mov cx,0005
****:**** loop 011f
****:**** mov al,ah
****:**** out 70,al
****:**** mov cx,0005
****:**** loop 0128
****:**** mov al,【bx】
****:**** out 71,al
****:**** jb 0136
****:**** add ah,80
****:**** inc ah
****:**** inc bx
****:**** mov cx,dx
****:**** loop 011a
****:**** mov ax,0040
****:**** mov ds,ax
****:**** mov ax,1234
****:**** mov 【0072】,ax
****:**** jmp ffff:0000
-a 150
****:0150 db "cmos.dat",0
****:0159
-r cx
cx 0000
:60
-n write cmos.com
-w
-q
```
##### 6. Saving and restoring DOS boot sector data
The DOS boot program is read into memory starting from 0000:7c00 for execution.
- **Obtain the normal boot program**
```
进入debug
-l 100 2 0 1
-n a:dosboot.com
-r cx
:200
-w
-q
```
- **Load the boot program**
```
进入debug
-n a:dosboot.com
-l
-r cx
:200
-w 100 2 0 1
-q
```
##### 7. Saving and restoring the hard disk master boot sector data
When the hard disk is working normally, read the main boot sector information
- **Note**: This data cannot be restored when the partition is changed.
- **Save the main boot sector data** Enter debug
```
-a 100
mov ax,0201
mov bx,0110
mov cx,0001
mov dx,0080
int 13
int 3
-g=100
-e 102 3
-e 10e c3
-r bx
bx 0110
:0
-r cx
cx 0001
:210
-n a:rboot.com
-w
-q
```
- **Restore the main boot sector data**: Just run rboot.com on drive A.
##### 8. Backup and restore of the non-allocation table of the hard disk
- **Backup the allocation table when the computer is running normally**
```
进入debug
-l 100 2 0 1
-n a:dbrup.dat
-r cx
:200
-w
```
- **Restore**
```
进入debug
-n a:dbrup.dat
-l
-w 100 2 0 1
-q
```
##### 9. Inside information of the hard disk protection card
For those who often use computers outside, once the computer maintenance personnel set the hard disk protection card, it is very troublesome to do some things by oneself. Do you want to shield the hard disk protection card? The following method may be useful:
```
进入debug
-a 100
mov ah,0
mov dl,0
int 13
-t
一直按t知道找到 cs=f000 记下此时 ds 的值 如:1234
-e e0:4c
34 12 00 f0
-q
```
##### 10. Use debug to perform low-level formatting of the hard disk
Low-level formatting of the hard disk is generally done with dm, but debug can also be used for low-level formatting of the hard disk.
```
进入debug
-a 100
mov ax,500
mov bx,180
mov cx,0
mov dx,80
int 13
int 3
-e 180 0 0 0 2
-q
```
##### 11. Cold boot and warm boot
Use debug to implement system cold boot and warm boot programs
- **Cold boot**:
```
-a 100
jmp ffff:0
int 20
-n a:reset.com
-r cx
:0007
-w
-q
```
- **Warm boot**:
```
-a 100
mov ax,0040
mov ds,ax
mov ax,1234
mov si,0072
mov (si),ax
jmp ffff:0
-n a:rset.com
-r cx
:0014
-w
-q
```
##### 12. Encryption of DOS internal commands
For example, encrypt dir
- **Find the command.com file under c: with pctools or diskedit**
```
pctools中:f-----f1 然后找所有03 44 49 52 找到后按f5修改成你所要的值 如:foo 以后只有输入foo 才能列出文件或文件目录。
```
- **diskfix has a good interface and is operated similarly to pctools**
- **Note**: If it cannot be modified, unlock the file. luck
- **Other command codes**
- type: 04 54 59 50
- cd: 02 43 44
- del: 03 44 45 44
- copy: 04 43 49 50 59
Last edited by zzz19760225 on 2017-11-13 at 14:06 ]
|