Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
system prog new.docx
Скачиваний:
1
Добавлен:
01.05.2025
Размер:
275.7 Кб
Скачать

33. Conditional assembling. Expressions

At the majority of programming languages there are the commands, allowing to

ignore this or that site of the program depending on performance of conditions,

for example: in language C it is carried out by preprocessor commands #if, #ifdef,

#ifndef, etc. The assembler too gives such opportunity.

if expression

… … …

endif

If value of expression — zero (lie), all site of the program between IF and ENDIF

is ignored. The directive IF can be combined with ELSE and ELSEIF also:

if expression

… … …

else

… … …

endif

If value of expression — zero, is assembled a program site from ELSE to ENDIF,

otherwise — from IF to ELSE.

if expression1

… … …

elseif expression2

… … …

elseif expression3

… … …

else

… … ...

endif

So, if, for example, expression 2 isn't equal to zero, the program site between the

first and second directive ELSEIF will be assembled. If all three expressions are

equal to zero, the fragment from ELSE to ENDIF is assembled. This structure of

directives can be used in that specific case similar to operators of switch/case of

languages of high level, if expressions — checks of some constant on equality.

Except the general directives IF and ELSEIF assemblers support a set of special

commands, each of which checks a special condition:

IF1/ELSEIF1 — if the assembler carries out the first pass of assembling;

IF2/ELSEIF2 — if the assembler carries out the second pass of assembling (often doesn't

work at modern assemblers);

IFE expression/ELSEIFE expression — if expression is equal to zero (in a false manner);

IFDEF label/ELSEIFDEF label— if a label is defined;

IFNDEF label/ELSEIFNDEF label— if a label isn't defined;

IFB <argument>/ELSEIFB <argument> — if value of argument — a gap (these and all

following directives are used in macrodefinitions for check of parameters);

IFNB <argument>/ELSEIFNB <argument> — if value of argument — not a gap (it is used in macrodefinitions for check of the given parameters);

IFDIF <arg1>, <arg2>/ELSEIFDIF <arg1>, <arg2> — if arguments differ (with distinction of capital and small letters);

IFDIFI <arg1>, <arg2>/ELSEIFDIFI <arg1>, <arg2> — if arguments differ (without distinction of capital and small letters);

IFIDN <arg1>, <arg2>/ELSEIFIDN <arg1>, <arg2> — if arguments are identical (with distinction of capital and small letters);

IFIDNI <arg1>, <arg2>/ELSEIFIDNI <arg1>, <arg2> — if arguments are identical (without distinction of capital and small letters).

Expression — is a set of numbers, labels or the strings connected with each

other by operators.

Operator <> (angular brackets). The part of expression concluded in angular

brackets, isn't calculated, and applied as a string of symbols, for example:

message1 equ <foobar>

Operator () (parentheses). The part of expression concluded in parentheses, is

calculated first of all.

mov al, 2*(3+4); mov al, 14

Arithmetic operators: + (plus), – (minus), * (multiplication), / (integer division),

MOD (remainder of division). They carry out the corresponding arithmetic

actions.

mov al, 90 mod 7; mov al, 6

Besides, the unary minus concerns to arithmetic operators - a minus which put

before a negative number.

Logical operators: AND, NOT, OR, XOR (excluding OR), SHL (shift to the left),

SHR (shift to the right). These operators carry out the corresponding logical

actions.

mov ax, 1234h AND 4321h; mov ax, 0220h

Operators of comparison: EQ (equally), GE (it is more or equally), is (more) than

GT, LE (it is less or equally), is (less) than LT, NE (not equally). The result of

action of each of these operators — unit if the condition is satisfied, and zero — if

isn't carried out.

.errnz $ gt 65535 ;If the address more than 64 KB – a

mistake

Operators of addressing:

SEG expression — the segment address;

OFFSET expression — shift;

THIS type — the current address (MASM and TASM);

The PTR type expression — type redefinition;

LARGE expression — 32-bit shift (TASM and WASM);

SMALL expression — 16-bit shift (TASM and WASM);

SHORT expression — 8-bit shift.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]