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.

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

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) 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;

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment