Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3 Examining Computer Memory and Executing Instructions.

Similar presentations


Presentation on theme: "Chapter 3 Examining Computer Memory and Executing Instructions."— Presentation transcript:

1 Chapter 3 Examining Computer Memory and Executing Instructions

2 DEBUG Commands: A Assemble symbolic instruction into machine code D Display the contents of an area of memory in hex form E Enter data into memory, beginning at a specific location G Run the executable program in memory ( G means “go”) H Perform hexadecimal arithmetic N Name a program P Proceed, or execute a set of related instructions Q Quit the DEBUG session R Display the contents of one or more registers in hex format T Trace the execution of one instruction U Un-assemble machine code into symbolic code

3 D DS:200 1380: – ……………. 1380: – ……………. 1380: – ……………. 1380: – ……………. 1380: – ……………. 1380: – ……………. 1380: – ……………. 1380: – ……………. ASCII representation Hex representation of the displayed area

4 Viewing Memory Locations
Exercise 1: Checking the serial and parallel ports at memory location 40:00 D 40:00 < Enter> 0040: F8 03 F8 02 E8 03 E8 02-BC C0 9F ……….x.x… ... Serial ports COM1,…,COM4 Parallel ports LPT1,…,LPT4 COM1 at 03F8 COM2 at 02F8

5 Checking System Equipment at Locations 410H-411H D 40:10 <Enter>
0040: … Binary value: Bit position: Bits Device 15, Number of parallel printer ports attached = 1 (binary 01) Number of serial ports attached = 2 7, Number of diskette devices = 1 (00=1, 01=2, 10=3, 11=4) 5, Initial video mode = 10 (01=40x25 color,10=80x25 color, 11=80x25 monochrome) = numeric coprocessor is present =diskette drive is present Others not used

6 Checking the Keyboard Shift Status at Location 417H
D 40:17 <Enter> 0040: … Checking the video status at location 449H D 40:49 <Enter> The first byte: current video mode (03 for color) The second byte: number of columns on the screen (50H = 80) you can find number of rows at location 40:84H

7 Exercise 2: Examining ROM BIOS
Checking copyright notice and serial number at location FE000H (7-digit serial number follows the copyright notice) D FE00:0 <Enter> Checking ROM BIOS date at location FFFF5H recorded as mm/dd/yy D FFFF:5 <Enter>

8 Machine Language Example 1: Using Immediate Data
Machine instruction symbolic code explanation B MOV AX, move value 0123H to AX ADD AX, add value 0025H to AX 8BD MOV BX,AX move contents of AX to BX 03D ADD BX,AX add contents of AX to BX 8BCB MOV CX,BX move contents of BX to CX 2BC SUB CX,AX subtract content of AX from CX 2BC SUB AX,AX subtract AX from AX (clear AX) EBEE JMP go back to the start

9 Keying in Program Instructions:
E CS:100 B <enter> E CS:106 8B D8 03 D8 8B CB <enter> E CS:10C 2B C8 2B C0 EB EE <enter> Executing Program Instructions: -R: view the initial contents of the registers and flags AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0100 NV UP EI PL NZ NA PO NC 21C1:0100 B MOV AX,0123 -T AX=0123 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0103 NV UP EI PL NZ NA PO NC 21C1: ADD AX,0025

10 -T AX=0148 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0106 NV UP EI PL NZ NA PE NC 21C1:0106 8BD MOV BX,AX AX=0148 BX=0148 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0108 NV UP EI PL NZ NA PE NC 21C1: D ADD BX,AX AX=0148 BX=0290 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=010A NV UP EI PL NZ AC PE NC 21C1:010A 8BCB MOV CX,BX

11 -T AX=0148 BX=0290 CX=0290 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=010C NV UP EI PL NZ AC PE NC 21C1:010C 2BC SUB CX,AX AX=0148 BX=0290 CX=0148 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=010E NV UP EI PL NZ AC PE NC 21C1:010E 2BC SUB AX,AX AX=0000 BX=0290 CX=0148 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0110 NV UP EI PL ZR NA PE NC 21C1:0110 EBEE JMP Displaying memory contents: view the machine language program in the code segment D CS:100

12 Machine Language Example 2: Using Defined Data
DS offset Hex contents 0200H H 0202H H 0204H H 0206H A2A2AH Instruction Explanation A move the word at DS:0200H into AX add the contents of the word at DS:0202H into AX A move the contents of AX to the word at DS:0204H EBF jump to the start of program

13 Keying in Program Instructions and Data
E CS:100 A <enter> E CS:107 A EB F4 <enter> E DS: <enter> E DS:0206 2A 2A 2A <enter> ASCII code for * Executing the Program Instructions -R: view the initial contents of the registers and flags AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0100 NV UP EI PL NZ NA PO NC 21C1:0100 A MOV AX,[0200] DS:0200=0123

