Listing – what it is in simple words: a complete analysis of the concept. Design of program listings Listing in programming

Var n1, n2: Longint;

Function Quantity(x: Longint): Byte;

Var k: Byte;

While x<>0 Do

Begin

End;

Quantity:= k;

Begin

Writeln("Enter two numbers");

k1:= Quantity(n1);

(number of digits of the first number)

k2:= Quantity(n2);

(number of digits of the second number)

Writeln("Same number of digits")

If k1 > k2 Then

Writeln("The first number has more digits")

Writeln("The second number has more digits");

Lecture No. 17. Unconventional use of user routines. Recursion

A number of problem solving algorithms require calling a subroutine from the statement section of the same subroutine.

Recursion is a way of organizing a computational process in which a procedure or function refers to itself during the execution of its constituent operators. Using recursion special attention should be paid to exit the subroutine at the right time. Recursion is useful when a task needs to be divided into subtasks. When using a recursive procedure and function, you need to place the line at the beginning

if keypressed then halt; - to interrupt the hang if it happens. Keypressed is a function that returns a result true, if a key was pressed on the keyboard, and false- otherwise.

Example 1. Consider a program for calculating the elements of the Fibonacci series using recursive procedures.

procedure fibon(n,fn1,fn:integer);(recursive procedure)

if n > 0 then

writeln(fn1+fn);

fibon(n-1,fn,fn1+fn);

var n,a,b: integer;

write("enter the number of elements of the Fibonacci series: ");

write("...the following two given numbers: ");

Fibon(n,a,b);

Example 2. A program that displays the digits of a positive integer in reverse order.

program rekurs2;

procedure reverse(n:integer);(recursive procedure)

If keypressed then halt;

Write(n mod 10);

if (n div 10)<>0 then

Reverse(n div 10);

writeln("vvedi number<= : ", maxint);

Revers(n);

Lecture No. 18. Input – output of data. Files

A file is a set of data stored in the external memory of a computer under a given name.

Any file has three characteristic features:

1. The file has a name, which allows the program to work with several files simultaneously.

2. The file contains components of the same type. The file component type can be any type.

3. The length of the newly created file is not specified in any way when it is declared and is limited only by the capacity of external memory devices.

In order for the program to find the required file, you need to know the path or route to the file.

A path is a list of subdirectory names, separated from each other by a backslash, followed by the actual file name.

For example:

c:\catalog1\catalog2\file1.txt.

Each directory name corresponds to an entry in a subdirectory with that name. The ".." sign corresponds to an entry into a superdirectory. The maximum allowed path length is 79 characters.

In a TP program, the file name is specified as a text constant enclosed in apostrophes, which can be the value of a string variable:

"\turbo\pas\table.txt".

Devices. The use of files in TR was caused by the need to exchange data with the computer environment, its hardware: display, keyboard, printer, input-output channels. All of them are considered in TP as files that can be worked with in the same way as with regular files. Files on external devices are often called physical or external files . Devices are accessed using special names that are prohibited from being used for regular files - the so-called names of computer logical devices.

­ CON – console . Using the console, the output information is sent to the display screen, and the input information is received from the keyboard;

­ PRN this is the name printer . If several printers are connected to the computer, then they are accessed using logical names: LPT1, LPT2, LPT3.

­ COM1, COM2, COM3 – these are devices for connecting to serial ports . Used to communicate with other computers and to connect a mouse.

­ NUL - zero or empty device. Often used by programmers to debug a program. Allows you to avoid creating a separate file. When using it to output information, the information is not output anywhere, but it is reported that the output was successful.

Access to files. At any time, the program is only accessible one file element referenced by the current file position pointer. It defines the location in the file from or to which data is read or written. When opening or creating a file the pointer is placed at the beginning of it. The pointer behaves like a cursor, which, moving while editing text, always shows the current position. When reading data from a file, the pointer will eventually reach the end of the file. According to the method of accessing elements, they distinguish sequential or direct access files.

Which can be read by a person. In a generalized sense - any input data for the translator. The source code is translated to executable code entirely before running the program using a compiler or can be executed immediately using an interpreter.

Purpose

The source code is either used to produce object code or executed by an interpreter. Changes are made only to the original one, followed by re-conversion to the object one.

Another important purpose of source code is as a description of a program. Based on the text of the program, you can reconstruct the logic of its behavior. Comments are used to make source code easier to understand. There are also tools that allow you to automatically obtain source code documentation - the so-called. documentation generators.

In addition, the source code has many other uses. It can be used as a teaching tool; Beginning programmers may find it useful to examine existing source code to learn programming techniques and methodology. It is also used as a communication tool between experienced programmers due to its concise and unambiguous nature. Code sharing among developers is often cited as a contributing factor to improving the programmer experience.

Programmers often move source code (either as modules, as is, or with adaptations) from one project to another. This is called code reuse.

Source code is a critical component for the process of porting software to other platforms. Without the source code of any piece of software, porting is either too difficult or completely impossible.

Organization

The source code of some part of the software (module, component) may consist of one or more files. Program code is not necessarily written in only one programming language. For example, often programs written in C language contain insertions of assembly language code for optimization reasons. It is also possible that some components or parts of a program are written in different languages, and then assembled into a single executable module using a technique known as library linking ( library linking).

Complex software requires dozens or even hundreds of source code files to be built. In such cases, to simplify the build, project files are usually used that contain a description of the dependencies between the source code files and describe the build process. These files may also contain options for the compiler and design environment. For different design environments, different project files can be used, and in some environments these files can be in a text format, suitable for direct editing by a programmer using universal text editors; in other environments, special formats are supported, and the creation and modification of files is carried out using special tools programs. Project files are usually included in the term "source code". Often, source code also refers to resource files containing various data, for example, graphic images needed to build a program.

To make it easier to work with source code and to allow a team of programmers to collaborate on code, version control systems are used.

Quality

Unlike humans, there is no “well-written” or “badly written” code for a computer. But how the code is written can greatly influence the software maintenance process. The quality of the source code can be judged by the following parameters:

  • code readability (including the presence of comments to the code);
  • ease of support, testing, debugging and error correction, modification and porting;
  • economical use of resources: memory, processor, disk space;
  • absence of comments output by the compiler;
  • absence of “garbage” - unused variables, unreachable code blocks, unnecessary outdated comments, etc.;
  • adequate error handling;
  • possibility of interface internationalization.

Non-executable source code

Copyleft licenses for free software require distribution of the source code. These licenses are also often used for works that are not software - for example, documentation, images, data files for computer games.

In such cases, the source code is considered to be the form of the work that is preferred for editing. In licenses other than software, it may also be referred to as the "transparent format" version. This could be, for example:

  • for a file compressed with loss of data - the lossless version;
  • for rendering a vector image or a three-dimensional model - respectively, the vector version and the model;
  • for a text image - the same text in text format;
  • for music - a file in the internal format of the music editor;
  • and finally, the file itself, if it satisfies the specified conditions, or if a more convenient version simply did not exist.

see also

Purpose

The source code is either used to produce object code or executed by an interpreter. Changes are never made to object code, only to source code, and then converted back to object code.

Another important purpose of source code is as a description of a program. Based on the text of the program, you can reconstruct the logic of its behavior. Comments are used to make source code easier to understand. There are also tools that allow you to automatically obtain source code documentation - the so-called. documentation generators.

In addition, the source code has many other uses. It can be used as a teaching tool; Beginning programmers may find it useful to examine existing source code to learn programming techniques and methodology. It is also used as a communication tool between experienced programmers, due to its (ideally) concise and unambiguous nature. Code sharing among developers is often cited as a contributing factor to improving the programmer experience.

Programmers often move source code from one project to another, which is called code reuse ( Software reusability).

Source code is a critical component for the process of porting software to other platforms. Without the source code of any piece of software, porting is either too difficult or completely impossible.

Organization

The source code of some part of the software (module, component) may consist of one or more files. Program code is not necessarily written in only one programming language. For example, often programs written in C language, for optimization purposes, contain inserts of code in assembly language. It is also possible that some components or parts of a program are written in different languages, and then assembled into a single executable module using a technology known as library linking ( library linking).

