Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
ECP2046 – Computer Organization and Architecture LAB: CO1 Duration: 3 hours Introduction to the DEBUG Program 1 Objectives i. To study and understand the mechanisms involed in program execution in a microprocessor unit ii. To understand the concept of physical and logical addresses (Segment::Offset addressing). 2 Software MS-DOS DEBUG program. Please refer to http://kipirvine.com/asm/debug/Debug_Tutorial.pdf for additional examples of the program. 3 Introduction The generic term x86 refers to the instruction set of the most commercially successful CPU architecture in the history of personal computing. It is used in processors from Intel, AMD and others, and derived from the model numbers of the first few generations of processors, backward compatible with Intel's original 16-bit 8086 CPU. 3.1 X86 CPU registers The main tools to write programs in x86 assembly are the processor registers. The registers are like variables built in the processor. Using registers instead of memory to store values makes the process faster and cleaner. Table 1 lists some of the registers in the x86 series of processors. Table 1: List of registers in x86 CPU series AX BX CX DX DS ES SS CS BP SI DI IP F Accumulator Base register Counting register Data register Data Segment register Extra Segment register Battery segment register Code Segment register Base Pointers register Source Index register Destiny Index register Next Instruction Pointer register Flag register Of all the registers listed above, AX, BX, CX, and DX are general purpose registers which will be used extensively in the following exercises. These are 16-bit registers, which can also be used as 8-bit registers. To use them as 8-bit registers, it is necessary to refer to them for example as: AH and AL, which are the high and low bytes of the AX register. This nomenclature is also applicable to the BX, CX, and DX registers. Faculty of Engineering, Multimedia University 1/9 3.2 Physical and logical addresses A physical (absolute) address is the actual physical location in memory. A logical address is the address at which a memory location appears to reside from the perspective of an executing application program. Logical address may be different from the physical address due to the operation of a memory management unit (MMU) between the CPU and the memory bus. MMU is a computer hardware component responsible for handling accesses to memory requested by the central processing unit (CPU). Its function includes translation of virtual addresses to physical addresses. An example of the usage of logical address is the Segment:Offset addressing. Segment:Offset addressing was introduced due to the limitation in the capability to address memory contents. Without using Segment:Offset addressing, a CPU with a register of 16-bit long can only address 216 or 65,536 bytes (64 KBytes) of memory directly. This of course, significantly limits the size of usable program. Using Segment:Offset addressing, the CPU is able to group two 16-bit registers together to refer to a physical memory location beyond 64 KBytes. Of course, increasing the register size in the CPU will also increase the addressing capability. However, such approach can be very costly. The physical address for any combination of Segment and Offset pairs is found by using the formula: Physical address = (Segment value × 1016) + Offset value There is another easier way to compute physical address from the Segment:Offset values. Refer to the following examples: Example 1: The Physical address of the Segment:Offset pair, 0A00:0001 can be computed by inserting a zero at the end of the Segment value ( which is the same as multiplying by 10 16 ) and then adding the Offset value: 0A000 + 0001 --------A001 --------Example 2: Segment:Offset = 023F:02FF 023F0 + 02FF --------26EF --------The disadvantage of using Segment:Offset pairs is the fact that there are a large number of these pairs that refer to the same exact memory locations. As an example, every Segment:Offset pair below refers to the same physical address of 7C00 (or 0000:7C00): 0047:7790 004C:7740 007B:7450 0202:5BE0 0048:7780 0077:7490 007C:7440 0203:5BD0 0049:7770 0078:7480 01FF:5C10 0204:5BC0 Faculty of Engineering, Multimedia University 004A:7760 0079:7470 0200:5C00 07BB:0050 004B:7750 007A:7460 0201:5BF0 07BC:0040 2/9 The number of different Segment:Offset pairs vary between memory locations, which can be up to 4,09610 pairs. For the physical addresses from FFF0 to FFFFF, the number of Segment:Offset pairs that refers to the same physical address is fixed to 4,09610 pairs. For Physical addresses 016 through FFEF (0 through 65,51910), the number of different pairs can be computed by following 2 simple steps. First, divide the physical address by 1016 (which shifts the entire hexadecimal digits one place to the right). Second, throw away any fractional remainder and add 1 to the shifted value. Below is an example of number of available Segment:Offset pairs for physical address 2B10: Example 3: Physical address = 2B10 Step 1: 2B10 / 1016 = 2B1 Step 2: 2B1 + 1 = 2B2 (or 69010) Segment:Offset pairs 3.3 Using the DEBUG program In this section, we will learn to use the DEBUG program to execute assembly language program on an x86 compatible microprocessor. A summary of the common commands that may be used with DEBUG is shown in Table 2 below. Table 2: DEBUG program command sets Command assemble compare dump enter fill go hex input load move name output proceed quit register search trace unassembled write allocate expanded memory deallocate expanded memory map expanded memory pages Faculty of Engineering, Multimedia University Syntax A [address] C range address D [range] E address [list] F range list G [=address] [addresses] H value1 value2 I port L [address] [drive] [firstsector] [number] M range address N [pathname] [arglist] O port byte P [=address] [number] Q R [register] S range list T [=address] [value] U [range] W [address] [drive] [firstsector] [number] XA [#pages] XD [handle] XM [Lpage] [Ppage] [handle] 3/9 3.4 Procedure: 1. Click the Start button on Windows’ taskbar, select Run, type “cmd” in the corresponding dialog box and press Enter () to invoke MS-DOS command prompt. 2. In the command prompt, type “debug” and press Enter to invoke the DEBUG program. 3. The DEBUG prompt (-) will be displayed, indicating that DEBUG has been executed and is now waiting for a command. 4. Type in “?” (without the double quotes) at the DEBUG prompt and press Enter. This will display a summary of the available commands and their syntax, as shown in Table 2. 5. These commands allow DEBUG to load data, examine or modify the state of the microprocessor’s internal registers and memory, and execute a program. The following exercises will focus only on some of the commands. 6. The exercises will mainly focus on some of the commands. These commands and their functions are detailed in Table 3. 7. To quit from the DEBUG program, type “Q” (with the double quotes) in the DEBUG prompt and press Enter. This will terminate DEBUG and return to the command prompt. Table 3: Commands and their functions Command Register Quit Dump Enter Unassemble Assemble Trace Go Function Examine or modify the contents of an internal register Exit from the DEBUG program Dump the contents of memory to the display Examine or modify the contents of memory Unassemble the machine code into its equivalent assembler instructions Assemble the instruction into machine code and store in memory Trace (single-step) the assembled instructions Execute the instructions down through the breakpoint address 4 Exercise 1 In this exercise, we will assemble a program which adds together both 8-bit numbers at AL (lower byte of AX register) and BL (lower byte of BX register), subtract 24H from the result and multiply it with 04H. The instructions used in this program are describe in Table 4 below. Table 4: Description of instructions used in Exercise 1 Instruction ADD AL, BL SUB AL, 24 MOV CL, 04 MUL CL 4.1 Descriptions Add BL to AL, store result in AL Subtract 2416 from AL, store result in AL Store 416 in CL Multiply CL to AL, store result in AX Procedure: 1. Invoke the DEBUG program. 2. Using the Register (R) command, change the contents of register AX to 0035H and BX to 0068H as follows: Faculty of Engineering, Multimedia University 4/9 -R AX AX 0000 :0035 -R BX BX 0000 :0068 -R IP IP 3. Using the Assemble (A) command, assemble the instructions to perform required arithmetic operation as follows: -A CS:0100 XXXX:0100 ADD XXXX:0102 SUB XXXX:0104 MOV XXXX:0106 MUL XXXX:0108 AL,BL AL,24 CL,04 CL *XXXX indicates that the contents of CS may vary from machine to machine. 4. Using the Unassemble (U) command, the instructions previously assembled into the memory can be verified as shown below: -U CS:0100 0106 5. This command will display the instructions assembled between address CS:0100 to CS:0106 in 3 columns: 1st column shows the logical addresses of the instructions; 2nd column shows the machine codes of each instruction; 3rd column shows the assembled instructions. 6. List down the output of the Unassemble command in Table 5. Table 5: Output of the Unassemble command Address Machine Codes Instruction [1 Mark] 7. The Trace (T) command can then be used to step through the assembled instructions by executing one instruction at a time and the contents of the internal registers after the execution of each instruction are automatically displayed. 8. Before executing the instructions, use the Register (R) instruction to check the contents of the microprocessor’s internal registers and record down the contents of AX, BX, CX and IP registers in Row 1 of Table 6. [1 Mark] Faculty of Engineering, Multimedia University 5/9 9. Execute the first assembled instruction (ADD AL, BL) by using the Trace (T) command as follows: -T =CS:0100 10. Identify the contents of AX, BX,CX and IP registers after executing the instruction and list down their contents in Row 2 of Table 6. [1 Mark] 11. Execute the next instruction (SUB AL, 24) by issuing the Trace (T) command as follows: -T This form of the Trace command is used to execute the next instruction. 12. Identify and list down the contents of AX, BX, CX and IP registers in the next row of Table 6. [1 Mark] 13. Repeat Step (9) and (10) to execute the two remaining instructions and record down the contents of AX, BX, CX and IP in Table 6. Table 6: Contents of IP, AX, BX and CX after each Trace command Row No. 1 2 3 4 5 6 IP AX BX CX [1 Mark] 5 Exercise 2 Dump is one the commands from the DEBUG program. It displays the contents of a block of memory. The Memory locations near the beginning of Segment C000 should display information about the kind of video card installed on your PC. The example below shows the video card information of a system obtained from the dump command using logical address C000:0010. -d C000:0010 C000:0010 24 C000:0020 4D C000:0030 52 C000:0040 2F C000:0050 29 C000:0060 50 C000:0070 40 C000:0080 E8 12 20 4F 56 00 43 00 26 FF 43 58 42 87 49 12 56 FF 4F 2F 45 DB 52 10 8B 00 4D 4D 20 87 2B 00 D8 00 50 47 42 DB 10 80 E8 00 41 41 49 87 01 00 C6 00-60 54-49 2D-47 4F-53 DB-87 10-00 00-38 56-74 00 42 31 20 DB 00 37 22 00 4C 30 28 87 18 34 8C 00 45 30 56 DB 00 2D C8 00 20 20 31 87 00 32 3D 20 4D 56 2E DB 00 00 00 49 41 47 32 87 00 FF C0 42 $.......`.... IB 54 M COMPATIBLE MAT 41 ROX/MGA-G100 VGA 20 /VBE BIOS (V1.2 DB )............... 03 PCIR+........... FF @.......874-2... 74 . &V....Vt"..=..t The dump command will be used in the following exercise. Faculty of Engineering, Multimedia University 6/9 5.1 Procedure 1. Invoke the DEBUG program. 2. Use the dump command to display the video card information on your system. [1 Mark] 3. Use the dump command to verify that logical addresses 0007:7B90 and 07C0:0000 is pointing to the same physical address by looking at the memory contents. [1 Mark] 4. Compute the physical address of logical address 0C10:0010. Verify your answer using the dump command by looking at the memory contents. Assuming XXXX is your physical address, type: d 0000:XXXX to access the memory location. [2 Marks] 5. Compute the number of logical address available for physical address 6B00. Provide your answer in hexadecimal and decimal forms. [2 Marks] 6. Compute the number of Segment:Offset pairs that point to the same physical location as the Segment:Offset pair 0030:0000. Include Segment:Offset pair 0030:0000 in your calculation. Provide your answer in hexadecimal and decimal forms. [2 Marks] Hint: Verification can be done by comparing the contents of memory locations to see whether they are the same or not. 6 Exercise 3 In this exercise, you are required to complete the assembly program for 8-bit unsigned integer multiplication. Figure 1: Flow chart for 8-bit unsigned integer multiplication Faculty of Engineering, Multimedia University 7/9 6.1 Procedure 1. Assume the following: AH AL BL CX = = = = Register A Multiplier, Q Multiplicand, M Count 2. Create the following assembly program for 8-bit unsigned integer multiplication of multiplier = 25H and multiplicand = 24H by completing the missing parts. [6 Marks] ORG CLC MOV MOV MOV MOV 0100 AH, AL, BL, CX, 00 _____ _____ _____ MOV DL, AL AND DL, _____ JZ 0113 ADD _____, BL RCR _____, 1 CLC LOOP 010A MOV DX, AX 3. Verify your answer by keying in the assembly program into the DEBUG program and stepping through the program. List down the register content change for each step until the program reaches the end by completing the table below: Table 7: Contents of the registers in each step Steps 1 2 3 . . . . BL AH AL CX DL [3 Marks] 4. State the final value in register DX. [1 Mark] 5. Compute the product of 25H and 24H (Show manual calculation). Compare if whether the calculated value is the same as the one in register DX. [2 Marks] Faculty of Engineering, Multimedia University 8/9 7 Report writing guidelines Your report must contain the following sections: 1. Report cover Please follow the report cover format in the FOE lab webpage. You can download the template at http://foe.mmu.edu.my/lab/form/student_lab-report_cover-1%202010.doc 2. Brief introduction of the experiment Describe the motivations/objectives of the experiment and the DEBUG program. Please use your own words. [5 marks] 3. Experiment results and discussions Describe your observations in each exercise of this experiment. All questions in the exercises (if any) must be answered. Distribution of marks is indicated in each exercise. [25 marks] 4. Conclusions Conclude your lab report with a brief summary on knowledge and skills that you have acquired from this experiment. [5 marks] Faculty of Engineering, Multimedia University 9/9