Forum > Beginners

asmgetmem

<< < (2/2)

engkin:

--- Quote from: tormods on June 09, 2014, 04:54:23 pm ---I'm not sure how to use 'public name', how could it be implemented in this case?

--- End quote ---
I think something like this:

--- Code: ---function AsmGetMem(vSize: PtrUInt):pointer;register;[public];
begin
  Result := GetMem(vSize);
end;

--- End code ---
When you call it using assembly you pass the size in EAX and when it returns you receive the result in EAX as well. I did not try it, but you can see the generated assembly code if you add -al in your project "Other - Custom options"

Leledumbo:

--- Quote from: engkin on June 09, 2014, 05:40:59 pm ---
--- Quote from: tormods on June 09, 2014, 04:54:23 pm ---I'm not sure how to use 'public name', how could it be implemented in this case?

--- End quote ---
I think something like this:

--- Code: ---function AsmGetMem(vSize: PtrUInt):pointer;register;[public];
begin
  Result := GetMem(vSize);
end;

--- End code ---
When you call it using assembly you pass the size in EAX and when it returns you receive the result in EAX as well. I did not try it, but you can see the generated assembly code if you add -al in your project "Other - Custom options"

--- End quote ---

--- Code: ---public name 'AsmGetMem';
--- End code ---
would be better, since the label at assembly level will be exactly as written. Remember that by default FPC mangles name, so it will be quite difficult to call Pascal routine from assembly.

engkin:

--- Quote from: Leledumbo on June 09, 2014, 06:25:17 pm ---
--- Code: ---public name 'AsmGetMem';
--- End code ---
would be better, since the label at assembly level will be exactly as written. Remember that by default FPC mangles name, so it will be quite difficult to call Pascal routine from assembly.

--- End quote ---
It seems to me that FPC name mangling would be a problem if you were to use {$ASMMODE direct} only. Other than that I was able to call AsmGetMem as is without adding name 'AsmGetMem' to public and FPC took care of name mangling. So the above code worked with:

--- Code: ---{$ASMMODE intel}

procedure Test;assembler;
asm
  mov eax, $1234
  call AsmGetMem
end;

--- End code ---

Leledumbo:

--- Quote from: engkin on June 09, 2014, 11:48:33 pm ---It seems to me that FPC name mangling would be a problem if you were to use {$ASMMODE direct} only. Other than that I was able to call AsmGetMem as is without adding name 'AsmGetMem' to public and FPC took care of name mangling. So the above code worked with:

--- Code: ---{$ASMMODE intel}

procedure Test;assembler;
asm
  mov eax, $1234
  call AsmGetMem
end;

--- End code ---

--- End quote ---
I mean real (external) assembly, not inline assembly. I have no idea what assembly the OP means.

engkin:
You have a point, I assumed inline assembler where public does not make sense. It is up to the OP to clarify it.

Navigation

[0] Message Index

[*] Previous page

Go to full version