Debug Tool and Usage of software Interrupt
Debug Tool and Usage of software Interrupt
This lab will give you practical understanding of machine architecture (Von-Neumann and IA- 32) with the help of DEBUG program. You will also learn how programs are run via Fetch- Decode-Execute cycle in Step by Step Mode. You will also understand the differences of little- endian and big-endian formats as well as how data is stored in main memory, registers, and stack and how to view, edit the data at runtime of programs. t is implementation of conversions and arithmetic on unsigned and signed integers and real numbers among different radices of decimal, binary, and hexadecimals using programs in JAVA.
This lab teaches you the following topics:
- What is Von-Neumann architecture?
- IA-16 and IA-32 architecture from programmer’s
- How Fetch-Decode-Execute cycle works?
- Differences between Little-Endian and Big-Endian
- Viewing and editing contents of registers and main memory at run
As pre-lab activity, read web material via goggling on Introduction to Debug and also as given by your theory instructor.
Normally, there is no way to see the source code of a program while the program is running. This inability to “see under the covers” while the program is executing is a real handicap when you are debugging a program. The most primitive way of looking under the covers is to insert (depending on your programming language) print or display, or exhibit, or echo statements into your code, to display information about what is happening. But finding the location of a problem this way can be a slow, painful process. This is where a debugger comes in.
A debugger is a piece of software that enables you to run your program in debugging mode rather than in normal mode. Running a program in debugging mode allows you to look under the covers while your program is running. Specifically, a debugger enables you (1) to see the source code of each statement in your program as that statement executes, (2) to suspend or pause execution of the program at places of your choosing, (3) while the program is paused, to issue various commands in order to examine and change the internal state of the program, and (4) to resume (or continue) execution.
Debuggers come in two flavors (1) console-mode (or simply console) debuggers and
- visual or graphical debuggers. Console debuggers are often a part of the language itself, or included in the language’s standard libraries. The user interface to a console debugger is the keyboard and a console-mode window (Microsoft Windows users know this as a “DOS console”). When a program is executing under a console debugger, the lines of source code stream past the console window as they are executed. A typical debugger has many ways to specify the exact places in the program where you want execution to pause. When the debugger pauses, it displays a special debugger prompt that indicates that the debugger is waiting for keyboard input. The user types in commands that tell the debugger what to do next. Typical commands would be to display the value of certain program variables, or to continue execution of the program.
Typing various commands.
Type the following commands and see the behavior along with understanding of register dumps. Debug, Q, R, A, T, G.
- Debug (enter the program)
- Q (Quit from program)
- R (To see contents of all registers)
- R <register> (To see specific register contents + option to change its value).
see the contents of AX register and try changing its values to 1, 21, 321, 4321, 54321,GF
Try to see value of AL (AX=AH+AL)
- A (Assemble command)
To enter assembly language instructions into memory A <starting address>
starting address is offset into Code Segment or you can specify Segment register.
Note: A 100 OR A CS: 100 are same
now type A 100 and Debug will prompt you to type assembly language program. Type these instructions (pressing CR at end of each)
mov ax,1 mov bx,2 mov cx,3 add ax,bx add ax,cx INT 3
<CR> (Without typing an instruction)
Note: Debug assumes all numbers are in hex while most assemblers do not.
Also as you type instructions, Debug converts them to machine code
Also do not assemble beginning at address lower than 100(first 256 bytes reserved for DOS and your program should not overwrite this area)
- U Command (un-assemble command)
To see machine code of your program. It takes machine code stored in memory and converts it back to assembly language.
U <starting address><ending address> or U <starting address><L no of bytes>
U 100 10D or
U 100 LD (D bytes from start)
- G (Go command)
To execute instructions until breakpoint is reached.
AT end register contents are displayed again and prompt is displayed. G
G =100 109
now check the value of IP register, change it back to 100 and then use
G 109 (start address is not given so assume what is in IP,109 is ending address here)
Example shows how to understand the registers dumps and trace the program execution.
- Using R
First Line: General purpose registers, Index and pointer registers Second Line: Segment registers, IP’s value and FLAGS
Third Line: Location, Machine Code and Assembly Code of next instruction to be executed.
- Trace the program execution
T <=starting address><no of instructions> Default starting=CS:IP
Default no of instructions=1
Trace will display register contents after each instruction. T=100 5 (on your program) or
T 5 (keep in mind default for 1st fields)
Note that IP change value and points to next instructions address.
3rd line of registers show the Instruction and its machine code (which will be executed next)
Also notice how registers are changing values after each instruction esp AX register.
Try to write this program starting at 100 hex address
mov AL, FF3 mov AX, 23451
mov DS, 1200 mov SI, DH mov AX,BH mov AL,BX
<CR> Q <CR>
The example helps you understand unassembled command and physical address calculation.
- Write a program staring at offset 100 as shown below A 100
MOV AL,57 MOV DH,86 MOV DL, 72 MOV CX,DX MOV BH,AL MOV BL,9F MOV AH,20 ADD AX,DX ADD CX,BX ADD AX, 1F35
U 100 112 (Un-assemble)
- Physical Address calculation
Note that program is starting at CS:IP (CS:0100).It is called logical address but remember address bus in 8088 is 20 bit. Physical address will be calculated as
Let CS=1235 IP=0100
In Hardware, 4-bit left shift of CS and then add IP
Here it is demonstrated how to Examine and alter the memory contents and write dynamic programs that will change variable value every time the program is run.
(i) Memory Dump commands F (Fill command)
E (Enter command) D (Dump command)
D to see memory contents and F used to fill data in memory, used as F <starting address><ending address><data> or
F <Starting address><L no of bytes><data>
Note: D (to see memory contents) syntax is also same
usually used to fill data segment (default offset in) with some initial values (zero say)
To fill another segment, mention segment with offset.
F 100 10F FF (Filling 16 bytes with FF)
F CS:100 1FF 20 (Filling 256 bytes/block of code segment with space) F 100 L20 00 FF (Filling 20 hex (32) bytes alternately with 00 and FF)
Debug<cr> F 100 14F 20
F 150 19F 00 (number after 14F is 150 ) D 100 19F
F 104 10A FF D 104 10A
D 100 10F
F CS:100 12F 20 D CS:100 12F
Now un-assemble your previous program and dump the memory and note how machine code bytes are stored in consecutive memory areas.
U 100 122
D CS:100 11F
Note: if byte value is not ASCII code, a dot (.) will be displayed. E (to enter/alter any data values into memory portion)
F can fill same data while E is free Syntax
E <address><data list> or E <address>
E 100 ‘AKBAR SALEEM’ D 100:10F
E 100 23 B5 03 4F (To enter numeric data) To alter Data
E 106 (WILL show value at address 106, change it to other byte simply typing, you can press <CR> or <space>-you can go through each byte at a time by hitting space after each byte display or <-> instead of typing any value…see what each one shows)
Try change AKBAR’S first A with E
Now write a program whose data will be entered later on via E command as shown below
mov AL, 00
add AL, 
add AL, 
add AL, 
add AL, 
add AL, 
-E DS:0200 23 12 14 1F 2C
-D 0200 020F
-G 100 116
Here you will learn how Little-endian Format of Data storage differs from Big Endian Format and how stack shrinks and expands in memory
Low byte in register to Low byte address in memory, High byte in register to High byte address in memory
- Move the value at location 6830 into BX register (note two values will be moved one at location 6830 and other at 6831 as BX is 16-bit)
- First Dump the 10 bytes from 6825 (D 6825 LA) and note the value at 6830 and
- Assemble a program at 100 (A 100).
- mov BX,  INT 3 <CR>.
- Trace the program and check how value is stored in BX (Little Endean).
- How stacks grow and shrinks in
SP is attack pointer that points to start of the stack but start here is higher address in memory. So SP will be decremented each time when value will be pushed. Stack will grow toward lower memory address.
For POP operation, phenomena are reverse.
mov AX, 24BF mov DI, 85C0 mov DX, 5F90 mov SP, 1230 push AX
push DI push DX int 3
-F 1225 1240 00 (Stack memory filled with all 00)
-D 1225 LF (Check)
-G =100 (Run program and see values of stack pointer)
-D 1225 1240 (CHECK STACK ISPUSHED OR NOT?)
Perform the following activities at your home PC.
- Create a DEBUG script file using any available editor or word processing software, for example, DOS Edit. Enter the lines below and save the file as “COVER.SCR” in the C:\SCRATCH subdirectory. If such a subdirectory does not exist, create it by issuing the command: “MD SCRATCH”, then set the default path to it using the command: “CD C:\SCRATCH”. You do not have to enter the comments. When executed, this program waits for a keystroke and then fills the screen with that
MOV BH,0 ;SET PAGE NO. FOR INT 10
MOV DX,0 ;ROW AND COL FOR VIDEO DISPLAY OF INT 10 MOV AH,2 ;DESIGNATE SERVICE 2 OF INT 10
INT 10 ;SET CURSOR TO 0,0 (TOP LEFT CORNER) MOV AH,8 ;DESIGNATE SERVICE 8 OF INT 21
INT 21 ;KEYBD INPUT W/O ECHO, PLACE IN AL
MOV CX,7D0 ;LOAD NUM CHAR=2000D TO CX FOR WRITING ,INT 10 MOV AH,A ;SERVICE A OF INT 10
INT 10 ;WRITE CHARACTER IN REG. AL CX TIMES JMP 105 ;RETURN AND REPEAT- INFINITE LOOP
<blank line> <—– insert a blank line in the file
R CX 16
N C:\SCRATCH\COVER.COM W
<enter> <—– press the “Enter” key
- To create the executable DEBUG program, COM, enter “DEBUG
<C:\SCRATCH\COVER.SCR” at the DOS prompt. At this point, the assembled code has been stored as COVER.COM in the C:\SCRATCH subdirectory. To see the assembly code, invoke DEBUG and use the N, L, and U commands in sequence (N COVER.COM, L, U). Try entering “U 100” and then “U 101” or “U 102”. See anything different?
- To execute the program in DEBUG issue the command: G=100, or at the DOS prompt in the C:\SCRATCH subdirectory, enter: “COVER”. To terminate the program in DEBUG or DOS, enter: Ctrl-C. Follow the comments and study the role of the registers in accomplishing the desired result. What happens if you change “MOV CX,7D0” to “MOV CX,3E8”? You can do this by changing just this one line of code in DEBUG:
- -a cs:xxxx<enter>
-cs:xxxx MOV CX,3E8 where xxxx is the offset of that line of code
- Using DEBUG, display the memory locations listed below, which describe the computer’s configuration and help execute commands.
0:417h-418h These two locations describe the status of special keys, such as shift, and control
7 in the class Codes”).
Note the effect of the various key presses (see fig. 6-6, and 6-
packet, the section titled: “More about Keyboards and Scan
0:41Ah points to the keyboard buffer head location 0:41Ch points to the keyboard buffer tail location
0:41Eh-43Ch keyboard buffer: space for 15 key strokes beginning with
41Eh. Note the
ASCII and scan codes in the buffer and relate them to
0:449h video mode
0:44Ch-44Dh amount of display memory in bytes (remember “backwards” convention)
To see the operation of the keyboard buffer, in DEBUG issue the command: “d 0:41a” several times to fill the buffer with copies of this command. Using the ASCII display portion of DEBUG, identify the ASCII and scan codes for “d 0:41a” in the keyboard buffer. Remember key codes are stored in the buffer from low to high memory locations.
- To observe the effect of changing character attributes, use the DEBUG “Enter” command
(E) to enter values directly into video RAM. You must first determine the appropriate addresses to use in video RAM. The starting address of video RAM depends on the video mode (check location 0:449 for video mode, which will be a text mode). Consult Fig. 4- 10 in the class packet, the section titled: “More about Video Modes” for the starting segment address for the indicated mode. The offset address depends upon where you wish to place the characters on the screen.
In text mode, the complete screen contents are contained in memory between offset 0000h and 0F9Fh (0000d to 3999d). Pick a RAM location that maps to a row that you can easily see. A good screen location is in the last row, third column. Calculate the character memory offset value from the formula: CO = ROW*A0 + COL*2. Remember rows are numbered (in hex) 0,1,…,18, and columns 0,1,2,…,4F. Using DEBUG, enter the desired ASCII and attribute bytes.