Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework


Assembly Expressions (Win32 Only)



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə276/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   272   273   274   275   276   277   278   279   ...   294
DelphiLanguageGuide

Assembly Expressions (Win32 Only)
The built-in assembler evaluates all expressions as 32-bit integer values. It doesn't support floating-point and string
values, except string constants. The inline assembler is available only on the Win32 Delphi compiler.
Expressions are built from expression elements and operators, and each expression has an associated expression
class and expression type. This topic covers the following material:
Differences between Delphi and Assembler Expressions
Expression Elements
Expression Classes
Expression Types
Expression Operators
Differences between Delphi and Assembler Expressions
The most important difference between Delphi expressions and built-in assembler expressions is that assembler
expressions must resolve to a constant value. In other words, it must resolve to a value that can be computed at
compile time. For example, given the declarations
const
 X = 10;
 Y = 20;
var
 Z: Integer;
the following is a valid statement.
asm
 MOV        Z,X+Y
end;
Because both 
X
 and 
Y
 are constants, the expression 
X + Y
 is a convenient way of writing the constant 30, and the
resulting instruction simply moves of the value 30 into the variable 
Z
. But if 
X
 and 
Y
 are variables
var
 X, Y: Integer;
the built-in assembler cannot compute the value of 
X + Y
 at compile time. In this case, to move the sum of 
X
and 
Y
 into 
Z
 you would use
asm
 MOV            EAX,X
 ADD            EAX,Y
 MOV            Z,EAX
end;
In a Delphi expression, a variable reference denotes the contents of the variable. But in an assembler expression,
a variable reference denotes the address of the variable. In Delphi the expression 
X + 4
 (where 
X
 is a variable)
233


means the contents of 
X
 plus 4, while to the built-in assembler it means the contents of the word at the address four
bytes higher than the address of 
X
. So, even though you are allowed to write
asm
 MOV            EAX,X+4
end;
this code doesn't load the value of 
X
 plus 4 into AX; instead, it loads the value of a word stored four bytes beyond
X
. The correct way to add 4 to the contents of X is
asm
 MOV            EAX,X
    ADD            EAX,4
end;

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   272   273   274   275   276   277   278   279   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin