23
Chapter 3 Examining Computer Memory and Executing Instruction

Chapter 3 Examining Computer Memory and Executing Instructions

Embed Size (px)

Citation preview

Page 1: Chapter 3 Examining Computer Memory and Executing Instructions

Chapter 3

Examining Computer Memory and Executing Instructions

Page 2: Chapter 3 Examining Computer Memory and Executing Instructions

DEBUG Commands:

A Assemble symbolic instruction into machine codeD Display the contents of an area of memory in hex formE Enter data into memory, beginning at a specific locationG Run the executable program in memory ( G means “go”)H Perform hexadecimal arithmeticN Name a programP Proceed, or execute a set of related instructionsQ Quit the DEBUG sessionR Display the contents of one or more registers in hex formatT Trace the execution of one instructionU Un-assemble machine code into symbolic code

Page 3: Chapter 3 Examining Computer Memory and Executing Instructions

D DS:200

1380:0200 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00 00 00 …………….1380:0210 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00 00 00 …………….1380:0220 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00 00 00 …………….1380:0230 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00 00 00 …………….1380:0240 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00 00 00 …………….1380:0250 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00 00 00 …………….1380:0260 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00 00 00 …………….1380:0270 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00 00 00 …………….

Hex representation of the displayed areaASCII representation

Page 4: Chapter 3 Examining Computer Memory and Executing Instructions

Viewing Memory Locations

Exercise 1:

Checking the serial and parallel ports at memory location 40:00

D 40:00 < Enter>

0040:0000 F8 03 F8 02 E8 03 E8 02-BC 03 78 03 78 02 C0 9F ……….x.x…...

Serial ports COM1,…,COM4 Parallel ports LPT1,…,LPT4

COM1 at 03F8COM2 at 02F8

Page 5: Chapter 3 Examining Computer Memory and Executing Instructions

Checking System Equipment at Locations 410H-411H

D 40:10 <Enter>

0040:0010 23 44…

Binary value: 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 1 Bit position: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Bits Device15, 14 Number of parallel printer ports attached = 1 (binary 01)11-9 Number of serial ports attached = 27,6 Number of diskette devices = 1 (00=1, 01=2, 10=3, 11=4)5,4 Initial video mode = 10 (01=40x25 color,10=80x25 color, 11=80x25 monochrome)1 1 = numeric coprocessor is present0 1=diskette drive is presentOthers not used

Page 6: Chapter 3 Examining Computer Memory and Executing Instructions

Checking the Keyboard Shift Status at Location 417H

D 40:17 <Enter>

0040:0017 00 00…

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

Page 7: Chapter 3 Examining Computer Memory and Executing Instructions

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>

Page 8: Chapter 3 Examining Computer Memory and Executing Instructions

Machine Language Example 1: Using Immediate Data

Machine instruction symbolic code explanationB82301 MOV AX,0123 move value 0123H to AX052500 ADD AX,0025 add value 0025H to AX8BD8 MOV BX,AX move contents of AX to BX03D8 ADD BX,AX add contents of AX to BX8BCB MOV CX,BX move contents of BX to CX2BC8 SUB CX,AX subtract content of AX from CX2BC0 SUB AX,AX subtract AX from AX (clear AX)EBEE JMP 100 go back to the start

Page 9: Chapter 3 Examining Computer Memory and Executing Instructions

Keying in Program Instructions:

E CS:100 B8 23 01 05 25 00 <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=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0100 NV UP EI PL NZ NA PO NC21C1:0100 B82301 MOV AX,0123

-TAX=0123 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0103 NV UP EI PL NZ NA PO NC21C1:0103 052500 ADD AX,0025

Page 10: Chapter 3 Examining Computer Memory and Executing Instructions

-TAX=0148 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0106 NV UP EI PL NZ NA PE NC21C1:0106 8BD8 MOV BX,AX

-TAX=0148 BX=0148 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0108 NV UP EI PL NZ NA PE NC21C1:0108 03D8 ADD BX,AX

-TAX=0148 BX=0290 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=010A NV UP EI PL NZ AC PE NC21C1:010A 8BCB MOV CX,BX

Page 11: Chapter 3 Examining Computer Memory and Executing Instructions

-TAX=0148 BX=0290 CX=0290 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=010C NV UP EI PL NZ AC PE NC21C1:010C 2BC8 SUB CX,AX

-TAX=0148 BX=0290 CX=0148 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=010E NV UP EI PL NZ AC PE NC21C1:010E 2BC0 SUB AX,AX

-TAX=0000 BX=0290 CX=0148 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0110 NV UP EI PL ZR NA PE NC21C1:0110 EBEE JMP 0100

Displaying memory contents:view the machine language program in the code segment

D CS:100

Page 12: Chapter 3 Examining Computer Memory and Executing Instructions

Machine Language Example 2: Using Defined Data

DS offset Hex contents 0200H 2301H 0202H 2500H 0204H 0000H 0206H 2A2A2AH

Instruction Explanation A10002 move the word at DS:0200H into AX 03060202 add the contents of the word at DS:0202H into AX A30402 move the contents of AX to the word at DS:0204H EBF4 jump to the start of program

Page 13: Chapter 3 Examining Computer Memory and Executing Instructions

Keying in Program Instructions and Data

E CS:100 A1 00 02 03 06 02 02 <enter> E CS:107 A3 04 02 EB F4 <enter>

E DS:0200 23 01 25 00 00 00 <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=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0100 NV UP EI PL NZ NA PO NC21C1:0100 A10002 MOV AX,[0200] DS:0200=0123

Page 14: Chapter 3 Examining Computer Memory and Executing Instructions

-TAX=0123 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0103 NV UP EI PL NZ NA PO NC21C1:0103 03060202 ADD AX,[0202] DS:0202=0025

-TAX=0148 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=0107 NV UP EI PL NZ NA PE NC21C1:0107 A30402 MOV [0204],AX DS:0204=0000

-TAX=0148 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000DS=21C1 ES=21C1 SS=21C1 CS=21C1 IP=010A NV UP EI PL NZ NA PE NC21C1:010A EBF4 JMP 0100

D DS:0200, 020821C1:0200 23 01 25 00 48 01 2A 2A - 2A

Page 15: Chapter 3 Examining Computer Memory and Executing Instructions

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>

Page 16: Chapter 3 Examining Computer Memory and Executing Instructions

An Assembly Language Program

A 100 <enter>

xxxx:0100 MOV CL,42xxxx:0102 MOV DL,2Axxxx:0104 ADD CL,DL xxxx:0106 JMP 100xxxx:0108 <enter>

U 100, 107 <enter>

xxxx:0100 B142 MOV CL,42xxxx:0102 B22A MOV DL,2Axxxx:0104 00D1 ADD CL,DL xxxx:0106 EBF8 JMP 100xxxx:0108

Type R to display registers , and T to trace instructions.When you get to JMP, you will find IP=106H, CL=6CH

Page 17: Chapter 3 Examining Computer Memory and Executing Instructions

Using the INT Instructions

1. Getting the Current Date, INT 21H, function code 2AH

A 100<enter>MOV AH, 2A <enter>INT 21 <enter>JMP 100 <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 JMPThe 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)

Page 18: Chapter 3 Examining Computer Memory and Executing Instructions

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 21 <enter> JMP 100 <enter>, <enter>

The operation delivers hours to CH (00 = midnight) minutes to CL, seconds to DH hundredths of second to DL

Page 19: Chapter 3 Examining Computer Memory and Executing Instructions

3. Determining Installed Equipment: INT 11H

Type in A 100, then

INT 11JMP 100<enter>, <enter>

Press R to display the registers and T to trace repeatedly to seethe BIOS instruction execute. JMP EE53 ; PUSH DS ;save DS address in stack MOV AX, 0040 ;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.

Page 20: Chapter 3 Examining Computer Memory and Executing Instructions

4. Using INT for Displaying: INT 21H, function code 09H

Type A 100, then

100 MOV AH,09102 MOV DX,109105 INT 21107 JMP 100109 DB ‘your name’, ‘$’ <enter>, <enter>

Define byte dollar sign tell INT 21 to end the display.

Page 21: Chapter 3 Examining Computer Memory and Executing Instructions

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 youto press a key. If you press the number 1, you’ll see the operation delivers31H (hex for ASCII 1) to AL

Page 22: Chapter 3 Examining Computer Memory and Executing Instructions

Using the PTR Operator to indicate number of bytes 顯示

100 MOV AX,[11A] ;move contents at memory location 11AH-11BH to AX103 ADD AX,[11C] ;add contents of memory location 11CH-11DH to AX107 ADD AX,25 ;add immediate value 25H to AX10A MOV [11E],AX ;move contents of AX to memory locations 11EH-11FH10D MOV WORD PTR [120], 25 ;move a word of value 25H to 120H-121H113 MOV BYTE PTR [122], 30 ;move a byte of value 30H to location 122H118 JMP 10011A DB 14 23 ;define values 14H and 23H. DB: define byte11C DB 05 0011E DB 00 00120 DB 00 00 00

D 110 to view the changed contents of AX (233E) location 11EH-11FH (3E23) 120H-121H (2500) 122H (30)

Page 23: Chapter 3 Examining Computer Memory and Executing Instructions

Exercises:

3.4 (a) Use debug to enter the following: E CS:100 B8 45 01 05 25 00 (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, 1SUB DX, BAJMP 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)