flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Asm .obj into Devpas(FreePascal)

Author
Thread Post new topic Reply to topic
sittingduck



Joined: 31 Dec 2007
Posts: 7
sittingduck
test.obj:

format MS COFF
extrn var1
mov edx,[var1]
add edx,10
mov [var1],edx
ret


and then:

program MyProgram;
uses crt;

{$ASMMODE INTEL}
{$APPTYPE GUI}
{$MODE FPC}
{$MMX ON}
{$Q-}
{$R-}
{$S-}
{$D-}
{$L test.obj}

var
var1 : Longint; cvar; external;

begin
readln;
end.

Gives:

test.obj(.flat+0x1): undefined reference to `var1'
test.obj(.flat+0xa): undefined reference to `var1'


All i wanna do is using variables & functions.

Please help...
Post 08 Jan 2008, 20:50
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
"extrn" is for "importing" external symbol to your module. If you want to "export" symbol from module for other module to use, there is directive "public"
Post 08 Jan 2008, 23:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
sittingduck



Joined: 31 Dec 2007
Posts: 7
sittingduck
format ms coff
section '.code' code readable executable

; export symbols
public mymain as '_mymain'
public var1 as '_var1'

mymain:
mov edx,var1
add edx,100
ret

section '.data' data readable writeable
var1 dd 0,0,0,0


Assembles to objectfile.OBJ no errors.
But this:

program MyProgram;
uses crt;

{$ASMMODE INTEL}
{$APPTYPE GUI}
{$MODE FPC}
{$MMX ON}
{$Q-}
{$R-}
{$S-}
{$D-}
{$L objectfile.OBJ}

var var1,_var1: LongInt;

begin
var1:=20;
_var1:=67;
mymain;
_mymain;

WriteLN(var1,'...',_var1);
readln;
end.




why.pas(20,3) Error: Identifier not found MYMAIN
why.pas(20,9) Error: Illegal expression
why.pas(21,2) Error: Identifier not found _MYMAIN
why.pas(21,9) Error: Illegal expression
why.pas(26) Fatal: There were 4 errors compiling module, stopping
Post 09 Jan 2008, 13:27
View user's profile Send private message Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
I never tried to link external .obj with free pascal.

But fpc's inline asm is easy:

Code:
program project1;
{$APPTYPE CONSOLE}
{$ASMMODE INTEL}

function addnum(x, y : integer) : integer;
var
res : integer;
begin
asm
    pusha
    mov eax,x
    mov ebx,y
    add eax,ebx
    mov res,eax
    popa
end;
    addnum:=res;
end;



begin
     writeln('The sum is ',addnum(2,3));
end.    


I hope it helps.


It just reminds me how wonderful language pascal is. I'll start using it more. Razz
Post 11 Jan 2008, 04:09
View user's profile Send private message Reply with quote
sittingduck



Joined: 31 Dec 2007
Posts: 7
sittingduck
OzzY wrote:
I never tried to link external .obj with free pascal.

But fpc's inline asm is easy:

Code:
program project1;
{$APPTYPE CONSOLE}
{$ASMMODE INTEL}

function addnum(x, y : integer) : integer;
var
res : integer;
begin
asm
    pusha
    mov eax,x
    mov ebx,y
    add eax,ebx
    mov res,eax
    popa
end;
    addnum:=res;
end;



begin
     writeln('The sum is ',addnum(2,3));
end.    


I hope it helps.


It just reminds me how wonderful language pascal is. I'll start using it more. Razz


That works like a charm.
But why are the color of asm code same as the background in DevPas?
Post 11 Jan 2008, 21:15
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.