Transcript Document
Assembly Language
Programming
Part 3
• Windows Debugger
Debug Subcommands
Writing and Executing Assembly
Code Using Debugger
a <Assemble>
Assembles 8086/8087/8088 mnemonics directly into memory. Used without parameters, a starts assembling
where it last stopped.
Syntax
a [address]
Parameters
Address
Specifies the location where you type assemblylanguage mnemonics. Use hexadecimal values for
address and type each value without the trailing h
character.
Examples
- a CS:100
- a 100
d <Dump>
Displays the contents of a range of memory addresses. Used without parameters, d displays the contents of
128 bytes, starting at the end of the address range specified in the previous d subcommand.
Syntax
d [range]
Parameters
range
Specifies the starting and ending addresses, or the
starting address and length, of the memory area
whose contents you want to display.
Examples
- d CS:100 10C
- d DS:100 L12
- d 100 10C
- d 100 L12
e <Enter>
Enters data into memory at the address you specify.
Syntax
e address [list]
Parameters
address
Required. Specifies the first memory location where
you want to enter data.
list
Specifies the data you want to enter into successive
bytes of memory.
Examples
- e DS:200 5
- e DS:200 5 6 7
- e DS:200 2,1,4,7
- e 100 “Ahmed”
- e 102 ‘r’
f <Fill>
Fills addresses in the specified memory area with values you specify.
Syntax
f range list
Parameters
range
Required. Specifies the starting and ending
addresses, or the starting address and length, of the
memory area you want to fill.
list
Required. Specifies the data you want to enter.
Examples
- f DS:100 103 1 2 3 4
- f 100 L6 1 2 3 4
- f 100 110 66
- f 100 L100 “HI”
g <Go>
Runs the program currently in memory. Used without parameters, g starts running at the current address in the CS:IP
registers.
Syntax
Parameters
g [=address] [breakpoints]
address
Specifies the address in the program
currently in memory where you want to
begin running the program.
breakpoints
Specifies 1 to 10 temporary breakpoints
that you can set as part of the g
subcommand.
Examples
- g = CS:100 10f
h <Hexadecimal>
Performs hexadecimal arithmetic on two parameters that you specify.
Syntax
h value1 value2
Parameters
value1
Required. Represents any hexadecimal
number in the range 0 through FFFFh.
value2
Required. Represents a second
hexadecimal number in the range 0
through FFFFh.
Examples
- h 19f 10a
q <Quit>
Stops the Debug.exe session, without saving the file currently being tested, and returns to the command prompt.
Syntax
Parameters
Examples
q
-
q
r <Register>
Displays or alters the contents of one or more CPU registers. Used without parameters, the r command
displays the contents of all registers and flags in the register storage area, the status of all flags, and the
decoded form of the instruction at the current location.
Syntax
r [Register]
Parameters
Register
Specifies the name of the register
containing the information you want to
display.
Flag name
Examples
- r AX
- r CS
- r DS
-rf
Set
Clear
Overflow
ov
nv
Direction
dn (decrement)
up (increment)
Interrupt
ei (enabled)
di (disabled)
Sign
ng (negative)
pl (positive)
Zero
zr
nz
Auxiliary Carry
ac
na
Parity
pe (even)
po (odd)
Carry
cy
nc
t <Trace>
Executes one instruction and displays the contents of all registers, the status of all flags, and the decoded form of the
instruction that is executed. Used without parameters, t begins tracing at the address specified by your program's CS:IP
registers.
Syntax
Parameters
t [=address] [number]
address
Specifies the address at which
Debug.exe is to start tracing instructions.
number
Specifies the number of instructions to
be traced. This value must be a
hexadecimal number. The default value
is 1.
Examples
- t = CS:100 4
- t = 200 5
u <Unassemble>
Disassembles bytes and displays their corresponding source statements, including addresses and byte
values. The disassembled code looks like a listing for an assembled file. Used without parameters, u
disassembles 20h bytes (the default number), beginning at the first address after the address displayed by
the previous u subcommand.
Syntax
Parameters
u [range]
range
Specifies the starting and ending
addresses, or the starting address and
length, of the code you want to
disassemble.
Examples
- u CS:100 CS:110
- u CS:200 20f
- u 100 10a
Notes
•
CS is the default segment for the following debug
subcommands: a, g, l, t, u and w.
•
DS is the default segment for all subcommands.
•
All numeric values are in hexadecimal format.
•
You must include a colon between the segment name and the
offset value.
Example:
The following are valid addresses:
CS:0100
04BA:0100
How to use Debug
How to use Debug
Type cmd (command Line)
How to use Debug
This Local path changes from one
computer to another
How to use Debug
Write debug then hit enter
This prompt indicates that debug is ready to accept commands,
always remember that no assembly instructions are accepted
when this prompt is shown up
How to use Debug
Debug command a <assemble> followed by offset 100 (CS:0100)
0100 is the chosen offset number (specified by the programmer as part
of a command), it indicates where your assembly instructions resides
within the code segment in main memory
0AE2 is the Code Segment Number which is stored in register CS
How to use Debug
Simple program that uses the
instruction MOV to set register AL to 1
and Register AH to 2
Notice that, to exit instruction entering mode don’t type
any thing and hit enter, you should see the dash prompt
again which indicates that you can type debug instructions
How to use Debug
To run your program you should use g <go> command, without
it, your code will remain in memory, but nothing would actually
happen (Register AL and AH would keep their old values).
After executing your program, a list of registers and the values they are
holding are displayed. Our program only deals with two registers AL and AH.
AL and AH together forms the register AX. From the register list AX = 0201
(the first two bytes represents AH and the second two bytes represents AL).
How to use Debug
Segment Registers DS <Data Segment>, ES <Extra Segment>, SS<Stack
Segment>, and CS <Code Segment> are all set to one segment 0AE2
(normally they point to different segments but for simplicity debug use one
segment for all of them) which means that you should be careful not to
overlap your code with any existing data that is present in that segment.
How to use Debug
IP <Instruction Pointer> a special purpose
register that holds part of the logical
address (offset) of the instruction to be
executed (the full logical address is IP:CS).
How to use Debug
These are some of the individual bit values that
resides within the FLAGS register. They reflect some
event that my occur while the execution of your
program like arithmetic overflow and division by zero
How to use Debug
These are some of the individual bit values that
resides within the FLAGS register. They reflect some
event that my occur while the execution of your
program like arithmetic overflow and division by zero
How to use Debug
Debug command u <unassemble>,
which displays the machine code (in
hexadecimal) corresponding to the
assembly instructions in the memory
range you specify.
B001 is the machine code (in hex)
corresponding to the assembly instruction
mov al,01.
In the same way B402 corresponds to
mov ah,2
How to use Debug
mov al,2 is typed instead of mov ah,2
How to use Debug
To correct this line after it is already been written to memory, simply
type nothing and hit enter. Now next to the dash prompt type a 102
(CS:0102 is the address of the instruction to be replaced ). Now you
can run your program and every thing will work fine.
How to use Debug
Debug command r <register> display a list of
known registers and their current values.
Default value for IP <Instruction Pointer>
is 0100. All offsets from 0000 to 00FF are
reserved by the operating system.
When command r is followed by register e.g. r AX the value within
this specific register is displayed then a colon “:”prompt is displayed
which allow you to change the value within the register, if left blank
no change is applied to the register
How to use Debug
8-bit registers are not accessed via debug command r. You must use
assembly instructions in order to change the value within them
How to use Debug
Letters
String
Numbers (in hex)
Debug command e <enter> which is used to enter data into
specific memory address (in this example DS:0200)
How to use Debug
String (hex ASCII code)
Letters (hex ASCII code)
Numbers (in hex)
Since numbers 1,2,A, and E
are not representing ASCII
code of a character, a dot is
displayed.
Debug command d <dump> which is used to dump the
content of specific memory address range (in this example
DS:0200 DS:020a)
How to use Debug
Debug command f <fill>
which is used to enter a
pattern of data into specific
range of memory address
(e.g. DS:0100 DS:0104
and the pattern is “1,2”)