View and vote on the article here: Using the DEBUG tool in DOS
Using the DEBUG tool in DOS| Category | | | Summary | | The following is a brief introduction to DEBUG, a commonly used programmers tool. DEBUG is a programmer's tool to catch bugs and fix them. It has remained virtually the same as its form in DOS 1.0, except for few changes. You can even do more things with |
| | Body | 1.Type DEBUG at your command prompt, then type L 100 0 0 x
What it means is that to load(L) at memory location 100 from drive 0(Your A drive) from sector 0 through sector x.x must be replaced by number of sectors you wish to peek at.
Now to see the contents of the floppy loaded at memory location offset 100, type d 100. That is telling DEBUG to display the contents at offset 100.
Note: Remember all the values displayed by Debug on the left side are a pair of segment: offset addresses of memory, displayed in the middle are in Hex notation, and on the right side are ASCII notations.
Note: One byte is 8bits like FF in Hex and one word in two bytes or 16 bits and like FF FF in Hex so don't get confused.
2.If you want to write something to your disk, use 'W' for write. For example, w 100 0 0 x.
It means write (w) the contents from memory location 100 to 0(your A drive) at sector 0 to x.x must be replaced by the a valid sector number.
3.If you want to write a file to the disk use the n option. N stands for name. As an example: -n abc.exe or -n abc.123.Then use the load(l) command to load the contents of the file specified with n(name) option. By default, the contents of the file will be loaded at offset 100. After the contents have been loaded you can use the w(write) command for writing it to disks or memory.
4.Poking at your BIOS (Basic Input and Output System) is also easy with DEUBG. First you must get familiar with the D(Display) command because it is useful for many purposes, including reading files, memory locations, and disks.
->Checking the Serial and Parallel ports.
->The first 16 bytes of the BIOS data area contains the addresses of Serial and Parallel ports.
->The BIOS Data Area is loaded at memory location 40:0 H during the boot process. So you must look at 40:0 to view the addresses of the Serial and Parallel Ports.
->Type D 40:0 (and press Enter)
->Each line in DEBUG displays 16 bytes so it's enough that you see the first line in the middle section.
->If you have two COM ports than you will most probably see
F8 03 and F8 02 in the first four words.
->In order to know the address of your ports you must reverse them so F8 03 becomes 03F8(Your COM 1 port address) and F8 02 becomes 02F8(your COM 2 address)
->The reason to reverse the byte sequence is that interl stores the contents to memory in reverse order; so you will have to reverse to know what means.
->Though you may have more than two COM ports, the BIOS Data Area( 40:0) has information for only the first two ports.
->The next two words after the COM addresses or the addresses of LPT ports. It can display up to four LPT ports (LPT1 to LPT4). In case you don't know what LPT is, it means Line Printer Port. It is where you connect your printer.
->Till now you have only poked at RAM BIOS Data Area at 40:0 H but now you can even look at the ROM BIOS.
->The ROM BIOS will be higher up in the memory, usually after the 1 MB mark of the A20 gate.
->Checking Copyright Notice and Serial number.
->Type D FE00:0 (It doesn't matter if it is upper case or lower case because DOS isn't case sensitive.)
->You will be able to see on the right side, the Manufacturer name and serial number.
->If you want to see more then simply type D it will continue displaying the next bytes in the sequence.
->Checking the ROM BIOS date.
->Type D FFFF:5
->You will be able see the date in the right side.
5.Using DEBUG as a disassembler.
->Type n (name) command. For example: n abc.exe abc.123
->It is best to disassemble .COM programs or .SYS programs because .exe programs aren't supported by DEBUG. Try disassembling an .exe program and you will quickly understand why you can't do it. Follow these steps:
->n abc.com or abc.123
->u (Unassemble) this command will disassemble the program.
->After disassembling the program you can load it with
l(load),if you recall what i said in the beginning the l command load the contents by default at offset 100.
->So in order to see the contents loaded by l(load) command
->use D 100
6. A list of Commands supported by DEBUG:
(The commands are not case sensitive.)
Command Function Format
A Assemble a [address]
C Compare c [range address]
D Dump(Display) d [address length]
E Enter e [address value(s)]
F Fill f [range value(s)]
G Go g [=address]
H Hex arthimatic h [value value]
I Input I [port]
L Load(from memory/disk) l [address drive sector sector]
M Move m [range address]
N Name n [filename]
O Outport o [port value]
P Proceed p [address value]
Q Quit q
R Register Modify r [register]
S Search s [range value(s)]
T Trace executin t [=address value]
U Unassemble/Disassemble U [address]l[length]
W Write w [address drive sector sector]
XA EMS allocate xa[pages]
XD EMS deallocate xd[pages]
XM EMS status xs
An Example using a few of the above commands:
This example will let you see the time from DEBUG directly interfacing with the CMOS ports.
->From your command prompt, type DEBUG
->The CMOS takes values at port 70(hex), so in order to get the time we must first send a value to that port requesting the time.
->And after you send a value to the port 70(Hex) it keeps a value ready for you to take at port 71(hex).
O 70 4
I 71
O 70 2
I 71
O 70 0
I 71
->O stands for Out-port and I stands for In-port
->In the above code, first we sent a value to port 70(CMOS) requesting the hours. The value was placed at port 71(hex), so we took it from there and read it.
->The same thing continues, but this time the value 2 is for minutes and value 0 is for seconds.
If you are familiar with C, this is the same procedure that OS writers use for getting the time from the CMOS.
Here is some code I wrote in VC++ to get the time from your CMOS.
------------------Cute here---------and paste it in your compiler------
/*Copyright (C), Revanth 2002-2003
#include"stdio.h"
#include"conio.h"
typedef unsigned short int byte;
byte read_cmos(unsigned int reg);
byte read_cmos(unsigned int reg){
unsigned int high_digit,low_digit;
outp(0x70,reg);
high_digit=low_digit=inp(0x71);
/*Conver from BCD to binary*/
high_digit >>= 4;
high_digit &= 0x0F;
low_digit &= 0x0F;
return (10 * high_digit + low_digit);
}
int main(void){
byte sec=read_cmos(0);
byte min=read_cmos(2);
byte hour=read_cmos(4);
printf("The time is %2d:%2d:%2d",hour,min,sec);
getch();
return 0;
}
---------------------------code end-----------------------
There is a little catch in the program: the values returned by CMOS is in BCD(Binary coded decimal), so you will have to convert it into binary in order to get the correct time.
Hopefully you now have a better understanding of DEBUG. If you have any questions or comments, please send them to revanthn@unixhideout.com.
- Cyberr00t
|
|
This article was imported from zZine. (original author: cyber00t)
There are no replies to this post yet.
|