CO1 - Faculty of Engineering - Multimedia University

jaspersugarlandΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 7 μήνες)

89 εμφανίσεις

Faculty of Engineering, Multimedia University

1
/
9

EC
E
2046


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 phy
sical 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 o
f

the pr
ogram.


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 t
he 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. Usi
ng 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 C
PU series

AX

A
ccumulator

BX

B
ase register

CX

C
ounting register

DX

D
ata register

DS

D
ata
S
egment register

ES

E
xtra
S
egment register

SS

Battery segment register

CS

C
ode
S
egment register

BP

B
ase
P
ointers register

SI

S
ource
I
ndex register

DI

D
estiny
I
ndex register

IP

Next

I
nstruction

P
ointer register

F

F
lag 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 als
o 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

2
/
9

3.2

Physi
cal 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 ma
y 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
(C
PU). 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 m
emory contents. Without
using Segment:Offset addressing, a CPU with a register of 16
-
bit long can only address 2
16

or 65,536
bytes (64 KBytes) of memory directly. This of course, significantly limits the size of usable program.
Using Segment:Offset address
ing, 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 × 10
16
) + 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:




0A00
0


+


0001



---------




A001



---------


Example 2
: Segment:Offset = 023F:02FF



023F
0


+


02FF



---------




26EF


---------


The disadvantage of using Segment:Offset pairs is the fact that there are a lar
ge 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

0048:7780

0049:7770

004A:7760

004B:7750

004C:7740

0077
:7490

0078:7480

0079:7470

007A:7460

007B:7450

007C:7440

01FF:5C10

0200:5C00

0201:5BF0

0202:5BE0

0203:5BD0

0204:5BC0

07BB:0050

07BC:0040


Faculty of Engineering, Multimedia University

3
/
9

The number of different Segment:Offset pairs vary between memory locations, which can be

up to
4,096
10

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,096
10

pairs.


For Physical addresses 0
16

through FFEF (0 through 65,519
10
), the number of differe
nt pairs can be
computed by following 2 simple steps. First, divide the physical address by 10
16

(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 / 10
16

= 2B1


Step 2: 2B1 + 1 = 2B2 (or 690
10
) Segment:Offset pairs

3.3

Using the DEBUG program

In this section, we will learn t
o 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

S
yntax

assemble

A [address]

compare

C range address

dump

D [range]

enter

E address [list]

fill

F range list

go

G [=address] [addresses]

hex

H value1 value2

input

I port

load

L [address] [drive] [firstsector] [number]

move

M range address

name

N [
pathname] [arglist]

output

O port byte

proceed

P [=address] [number]

quit

Q

register

R [register]

search

S range list

trace

T [=address] [value]

unassembled

U [range]

write

W [address] [drive] [firstsector] [number]

allocate expanded memory

XA [#p
ages]

deallocate expanded memory

XD [handle]

map expanded memory pages

XM [Lpage] [Ppage] [handle]




Faculty of Engineering, Multimedia University

4
/
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 comm
and 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 D
EBUG 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

Comman
d

Function

Register

Examine or modify the contents of an internal register

Quit

Exit from the DEBUG program

Dump

Dump the contents of memory to the display

Enter

Examine or modify the contents of memory

Unassemble

Unassemble the machine code into its
equivalent assembler instructions

Assemble

Assemble the instruction into machine code and store in memory

Trace

Trace (single
-
step) the assembled instructions

Go

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

Descriptions

ADD AL, BL

Add BL to AL, store result in AL

SUB AL, 24

Subtract 24
16

from AL, store result in AL

MOV
CL, 04

Store 4
16

in CL

MUL CL

Multiply CL to AL, store result in AX

4.1

Procedure:

1.

I
n
voke 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

5
/
9

-
R AX


AX 0000

:0035


-
R BX


BX 0000

:006
8


-
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
A
L,
B
L


XXXX:0102 SUB AL,24


XXXX:0104 MOV CL,04


XXXX:0106 MUL CL


XXXX:0108




*
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: 1
st

column shows the logical addresses of the instructions; 2
nd

column shows the
machine codes of each instruction; 3
rd

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

6
/
9

9.

Execute the first assembled instruction (ADD
A
L,
B
L) 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 nex
t 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.

IP

AX

BX

CX

1





2





3





4





5





6





[1 Mark]


5

Exercise 2


Dump is one the commands from the DEBUG program. It displays the contents of a block of memor
y.

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 C0
00:0010.


-
d C000:0010

C000:0010

24

12

FF

FF

00

00


00

00
-
60

00

00

00

00

20

49

42

$.......`....
IB

C000:0020

4D

20

43

4F

4D

50

41

54
-
49

42

4C

45

20

4D

41

54

M COMPATIBLE MAT

C000:0030

52

4F

58

2F

4D

47

41

2D
-
47

31

30

30

20

56

47

41

ROX/MGA
-
G100 VGA

C000:0040

2F

56

42

45

20

42

49

4F
-
53

20

28

56

31

2E

32

20

/VBE BIOS (V1.2

C000:0050

29

00

87

DB

87

DB

87

DB
-
87

DB

87

DB

87

DB

87

DB
)
...............

C000:0060

50

43

49

52

2B

1
0

01

10
-
00

00

18

00

00

00

00

03

PCIR+...........

C000:0070

40

00

12

10

00

80

00

00
-
38

37

34

2D

32

00

FF

FF

@.......874
-
2...

C000:0080

E8

26

56

8B

D8

E8

C6

56
-
74

22

8C

C8

3D

00

C0

74 .

&V....Vt"..=..t


The dump co
mmand will be used in the following exercise.



Faculty of Engineering, Multimedia University

7
/
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:000
0 is pointing
to the same physical address by looking at the memory contents.


[1 Mark]

4.

C
ompute

the physical address of logical address 0
C10:0010. Verify your answer using the
dump command by looking at the memory contents. Assuming XXXX i
s your physical address,
type:

d 0000:XXXX

to access the memory location.






[2 Marks]

5.

C
ompute

the number of logical address available for physical address 6B00. Provide your
answer in hexadecimal and decimal forms.






[2 Marks]

6.

C
omput
e 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

8
/
9

6.1

Procedure

1.

Assume the following:


AH = Register A


AL = Multiplier, Q


BL = Multiplicand, M


CX = Count

2.

C
reat
e the following assembly program for 8
-
bit unsigned i
nteger multiplication of multiplier =
25H and multiplicand = 24H

by completing the missing parts
.




[6 Marks]



ORG 0100





CLC






MOV AH, 00





MOV AL, _____





MOV BL, _____




MOV CX, _____





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 conten
t 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

BL

AH

AL

CX

DL

1






2






3






.






.






.






.






[3 Marks]


4.

State

the final value in register DX
.





[1 Mark]


5.

Compute

the product of 25H and 24H (Show manual calculation)
.

Comp
ar
e

if whether
the
calculated value
is
the s
ame as the one in register DX
.



[2 Marks]








Faculty of Engineering, Multimedia University

9
/
9

7

Report writing guidel
ines


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.

Ex
periment 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]