Download assLect6(cont)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Lecture 6 (continuation)
Fundamentals of programming. Programs
preparation and debugging.
1. Listing of Example program translation.
2. Elements of program listing.
4. Segmentation directives.
3. Debugging of Program.
Literature.
1. Jurov V. Assembler, – SPb.: Piter, 2001. – 624 p.
2. Pustovarov V. I. Assembler. Programming and
analysis of machinery programs correctness, Kiev: “Irina”, 2000. - 476
3.Tanenbaum,
A.S.
Structured
Computer
Organization, 4th ed. - Upper Saddle River, NJ :
Prentice Hall, 2002.
Segmentation directives.
The functional predestination of segments is a
bit wider than a simple partition of the program into
blocks of code, data and stack. Segmentation
supposes as well, the unification of object modules,
created by the compiler, which allows to connect
(unite) programs, written in different languages. For
realizing of such connections special operands in
the directive SEGMENT are intended.
The segment directive allows six different
attributes (items) in the operand field: an align
operand, a combine operand, a class operand, a
readonly operand, a "uses" operand, and a size
operand. Three of these operands control how DOS
loads the segment into memory, the other three
control code generation.
Let’s consider some of such operands:
 Attribute
of segment alignment (type of
alignment). It informs the compiler, that it is
necessary to provide an allocation of the segment
beginning at the given border (it is important for
simplification of access to the data). There are
following permissible meanings of this attribute:
 BYTE. In this case the segment may be
allocated starting from an arbitrary address in
the main memory;
 WORD. In this situation the initial (base)
address of the segment will be dividable by 2;
 DWORD. The segment begins with an
address dividable by 4;
 PARA. The segment begins with an address
dividable by 16;
 PAGE. The segment begins with an address
dividable by 256;
 MEMPAGE. The segment begins with an
address dividable by 4 Kbytes.
If one of the above keywords does not
appear as a parameter to the segment directive,
the default alignment is PARA paragraph (a
paragraph is a multiple of 16 bytes).
 Attribute
of segments combining (combining
type). It informs the compiler, that it is necessary
to combine segments of different modules, which
have the same name. The default the combining
is PRIVATE. Meanings of this attribute may be
following:
 PRIVATE. In this case the segment will not
be united with other segments;
 PUBLIC. It compels the compiler to unite
all segments (with the same name) in one
continues segment;
 COMMON. In this case all the segments
will overlay and use collectively (share) the
memory (the size of such segment will be
equal to the size of the segment with the
largest area).
 STACK. It determines a segment for the
stack (there is some analogy with the
PUBLIC).
 Attribute of segment class (type of class). It is
enclosed in inverted commas (‘’) string, which
helps the compiler to determine an order of
segments location during compilation a program,
which consists from several modules
 Attribute
of
segment’s
size.
For
microprocessors i80386 and higher segments
may be 16- or 32-width, so it may influence on
segments sizes and on the order of the physical
address formation inside these segments. This
attribute may have the following meanings:
 USE16 – it means, that during a physical
address formation, can be used only 16width offset;
 USE32 – it means, that during a physical
address formation, can be used only 32width offset.
Debugging of Program in Assembly.
Turbo Debugger (TD) is a window medium
for debugging programs. It allows to solve the
following problems:
 to determine a place of logic error;
 to determine the reason of logic error appearance;
The TD has got the following abilities:
 to execute a program’s trace forward, i.e. a
sequential program’s execution, when only one
machinery instruction is fulfilled per one step;
 to execute a program’s trace backward, i.e.
execution one machinery instruction per one step
in the opposite direction;
 survey and change of state of the
microprocessor’s hardware during execution
program’s instructions.
 The TD doesn’t allow to correct the initial text
of the program. After the completion work of the
debugger all changes will not be saved.
Key Moments of Creation EXE Module, which
will be possible to Debug.
 A label (or a name of procedure) for the first
instruction, from which the program’s execution
begins, must be determined in the program. The
name of this label must be determined at the end
of the program as an operand of the directive
END.
 The initial module must be translated with an
option /zi:
TASM/zi name_of_initial_module.
The using of this option (/zi) permits to the
translator to save connections among symbolic
names in the program and their offsets inside the
code segment, all this allow to the debugger to
execute the debugging by using original names.
 Linking of the module must be executed with an
option /v:
tlink/v name_of_object_module
This option(/v) transfers the information to the
loaded file, which is used by TD.
 Before start of TD you should be certain, that
there are loaded and initial modules (i.e.: .exe
and .asm, correspondingly) in your working
catalogue. The start of TD is better to make from
the commands string in a form:
TD name_of_executed_module
After loading the TD two windows will appear on
the screen: Module and Watches. The first
contains the initial text of the program, and the
second will be empty at the beginning, but during
the debugging process it’ll reflect changes of
variables.
For the debugging program in assembly, it is
necessary to control all microprocessor’s registers
(some times to control fields of interrupt vectors).
For this purpose it is recommendable to use the
CPU window, which may be called with help of
upper menu: View > CPU, or by the command:
<Alt> + <V> +<C>.
The CPU window includes 5 internal windows:
 Window of initial text (as in Assembly, so in
machinery codes);
 Window of CPU registers;
 Window of flags;
 Window of memory;
 Window of stack.
In order to choose the necessary window it is
possible to use a button(key) “Tab”.
Let’s consider the contents of the window of
CPU registers: the contents of DS and ES the same
and equals 11F5h (it means that the program is
loaded into the memory beginning from the physical
address 11F50, i.e. approximately from the 70-th
kilobyte. The first kilobytes (about 25 Kbytes) are
occupied by DOS, and a bit less than 50 Kbytes are
occupied by the TD, So, if we don’t use TD, the
program is loaded from the other (less) physical
address, and even more, under the debugger
control a program may be processed differently,
than it’s processed directly in DOS (sometimes
programs under TD control are processed
incorrectly).
Why the contents of DS and ES registers is the
same after the program loading? We already know,
that at first these registers are tuned on the
program’s prefix (the prefix usually occupies 100
bytes, i.e. 10h paragraphs). After the prefix the
codes segment is located, so, the CS contents will
be equal to 11F5h + 10h = 1205h.
In our example the program starts from the label
begin (because it has been pointed as an operand
in the directive of the program completion end).
This label refers to the first instruction of the code
segment, so its offset must be equal to 0. Further,
the meaning of IP will grow. In order to execute 2
instructions, it will be enough to push twice the
button <F8>, or <F7>. When we use these buttons,
the so-called “step by step” mode is used. The
difference of using buttons <F8> and <F7> consists
in the following: if there are subroutines or interrupts
in the program, then the debugger will execute their
instructions step by step, when <F7> is used, when
we use <F8>, every subroutine, or interrupt will be
processed as one instruction (not in detail).
The ‘step-by-step” mode is more often used,
because it allows to observe execution of any
concrete instruction. Except this mode, there are
three additional modes:
Mode of “unconventional execution”,
when it is enough to observe a general
behavior of the program. For using this
mode, it is necessary push the button
<F9>.
Mode of “executing up to current cursor’s
position”. This mode is expedient to use, if you are
interested in a processing of some part of
instructions of your program. The button <F4> is
used for starting this mode.
Mode of “execution with setting points
of interrupts (breakpoints)”. For starting
this node the button <F2> is used.
Problems.
1. How the processor can address a segment that is
aligned on a byte, word, or double word boundary?
2. What problems does the TD allow to solve? Which
modes of program execution (debugging) are used in
the TD?
3. What‘s for is created program listing?
4. List the main elements of program’s listing.