Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Free Pascal
»
Beginners
(Moderators:
FPK
,
Tomas Hajny
) »
asm from delphi to fpc
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
IRC channel
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
how to tweek fpmake to co...
by
paule32
[
Today
at 07:10:34 pm]
Quirky windows
by
ASerge
[
Today
at 07:07:16 pm]
Parameter passing odditie...
by
ASerge
[
Today
at 06:59:05 pm]
A fairly simple sound sol...
by
Thaddy
[
Today
at 06:52:55 pm]
add new targets to make
by
Key-Real
[
Today
at 06:44:32 pm]
[Request] Demo Scene Sub ...
by
Gigatron
[
Today
at 06:29:39 pm]
Unlocking Files
by
KodeZwerg
[
Today
at 06:03:08 pm]
[SOLVED] trunk bug for mi...
by
Key-Real
[
Today
at 05:56:32 pm]
Demo Scene Bitmap Font Sc...
by
Gigatron
[
Today
at 05:56:27 pm]
Compile/Convert Delphi pr...
by
Martin_fr
[
Today
at 05:43:11 pm]
Generics - correct syntax
by
Thaddy
[
Today
at 05:40:59 pm]
Lazarus for Windows on aa...
by
msintle
[
Today
at 05:32:42 pm]
InstallAware Using Lazaru...
by
msintle
[
Today
at 05:26:36 pm]
Xcode Command Line Tools ...
by
Joseph
[
Today
at 05:16:39 pm]
Offical launch of the 1 B...
by
Hartmut
[
Today
at 04:49:29 pm]
what to do if my target M...
by
nickysn
[
Today
at 04:16:02 pm]
compiler error in unit
by
paule32
[
Today
at 03:49:50 pm]
Can function be used for ...
by
VisualLab
[
Today
at 02:15:30 pm]
Multithreading - synchron...
by
mika
[
Today
at 01:48:51 pm]
May be useful to somebody
by
KodeZwerg
[
Today
at 12:38:22 pm]
match automatic highlight...
by
Чебурашка
[
Today
at 11:35:14 am]
Tchart with dual numbers ...
by
wp
[
Today
at 10:48:18 am]
Debugger crashes with App...
by
Martin_fr
[
Today
at 09:29:46 am]
Copyrights Q
by
BrassGear
[
Today
at 09:13:14 am]
[SOLVED] how to build the...
by
Key-Real
[
Today
at 09:12:33 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: asm from delphi to fpc (Read 2263 times)
nanobit
Full Member
Posts: 160
asm from delphi to fpc
«
on:
October 23, 2018, 08:26:32 am »
The following delphi asm code (to change the field TFreeObject.VMIndex: Integer)
does not compile with fpc. How could one port this?
Code: Pascal
[Select]
[+]
[-]
procedure
TFreedObject
.
GetVirtualMethodIndex
;
assembler
;
asm
Inc
(
VMIndex
)
;
Inc
(
VMIndex
)
;
Inc
(
VMIndex
)
;
Inc
(
VMIndex
)
;
Inc
(
VMIndex
)
;
Inc
(
VMIndex
)
;
Inc
(
VMIndex
)
;
Inc
(
VMIndex
)
;
Inc
(
VMIndex
)
;
Inc
(
VMIndex
)
;
jmp TFreedObject
.
VirtualMethodError
end
;
Logged
Thaddy
Hero Member
Posts: 14381
Sensorship about opinions does not belong here.
Re: asm from delphi to fpc
«
Reply #1 on:
October 23, 2018, 10:13:11 am »
Such code relies on very low level implementation detail and may even change between Delphi versions: it is bad code! in my opinion.
Since it relies on implementation detail it is not FPC compatible.
But you can use e.g. TObject.MethodAddress
Depends what you want?
[edit]
FPC Has a TypeOf() function that returns the VMT, so the index is something like (TYourObject.MethodAddress('methodname') - TypeOf(TYourObject)) div sizeOf(Pointer);
You can get the address and the VMT and subsequently the index.
That also means it is silly to use assembler for it.
«
Last Edit: October 23, 2018, 10:25:21 am by Thaddy
»
Logged
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.
marcov
Administrator
Hero Member
Posts: 11455
FPC developer.
Re: asm from delphi to fpc
«
Reply #2 on:
October 23, 2018, 10:14:13 am »
Compile a small program that has a pascal version of the method with -Rintel -a and look at the generated code in the .s file.
Logged
Thaddy
Hero Member
Posts: 14381
Sensorship about opinions does not belong here.
Re: asm from delphi to fpc
«
Reply #3 on:
October 23, 2018, 10:22:44 am »
Marco, I did an edit. Would that work? [edit] No! but something can be done along those lines.
«
Last Edit: October 23, 2018, 11:33:44 am by Thaddy
»
Logged
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.
nanobit
Full Member
Posts: 160
Re: asm from delphi to fpc
«
Reply #4 on:
October 23, 2018, 03:02:33 pm »
Unfortunately, I will give up. I wanted to port fastMM to Lazarus, but it compiles only without the FullDebugMode define. FullDebugMode is required to use detection of memory corruptions, the main reason I wanted to use it.
Logged
Thaddy
Hero Member
Posts: 14381
Sensorship about opinions does not belong here.
Re: asm from delphi to fpc
«
Reply #5 on:
October 23, 2018, 03:11:08 pm »
heaptrc.pp shows you how to detect memory corruption in much the same way. So examine that.
Also note the memory manager from Freepascal works internally different - not much but significant - from Delphi and is already fast (much faster than the default Delphi one once was before they changed to fastmm light) and it is cross-platform which fastmm isn't...
«
Last Edit: October 23, 2018, 03:29:40 pm by Thaddy
»
Logged
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Free Pascal
»
Beginners
(Moderators:
FPK
,
Tomas Hajny
) »
asm from delphi to fpc
TinyPortal
© 2005-2018