Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-11

asm offset question

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ABorka

Hi,

I'm converting a Delphi program to FPC/lazarus and I did hit a snag with an asm code part (win32, latest fpc and lazarus svn trunk is used). I know it is probably simple to fix, but I cannot seem to be able to figure it out:

function something(s :String; i: Integer):String;
var tmp:Array[0..32768]of byte;
begin
.
.
{$ASMMODE intel}
asm
pushad
mov edi, offset tmp
add edi, ebp
.
.
popad

     end;

end;

The compiler gives "Error: Cannot use local variable or parameters here" at line "mov edi, offset tmp" .
How can I get the offset of a local variable into a register?

Thanks for any help.

Reply by email

Daniël Mantione
to ABorka

Op Sat, 8 Nov 2008, schreef ABorka:

Show quoted text 26 lines
Hi, I'm converting a Delphi program to FPC/lazarus and I did hit a snag with an asm code part (win32, latest fpc and lazarus svn trunk is used). I know it is probably simple to fix, but I cannot seem to be able to figure it out: function something(s :String; i: Integer):String; var tmp:Array[0..32768]of byte; begin . . {$ASMMODE intel} asm pushad mov edi, offset tmp add edi, ebp . . popad end; end; The compiler gives "Error: Cannot use local variable or parameters here" at line "mov edi, offset tmp" . How can I get the offset of a local variable into a register?

This seems like an incompatibility you might want to report. However, you can replace the mov & add by:

lea edi,tmp

... whould should be accepted by FPC.

Daniël

Reply by email

ABorka
to Daniël Mantione

Thanks. It seems that

mov al, dl

as well as

xor al, dl

gives error too. I created a bug report
http://bugs.freepascal.org/view.php?id=12595

Daniël Mantione wrote 46 lines
Op Sat, 8 Nov 2008, schreef ABorka: > Hi, > > I'm converting a Delphi program to FPC/lazarus and I did hit a snag > with an asm code part (win32, latest fpc and lazarus svn trunk is used). > I know it is probably simple to fix, but I cannot seem to be able to > figure it out: > > function something(s :String; i: Integer):String; > var tmp:Array[0..32768]of byte; > begin > . > . > {$ASMMODE intel} > asm > pushad > mov edi, offset tmp > add edi, ebp > . > . > popad > end; > end; > > The compiler gives "Error: Cannot use local variable or parameters > here" at line "mov edi, offset tmp" . > How can I get the offset of a local variable into a register? This seems like an incompatibility you might want to report. However, you can replace the mov & add by: lea edi,tmp ... whould should be accepted by FPC. Daniël ------------------------------------------------------------------------ _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

ABorka
to Michael Schnell

True, but if the programs only run on PCs (Windows and Linux on Intel processors in this case) it should work. Not everyone who considers using FPC/Lazarus wants to run the compiled programs on 15 platforms. Sometimes all that is needed is 1 platform.
There are some encrypting/decrypting functions that would be hard to write in other than asm, especially if they are already done.

Some projects I just wanted to try to compile strictly on Windows without wanting to go to other OS-es. Just to see if it is possible at all to move projects over to FPC/Lazarus from Delphi with a reasonable amount of work. Until that doesn't work, going to other OS-es is not really viable anyway.
Not having a debugger in Lazarus with a properly working watch window and CPU window doesn't help either to do these tasks.

The "offset", "aam" and "aad" asm instructions are not working as they are in Delphi, but there are workarounds fortunately, until they will be fixed in FPC, if ever.

http://bugs.freepascal.org/view.php?id=12595

aam 16 (or aam 8, etc.)
aad 16 (or aad 8, etc.)
Both give compiler errors and points to the wrong source line. Need to use "db" instructions to put the machine code there to circumvent it.

move esi, offset variable
Gives compiler error but the functionality can be replaced with the "lea esi, variable" instruction instead as a workaround.

Michael Schnell wrote 9 lines
IMHO, it's not a good idea to "port" ASM code to TP (as TP's purpose is platform independence). So at best you should rewrite this in Pascal. Normally with modern PCs the performance decrease is not noticeable. -Michael _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email