14 -T AX=0123 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0103 NV UP EI PL NZ NA PO NC 21C1: ADD AX,[0202] DS:0202=0025 AX=0148 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0107 NV UP EI PL NZ NA PE NC 21C1:0107 A MOV [0204],AX DS:0204=0000 DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=010A NV UP EI PL NZ NA PE NC 21C1:010A EBF JMP D DS:0200, 0208 21C1: A 2A - 2A

15 Reset offset value in the IP register
1. Key in R IP to display the contents of IP, and 2. Type in the value 100 ( or address of another instruction), <enter>

16 An Assembly Language Program
A 100 <enter> xxxx: MOV CL,42 xxxx: MOV DL,2A xxxx: ADD CL,DL xxxx: JMP 100 xxxx: <enter> U 100, 107 <enter> xxxx: B142 MOV CL,42 xxxx: B22A MOV DL,2A xxxx: D1 ADD CL,DL xxxx: EBF8 JMP 100 xxxx:0108 Type R to display registers , and T to trace instructions. When you get to JMP, you will find IP=106H, CL=6CH

17 Using the INT Instructions
1. Getting the Current Date, INT 21H, function code 2AH A 100<enter> MOV AH, 2A <enter> INT <enter> JMP <enter>, <enter> Type R to display the registers T to execute the MOV P to proceed(進行) directly through the interrupt routine The operation stop at the JMP The registers contain this information in hex format: AL: Day of the week, where 0 = Sunday CX: Year ( for example, 07D4H = 2004) DH: Month (01H through 0CH) DL: Day of the month (01H through 1FH)

18 2. Getting the Current time: INT 21H, function code 2CH
First use R IP to reset IP to 100 and then key in A 100, and MOV AH, 2C ,<enter> INT <enter> JMP <enter>, <enter> The operation delivers hours to CH (00 = midnight) minutes to CL, seconds to DH hundredths of second to DL

19 3. Determining Installed Equipment: INT 11H
Type in A 100, then INT 11 JMP 100<enter>, <enter> Press R to display the registers and T to trace repeatedly to see the BIOS instruction execute. JMP EE ; PUSH DS ;save DS address in stack MOV AX, ;get segment address MOV DS, AX ;move it to DS MOV AX,[0010] ;get data from 40:10 into AX POP DS ;restore address in DS IRET ;return from interrupt The last T command exits from BIOS and returns to DEBUG. AX now contains the record of installed equipment.

20 4. Using INT for Displaying: INT 21H, function code 09H
Type A 100, then 100 MOV AH,09 102 MOV DX,109 105 INT 21 107 JMP 100 109 DB ‘your name’, ‘$’ <enter>, <enter> Define byte dollar sign tell INT 21 to end the display.

21 5. Using INT for Keyboard Input: INT 16H, function code 10H
Type A 100, then 100 MOV AH, 10 102 INT 16 104 JMP 100 <enter>, <enter> When you type in P for INT 16H, the system waits for you to press a key. If you press the number 1, you’ll see the operation delivers 31H (hex for ASCII 1) to AL

22 Using the PTR Operator to indicate number of bytes 顯示
100 MOV AX,[11A] ;move contents at memory location 11AH-11BH to AX 103 ADD AX,[11C] ;add contents of memory location 11CH-11DH to AX 107 ADD AX, ;add immediate value 25H to AX 10A MOV [11E],AX ;move contents of AX to memory locations 11EH-11FH 10D MOV WORD PTR [120], 25 ;move a word of value 25H to 120H-121H 113 MOV BYTE PTR [122], 30 ;move a byte of value 30H to location 122H 118 JMP 100 11A DB ;define values 14H and 23H. DB: define byte 11C DB 05 00 11E DB 00 00 120 DB D 110 to view the changed contents of AX (233E) location 11EH-11FH (3E23) 120H-121H (2500) 122H (30)

23 Exercises: 3.4 (a) Use debug to enter the following: E CS:100 B (b) Use E command to change 45 to 54 3.10 Use debug’s A command (A 100) to enter the following instructions: MOV DX, 2E ADD DX, 1F SHL DX, 1 SUB DX, BA JMP 100 Un-assemble the instructions and trace their execution. Check the value in DX. 3.12 Use debug to create and run a program to display the sentence “Coffee Break.” Start with A 100 for entering the instructions and use A 120 for the sentence ( remember the $ delimiter)


Download ppt "Chapter 3 Examining Computer Memory and Executing Instructions."

Similar presentations


Ads by Google