Block structure of the program. Modular program structure

Often large programs use subroutines to implement auxiliary algorithms. In JA, subroutines are formalized in the form of procedures.

Description of procedures

(name of the process) PROC (parameter) (body of the process) (name of the process) ENDP where (name of the process) – must be repeated twice and is used to refer to the procedure; (parameter) can take one of two values ​​- (default) or . A closely related (internal) procedure can only be accessed from the command segment where it is described. A far (external) procedure can be accessed from any program command segments, including the one where it is described. Names and labels described in a procedure are not localized within it, so they must be unique in the program . Although it is possible in AY to describe one procedure within another, this does not provide any benefit and is not usually used.

Calling procedures

In YA, all transitions between the main program and the procedure must be organized by yourself. If a procedure can return to DOS, then it can be called with the jump command to the procedure name JMP (process name). If you need to return to the calling program, then the easiest way is to use the call command CALL (process name). Then the body of the procedure must contain a return command RET There is another possibility: remember the return address using the stack and organize the return using jump commands. When calling a procedure, you should take into account the parameters passed to the procedure and its location relative to the point of call, i.e. the type of transition in the CALL command is determined automatically, For example(for procedure p). P CALL P If this is a close call (NEAR), then the following actions are performed: Stack:= AB, IP:= offset P where AB is the return address, i.e. the effective address of the command following the call; A far call (FAR) provides the actions: Stack:= CS, Stack:= AB, CS:= seg P, IP:= offset P If the procedure description is in a segment below the call command, then the branch attribute must be specified with the PTR statement. For example, CALL FAR PTR P; long distance call P

Location of procedures in a segment

    Internal procedures are in the same segment as the calling program.
In this case, 3 placement options are possible: a) All procedures are placed before the main (calling) program, which can also be formatted as a procedure. For example: Text SEGMENT 'code' ASSUME CS: text, DS: data, SS: stack A1 PROC … RET A1 ENDP Main PROC MOV AX, data MOV DS, AX … CALL A1 … MOV AX, C400h INT 21h Main ENDP Text ENDS Data SEGMENT … Data ENDS Stack SEGMENT 'stack' … Stack ENDS END Main b) all procedures are below the call point. c) procedures - inside the main procedure, it is even possible that the procedure is inside another procedure (although this does not provide any benefit) For example,… Main PROC … CALL A1 … MOV AX, C400h INT 21h A1 PROC … RET A1 ENDP Main ENDP Text ENDS 2) External procedures located in other segments or in other files. For example p, the text of the main program is in the file P.asm Text SEGMENT public 'code' ; combining modules sequentially; to the general segment ASSUME CS: text, DS: data, SS: stack EXTRN stop: proc; declaration of external name Main PROC ... CALL Stop ... Main ENDP Text ENDS Data SEGMENT ... Data ENDS Stack SEGMENT 'stack' ... Stack ENDS END Main The source text of the procedure is in the file P1.asm Text SEGMENT public 'code' ASSUME CS: text PUBLIC stop; making a name accessible from outside Stop proc ...

Stop ENDP text ENDS END ; end of file without entry point The merging of these files occurs at the linking step, i.e. separate broadcast required. For example, for MASM MASM/ZI PR MASM/ZI P1 where ZI is an option that allows you to place it in an object file full information about line numbers and symbols of the source module (IM). After PR.obj and P1.obj are formed, they need to be combined into a single boot file LINK/C0 ​​PR P1, COMPOZ where C0 is an option that transfers symbolic information to the boot file, allowing the CV debugger to display the full text of the MI, including labels and comments. The COMPOZ.exe module is ready for execution. Can include a procedure from the library. To do this, the INCLUDE directive (library file name) is placed before the IM segments For example p, to connect the IO.asm file you should write INCLUDE IO.asm S SEGMENT 'stack' … S ENDS D SEGMENT 'data' … D ENDS C SEGMENT 'code' ASSUME CS:C, SS:S, DS:D Begin: … …C ENDS END Begin

Passing parameters between procedures (organized at the request of the programmer)

    Passing parameters through MP registers
