Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assembly Language Programming Part 3

Similar presentations


Presentation on theme: "Assembly Language Programming Part 3"— Presentation transcript:

1 Assembly Language Programming Part 3
Windows Debugger Debug Subcommands Writing and Executing Assembly Code Using Debugger

2 a <Assemble> d <Dump>
Assembles 8086/8087/8088 mnemonics directly into memory. Used without parameters, a starts assembling where it last stopped. Syntax Parameters Examples a [address] Address Specifies the location where you type assembly-language mnemonics. Use hexadecimal values for address and type each value without the trailing h character. - 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. d [range] range Specifies the starting and ending addresses, or the starting address and length, of the memory area whose contents you want to display. - d CS:100 10C - d DS:100 L12 - d C - d 100 L12

3 e <Enter> f <Fill>
Enters data into memory at the address you specify. Syntax Parameters Examples e address [list] 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. - e DS:200 5 - e DS: - 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. f range list range Required. Specifies the starting and ending addresses, or the starting address and length, of the memory area you want to fill. Required. Specifies the data you want to enter. - f DS: - f 100 L - f - f 100 L100 “HI”

4 g [=address] [breakpoints]
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 Examples 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. - g = CS:100 10f h <Hexadecimal> Performs hexadecimal arithmetic on two parameters that you specify. h value1 value2 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. - h 19f 10a

5 q <Quit> r <Register> Syntax Parameters Examples
Stops the Debug.exe session, without saving the file currently being tested, and returns to the command prompt. Syntax Parameters Examples 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 Parameters Examples r [Register] Register Specifies the name of the register containing the information you want to display. - r AX - r CS - r DS - r f Flag name 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

6 t <Trace> u <Unassemble> Syntax Parameters Examples
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 Examples 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. - 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. u [range] range Specifies the starting and ending addresses, or the starting address and length, of the code you want to disassemble. - u CS:100 CS:110 - u CS:200 20f - u a

7 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

8 How to use Debug

9 Type cmd (command Line)
How to use Debug Type cmd (command Line)

10 How to use Debug This Local path changes from one computer to another

11 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

12 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

13 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

14 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).

15 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.

16 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).

17 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

18 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

19 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

20 How to use Debug mov al,2 is typed instead of mov ah,2

21 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.

22 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 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

23 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

24 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)

25 How to use Debug String (hex ASCII code)
Since numbers 1,2,A, and E are not representing ASCII code of a character, a dot is displayed. Letters (hex ASCII code) Numbers (in hex) Debug command d <dump> which is used to dump the content of specific memory address range (in this example DS:0200  DS:020a)

26 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”)


Download ppt "Assembly Language Programming Part 3"

Similar presentations


Ads by Google