[英]Store function variable in ASM functions in Delphi
How can I properly store n
in functions like the following one ? 如何在以下函数中正确存储
n
? Because of value in n
changes for some reason after I use it once. 由于使用一次后,
n
的值由于某种原因而改变。
function Test(n: Integer): Byte;
asm
mov eax, n
add eax, eax
add eax, n
mov ecx, eax
mov ebx, eax
mov ecx, n
end;
The first argument to the function, n
, is stored in eax
, so your line 函数的第一个参数
n
存储在eax
,因此您的行
mov eax, n
is highly strange (move n
to n
). 非常奇怪(将
n
移至n
)。 Also, if you change eax
, you change n
. 另外,如果您更改
eax
,那么您将更改n
。
You could save the argument for future use (since you likely need to alter eax
): 您可以保存该参数以备将来使用(因为您可能需要更改
eax
):
var
tempN: integer;
asm
mov tempN, eax
Also, IIRC, you must not change the value of ebx
when writing inline ASM. 另外,在IIRC中,编写内联ASM时不得更改
ebx
的值。 Hence, you need to surround your code by push ebx
and pop ebx
. 因此,您需要通过
push ebx
和pop ebx
包围代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.