The values ​​of actual parameters can be transferred through MP registers at the request of the programmer. For example, ; calculation procedure AX:= max (AX, BX) max proc far CMP AX, BX JGE Max1 MOV AX, BX Max1: RET max endp … ; in the main procedure ... MOV AX, A ; preparing parameters MOV BX, B ; to call the procedure CALL max MOV C, AX ; saving the result...
    Passing parameters by reference means passing the address (name) of the memory location corresponding to the actual parameter (passing a named value from assembler to Pascal). To do this, you can use the name of the memory location or load the address into a register (BX, BP, SI or DI, since the procedure can use these registers for addressing) before calling the procedure.
For example, team LEA BX, B CALL……
    Passing parameters via the stack.
Passing parameters through registers is limited to a small number of them. If there are many parameters (more than 5), they are passed through the stack as follows: - The main program writes the actual parameters (values ​​or addresses) to the stack; - The procedure uses parameters written to the stack. For example:; call p(a1,…, ak) PUSH a1 … PUSH ak CALL p … An additional stack pointer BP can be used in a procedure, but at the beginning of the procedure the BP value that was used in the calling program should be stored, i.e. ; start of procedure P P proc PUSH BP ; save BP MOV BP, SP ; setting the BP to the top of the stack...Basic addressing can then be used. For example, for a close call, the return address, pushed onto the stack automatically, is the address of the last parameter ak. Before returning from the procedure, you should restore BP with the POP BP command, then clear the stack of passed parameters so that it does not become overloaded when calling procedures multiple times, i.e. set SP to a value 2*k greater than it was after the procedure was called. There are 2 possibilities for correctly returning from the procedure. a) adjust SP in the calling program
; end of procedure; in the calling program
POP BPCALL p
RETADD SP, 2*k ; SP correction
PENDP
b) use a return command with stack restoration, which has the form for a close call RET (cnt) where (cnt) is a counter (constant expression), word size. The command performs the following actions: IP:= Stack SP:= SP + (cnt) Then the end of the procedure looks like: POP BP RET 2*k p ENDP For a long procedure call, the return command looks like RET (cnt) and performs the following actions: IP:= Stack CS:= Stack SP:= SP + (cnt) With this return from a procedure, no additional action is required in the calling program.
    Problem saving registers when calling a procedure
To prevent the procedure from corrupting the values ​​of registers that were used in the calling program, it is required in the text of the procedure before using any register to save its “old” value on the stack, and at the end of the procedure to restore all saved values. For example, if the procedure uses the CH register, then it should be stored on the stack, but the stack only remembers the word, so the procedure will contain a fragment: PUSH CX ; saving the “old” CX MOV CX, 0 ; using CX in the procedure...; before exiting the POP CX procedure; restoring the “old” CX Thus, we get a generalized scheme of a close (NEAR) procedure with parameters passed through registers and through the stack

(proc name) proc

PUSH BP for maintenance

Mov BP, SP stack

PUSH saving registers,

used in the procedure

body proc.

POP... register recovery

POP BP recovery BP

Previously, the tabular type of layout was widespread on the Internet, to which this page is dedicated. However, over time, this approach to creating a website structure became outdated, and it was replaced by block layout.

Differences between block layout and tabular layout

If the table layout implies that the page contents are inside the tag

, then the concept of block layout is based on the active use of universal tags
, which contain content, including other tags.

Block layout does not have the disadvantages of tabular layout - search engines it is indexed better, its code is not so sprawling, and the blocks

, which they like to call “layers”, were originally intended to be universal, that is, “for everything,” whereas
is a table that should be used to display tabular data and nothing more.

The only noticeable disadvantage of block layout is that sites made on it may be displayed differently in browsers. To avoid this, you need to make the layout “cross-browser”, that is, displayed equally by any browser.

The essence of block layout

IN graphic editor a website layout is created: it is marked where which area of ​​the page (header, bottom, sidebar, main content) will be located and how much space it will take up, pictures and backgrounds are prepared.

Each part of the page is placed in its own block

: top of the site - in the first, menu - in the second, content - in the third, etc. Each block is filled with content using HTML, and is also positioned and styled using CSS markup.

The final HTML document is a collection of blocks

with content inside. The design is often located in a separate CSS file, connected to the page with the tag , or at least in a container

2024, applelavka.ru - Studying the computer. Just something complicated. Gadgets