Passing const strings to asm routine
Posted on 1997-09-09
In a class called TShareBlock, with members
ptr : Pointer;
hMem : PChar;
FSize : Integer;
There is a method Add which increments the ptr member by n bytes after doing some range checking. (the add method source is shown below)
Should the range check fail, Add preempts the _RaiseException routine, which merely raises a new exception with the error string passed into it.
_RaiseException is not a member function. It is declared in the same scope as the class itself.
My problem is that the assembler add routine needs to call _RaiseException with a constant string. How do I pass the constant string into _RaiseException.
SMemError is declared in the implementation section of the unit as a const
SMemError = 'Memory Overrun in Share Block.'
When SMemerror is declared as a var (as opposed to const) in the unit,
_RaiseException collects the variable (in EAX) correctly, and shows the
when SMemError is declared as a const there is an access violation in the
How are const strings passed into procedures using the inline assembler in
Note that the declaration of the _RaiseException routine can be _RaiseException ( const s : String) or.
_RaiseException ( s : String ) the const here makes no difference to the success of the asm call.
Awaiting your kind resposes.
(* Code snippits *)
Procedure TShareBlock.Add( n : Integer );
MOV ECX, [EAX].&ptr
ADD ECX, EDX
MOV EDX, [EAX].hMem
ADD EDX, [EAX].FSize
CMP EDX, ECX
MOV EAX, SMemError
CALL _RaiseException // Raise Exception
MOV [EAX].&ptr, ECX
Procedure _RaiseException(const s : String );
// Collects s in EAX, as it is not a member procedure, otherwise it would
// be in EDX.