Complex software requires dozens or even hundreds of source code files to be built. In such cases, to simplify the build, project files are usually used that contain a description of the dependencies between the source code files and describe the build process. These files may also contain other compiler and design environment parameters. For different design environments, different project files can be used, and in some environments these files can be in a text format suitable for direct editing by a programmer using universal text editors; in other environments, special formats are supported, and the creation and modification of files is carried out using special tools programs. Project files are usually included in the term "source code". The vast majority of modern language environments require the use of project files, regardless of the complexity of the other source code included in the project. Often, source code also refers to resource files containing various data, for example, graphic images needed to build a program.

To facilitate work with source code, for collaboration on code by a team of programmers, version control systems are used.

Quality

Unlike humans, there is no “well-written” or “badly written” code for a computer. But how the code is written can greatly influence the software maintenance process. The quality of the source code can be judged by the following parameters:

  • code readability (including the presence or absence of code comments;
  • ease of support, testing, debugging and error correction, modification and porting;
  • low complexity;
  • low resource usage - memory, processor, disk space;
  • absence of comments output by the compiler;
  • absence of “garbage” - unused variables, unreachable code blocks, unnecessary outdated comments, etc.

The listing of the “demol.c” program is shown in Fig. 6.7. The programmer will come up with a name for the program. The extension “.c” is required. The text is typed in the editor “Programmer’s Notepad 2” (abbreviated as PN2), which is included in the WinAVR package instead of the graphical shell. It also allows you to create a project, fix errors, compile a program, and even program MK.

Rice. 6.7. Listing of the program "demol.c".

Rice. 6.8. Appearance of the PN2 program.

The PN2 editor is an independent project with its own website. The appearance of the PN2 main menu is shown in Fig. 6.8.

Procedure.

1.3run the file “WlnAVR-20100110-install.exe” (29 MB) located on the supplied CD. This file can be freely downloaded from the Internet if necessary. Install WlnAVR by default in the C:\WinAVR-20100110\ folder.

2. Open the PN2 editor: “Start - Programs - WinAVR-20100110 - Programmers Notepad”. Enable line numbering: “Tools - Options - General - Default -<поставить «галочку» возле «Show Line Numbers»>- OK".

3. Create a new C file in the PN2 editor: “File - New - C/C++”. Enter the program text from the keyboard according to Fig. 6.7 and save it to your hard drive: “File - Save As... -<ввести путь и имя файла, например, для однозначности C:\1001\demol.c>- OK".

Here and below, screenshots (screenshots) will be shown only at the most important points of action to save space. The remaining step-by-step screenshots can be viewed in the video tutorials on the included CD.

Explanations for listing.

Line 1 begins with comments, which are delimited on the left by two forward slash lines. All text after the “//” signs can be about anything, in any language, with any liberties and abbreviations. This is arbitrary information that the programmer writes for himself, his loved one, so that in a month or two he can remember what was actually discussed. Usually the short name of the program and authorship are indicated.

Line 2 also contains comments, but of a technical nature. Here is an electrical diagram for connecting the HL1 indicator and the SB1 button to specific lines of MK ports. The names of the signals correspond to the layout from the dashsheet on MHKpocxeMyATmega48A (Fig. 6.9).

Rice. 6.9. MKATmega48A signal layout.

The practice of textually describing simple diagrams in the header of a program is widespread in the community of programmers who are too lazy to draw and attach graphic diagrams, believing that “everything is clear anyway.”

Line 3 specifies the makefile parameters. For reference, normal operation of the AVR-GCC compiler is possible with the presence of two required files. The first of them is a listing file with the extension “.c”, the second is a system instructions file “makefile” without an extension. “Makefile” is created by the “MFile” utility (Fig. 6.10, author JoergWunsch, Germany), included in WinAVR.

Rice. 6.10. Appearance of the MFile program.

Procedure.

1. Run the “MFile” utility: “Start - Programs - WinAVR-2010010 – MFile”.

2. Fill in the template fields as follows (Fig. 6.11):

In the item “Makefile - Main file name… - Main file” enter the name of the project being developed “demol” and click OK;

In the item “Makefile - MCU type - ATmega” select MK “atmega48a”;

In the “Makefile - Optimization level” item, set the optimization level to “2”. Other possibilities: “0” - no optimization, “s” - minimum code length, numbers “1” ... “3” - these are three different optimization methods, and the number “3” does not mean the best option, it all depends on the specific C program .

It is not necessary to adjust the remaining points of the “makefile” template; let them remain as default.

Rice. 6.11. Filling out fields in the MFile program.

For each new project and new MK type, you need to create your own “makefile”, and the project name and MK type will change.

Line 4 contains comments specifying the hexadecimal numbers of the Low, High, and Ext bytes of the configuration. These values ​​will be needed later when programming MK “fuses”.

S « ktg5 is informationally empty. It visually separates comment text from the rest of the program. Instead of one, you can insert two empty lines, which is not important. The main point is to improve visibility. This does not affect the length of MK firmware codes.

The external design of the listing is created by the programmer himself, based on his own ideas about the beauty of the picture and the ease of presenting information. Often, by the design style of the “header”, listing lines and comments, you can identify the author of the program or create his psychological portrait. Interesting notes on this matter are given in the monograph by Alain Golub.

Line 6 is served by the compiler preprocessor. This is not a C language statement or a comment. The name is complex, but the meaning is simple. The preprocessor (pre-PROCESSOR) searches for lines in the program that begin with the “#” character. Next, depending on the keyword, it performs a certain action, for example, “define” - assigns values ​​to constants, “if defined” - checks the condition, “inC1ude” - connects the function library, etc.

For the first acquaintance, it is enough to know that the function library is a set of files into which the texts of standard or frequently repeated procedures are placed. In this case, the “#inC1ude” directive (translated from English as “enable”) activates the system library “avr/io.h”, which is responsible for the operation of I/O ports. This library has different names in different compilers, but the essence is the same, without it you cannot manage any line of MK ports. Therefore, connecting an I/O library is mandatory for all microcontroller C programs.

Line 7 is also processed by the compiler preprocessor, but has the keyword “define” (translated from English as “define”). Consequently, it declares the INI constant and assigns it the constant value 255. The comments specify the translation of the number 255 into hexadecimal 0xFF and binary 0bl 1111111 number form. The difference between them lies in the letters “x” and “b” after the obligatory number “0”. The correspondence of numbers in different systems is given in Table. 6.3.

Table 6.3. Converting numbers from hexadecimal to binary and vice versa

If the INI constant is found somewhere in the “body” of the program, then the compiler without thinking substitutes the numeric value specified in line 7 instead of it, i.e. 255. This is very convenient for programmers when correcting large listings, when constants are scattered throughout the text. In addition, the name of the constant itself can carry a semantic load and serve as a verbal hint. In particular, INI is an abbreviation for the English word “initialization”, which means some initial value.

The importance of placing a constant in the “header” of the program lies in the ease of finding it and the speed of making changes. For example, having corrected the number “255” once, you can be sure that everywhere in the text it will be automatically (and error-free!) entered through the lNI constant.

The programmer comes up with a name for the constant based on common sense and human preferences. According to a long-standing tradition, the names of constants are written in capital characters. The first letter in the name must be, for example, I2CBUS, T34. The use of Cyrillic alphabet is not allowed.

The declaration of the INI constant could be written in two more equivalent ways: “#define INI OxFF” or “#define INI Obl 1111111”.

Line 8 contains the variable declaration statement "a". A variable can be figuratively represented as a box (box, box, pencil case), where a certain number of objects (beads, grains, matches) are stored. To make the “boxes” different from each other, they are marked with different inscriptions on the body, in this case with the letter “a”. If the variable description does not indicate the initial number, then the “box” is considered empty and it is initialized to zero (a = 0). As the program progresses, objects can be added to the “box” and objects can be removed from it, i.e. increase and decrease the value of a variable.

The volume of the “box” depends on its original advertisement. In Table. 6.4 shows the limits accepted in the AVR-GCC compiler. As you can see, the “unsigned char” declaration allows you to put 255 items in the “box”. Together with the zero value (an empty “box”) there will be a total of 256 states or 256 bytes. A variable with the declaration “unsigned long” no longer looks like a box, but like an entire train, which is designed to hold 4.2 billion items.

Table 6.4. Dimensions of variables adopted by AUK-vSS

Since MK does not have developed tools for working with negative numbers, at first, in order not to get confused, it is better to use only positive numbers in programs, i.e. containing the “unsigned” declaration.

Since ancient times, the “commanding fathers” of the language have established an unspoken order, according to which the name of a variable should consist of no more than 8 characters. In the AVR-GCC compiler, this rule is ignored and the variable can contain as many characters as you want, but without fanaticism. The only thing is that the first letter in the name must be a letter of the Latin alphabet; it can be followed by letters, numbers, and symbols. Cyrillic alphabet is not allowed.

A variable, unlike a constant, contains some variable (rather than constant) number. To distinguish variables from constants, they are written in small letters. Usually they try to ensure that the name matches the meaning, for example, “count” for a counter, “data” for data, “delay” for a delay. Although sometimes one-letter variables that are familiar from school algebra look simpler, more familiar and more compact - a, b, c, d, i, j, k, x, y, z.

The programmer determines which dimension to indicate for a specific variable. Since the variable “a” in this listing is a storage for collecting information from the digital 8-bit port “C”, it means that it should contain “two to the eighth power” bytes, i.e. from 0 to 255.

Interestingly, the compiler does not throw an error if you play it safe and declare the variable with a reserve as “unsigned long a;”. True, this leads to a needless increase in the amount of code from 114 to 126 bytes and, accordingly, to a slight decrease in the speed of program execution.

The other extreme is underestimation of the dimension, when, for example, instead of declaring “unsigned int”, “unsigned char” is used. If you enter a number greater than 255 into such a variable, then only the remainder of division by 256 will be retained, and the leading part will be irretrievably lost. Figuratively speaking, objects spill out of the “box” out. The compiler does not react to such errors, believing that the programmer is in an adequate state and understands what he is doing. Correct and error-free determination of the dimension of variables usually comes with experience.

Line 9 is informationally empty, similar to line 5. Whether to insert it into the listing depends on the will of the programmer.

Line 10 is filled with comments, but they are presented in a different format for variety. Namely, the text is highlighted on the left side with the symbols “/*”, and on the right side with the symbols “*/”. This style originates from the most ancient versions of the C language. Later, the “//” symbols began to be used in comments, which is typical for the C++ language. In WinAVR, both options have an equal right to exist. The “new” spelling is simpler and more visual, while the “old” spelling is in some places the only possible one if you need to comment on the beginning of a statement.

Line 11 contains a typical call to the "main" function according to the rules of the American National Standards Institute (ANSI). Abbreviated expressions are allowed, but not recommended: “int main ()”, “main ()”, “main (void)”. Sometimes they even write “void main (void)”, emphasizing the complete absence of received and transmitted parameters. For simple MKs that do not support real-time operating systems, there will be no negative consequences. However, if you think about the future, it is better to immediately memorize the full form of writing, which will make it easier in the future to transfer C programs to more modern microcontroller platforms.

Line 12 is entirely devoted to the first opening curly brace. It is no coincidence that she was awarded this honor. When executing line 12, the C language compiler performs the initial initialization of the MK registers, setting up the stack, and allocating the address space. There is no need to study the mechanics of this jewelry process (unlike assembler programs!).

For a programmer, the main thing is to correctly understand two things that the compiler included in WinAVR automatically produces:

When the program starts, all interrupts are disabled;

The lines of all MK ports are configured as inputs without “pull-up” resistors.

Line 13. Finally, the first executable command of the program appeared in the form of an assignment operator. Explanation of symbols:

“DDRB” is the conditional name of the eight-bit DDR register of port “B”;

“=” - sign of writing data to the DDRB register;

“Оь” - an indication that the next 8 digits will be in binary code;

“11111111” - bits of a binary number written to the DDRB register, arranged in the order 7, 6, 5, 4, 3, 2, 1, 0 (most significant bit on the left, least significant bit on the right).

As a result of executing this operator, all lines of port “B” are set to output mode, since all digits contain ones.

The statement on line 13 is indented two spaces to the left. This is a text formatting convention that many programmers adhere to. The compiler will remain silent if you start the text in the first or seventh column on the left, as you like. There is only one recommendation: “The C-program listing should be easy to view.” Following it, in the future all texts will be formatted so that the curly braces are located in odd columns vertically (1, 3, 5, etc.), and in each column there will be only one opening at the top and one closing at the bottom.

This order is not a dogma, but a way to shorten the listing in width and length without losing information content. The programmer “at home”, in his listings, has the right to enter any number of spaces, empty lines, etc.

Line /4 works in conjunction with line 13, since the specific state of the port line in AVR controllers is determined by a combination of two registers DDRx and PORTx, where “x” is the serial letter of the port, for example, B, C or D. Considering that each register has 8 bits with numbers from 0 to 7 (conventionally “z”), then the general layout along the port lines is as follows:

DDRx.z = 1, PORTx.z = 1 - output with HIGH level;

DDRx.z = 1, PORTx.z = 0 - output with LOW level;

DDRx.z = 0, PORTx.z = 1 - input with “pull-up” resistor;

DDRx.z = 0, PORTx.z = 0 - input without “pull-up” resistor.

Generalization of lines 13 and 14: DDRB.0…DDRB.7 = 1, PORTB.O = 0, PORTB.l = 1, PORTB.2…PORTB.7 = 0, therefore, lines 0, 2…7 of port “B” will be configured as LOW outputs and line 1 as HIGH output. Since the HL1 indicator is connected to line PB1 (pin 15 of the DD1 chip in Fig. 6.3), it will be turned off. It turns out that the initial part of the technical assignment was completed successfully.

Lines 15, 16 are similar to lines 13, 14, but for port “C”. For variety, the constant lNI is substituted. After lines 15 and 16 are executed, all lines of port “C”, even those that are not directly involved in operation, will be configured as inputs with “pull-up” resistors. This is a standard technique for initially initializing ports in order to activate internal pull-up resistors, which prevent the CMOS inputs of the MK lines from “hanging in the air” and eliminate the penetration paths of all kinds of interference and interference.

Line 17 is the same as lines 13, 14 and 15, 16, but for port “D”. It is not involved in the electrical circuit at all, but you should make it a rule to initialize all ports without exception at the beginning of the program. Their idle lines must be configured as pull-up resistor inputs or HIGH/LOW outputs. In the future, such automation will help avoid collisions and misunderstandings.

A special feature is that the PORTD register is assigned the value previously assigned in line 13 to the DDRB register, i.e. binary number Obl 1111111. This was done for educational purposes, because it could have been done simpler: “PORTD = OxFF;”.

Another detail is the absence of a DDRD register entry. This is not a typo, but a deliberate reduction of the listing by one line, since when the power is turned on, according to the datasheet, “zeros” are automatically entered into all DDRx and PORTx registers, i.e. It is not necessary to additionally reset the DDRD register.

Line 18 contains the "while" loop statement. For the first acquaintance, it is enough to remember that the expression “while (1)” means sequential execution of the statements in lines 19...21 in an endless loop.

Line 19 contains an open parenthesis and an assignment operator. This combination is allowed by the rules of the C language, which makes the listing more compact in height.

After line 19 is executed, the variable “a” will store the status byte of the eight lines of port “C”, which was read from the PINC register. If the SB1 button is not pressed, then “a = OxFF”, and if it is pressed, then “a = OxFE”.

Line 20 shifts the contents of variable “a” one place to the left. There are two possible options: if “a” was previously OxFF, then it will become OxFE, and if it was OxFE, then it will become OxFD. The next line of the program will tell you why this is done.

Line 21 contains an assignment statement, but, compared to line 19, the variable "a" and the port register have swapped places. In the C language, such castling results in the replacement of a read operation from a port with a write operation to a port. In total, code 0xFE (if the SB1 button is not pressed) or code 0xFD (if the SB1 button is pressed) will be output to port “B”. In the first case, the HL1 indicator will be off, in the second it will be on, which is what was required to be achieved according to the technical specifications.

Lines 22, 23 contain closing curly braces. If you mentally draw two vertical lines from them “bottom-up”, they will point directly to the opening brackets in lines 19 and 12. The bracket in line 22 indicates a repetition of the cycle in lines 19...21. The parenthesis in line 23 begins in the first position from the left, therefore, the end of the “main” function, and therefore the main program, has been reached.

Line 24 contains comments about the WinAVR version number and the length of the firmware codes, which is very useful when compiling the program by other users. It is known that WinAVR versions are not 100% compatible with each other, and there are clear examples of this. Consequently, the length of the compiled code for the same listing may differ from release to release. The practical conclusion is that you must first compile the program with the WinAVR package indicated in line 24, and only then with an older or newer version, checking the resulting code length as a checksum.

The attentive reader has the right to notice that at the stage of compiling the listing of the C program it was impossible to calculate in advance how much space the codes occupy in the MK memory. To be honest, the inscription “114 bytes (2.8%)” was added later, after compiling the program. There is a clear example of the same feedback that is in the block diagram in Fig. 6.1 was indicated by a dotted line between blocks “K” and “L”.

Line 25 is completely empty, but unlike lines 5 and 9, it marks the physical end of the listing. Without this final line, the compiler issues a mild but still warning: “Warning: no newline at end of file.”

When compiling a program, you can set the "l" (listing) parameter:

Then, in addition to the file with the object code sum. obj, a file with the listing sum will be created. lst:

  • 1 ;sum. asm – program that calculates S=A+B
  • 2 0000 data segment
  • 3 0000 0001 a dw 01h
  • 4 0002 0002 b dw 02h
  • 5 0004 ???? s dw ?
  • 6 0006 data ends
  • 7 0000 code segment
  • 8 assume ds:data
  • 9 0000 BA 0000s begin: mov dx, data
  • 10 0003 8E DA mov ds, dx
  • 11 0005 A1 0000r mov ax, a
  • 12 0008 03 06 0002r add ax, b
  • 13 000C A3 0004r mov s, ax
  • 14 000F B8 4C00 mov ax, 4C00h
  • 15 0012 CD 21 int 21h
  • 16 0014 codeends
  • 17 endbegin

The listing is a table containing four columns:

    Line number.

    Address inside the segment, i.e. from its beginning (offset).

    Memory contents at given addresses. In the data segment these are the values ​​of variables, in the code segment these are machine codes of instructions.

    Assembly code.

Comments in the listing are also preserved, they are simply omitted here to save space.

From the listing it is clear that only lines 9-15 correspond to processor commands. The remaining lines correspond to the so-called. assembler directives.

In any case, information of various levels appears. There is information directly about the task, and there is information about the information - meta-information. These are, for example, various explanations, instructions, etc. The source code in assembly language contains two types of information:

    commands - information for the processor;

    directives - information for the assembler itself, how to compile a program: how to translate commands into machine language and how to place data.

There is an analogy here with distinguishing types of commands. Data transfer commands, control transfer commands and arithmetic-logical commands carry information about the task, and machine control commands carry information about the conditions for its execution, i.e. also represent meta-information.

The program in question contains the following directives:

    segment - directive for declaring the beginning of a segment;

    dw (define word) - directive for defining data (allocating and initializing a memory area) of 16 bits in size;

    ends (end segment) - directive for declaring the end of a segment;

    assume - directive for assigning a segment to a segment register;

    end is a directive indicating the end of the program; its argument must be the label of the first command of the program - the entry point into the program.

There are also the following data definition directives:

    db (define byte) - directive for defining an 8-bit memory area;

    dd (define double word) - directive for defining a 32-bit memory area.

There are directives whose names are preceded by a dot. Of this kind of directives, we only need directives indicating the used set of instructions for a particular processor model, for example:

    386 - non-system commands of the i80386 processor are used;

    386p - all commands of the i80386 processor are used, including system ones.

Lines 3-5 contain directives for defining variables A, B and S. Collectively, lines 3-5 and 9-15 contain information for the processor - a program that includes instructions and data. They are directly mapped to the computer's memory.