Board index » delphi » ASM in Delphi 2??

ASM in Delphi 2??

Hi all!

How do I implement the following in Delphi 2?

Procedure do_it (var buffer);
asm
  les di, buffer
  mov ax, es:[di]
  (etc)
  (how do I setup es:[di], ds:[si] for 32-bit addressing?)
  rep movsd ??
end;

Thanks in advance, from Ken

 

Re:ASM in Delphi 2??


Quote
Kenneth Teo wrote:

> Procedure do_it (var buffer);
> asm
>   les di, buffer
>   mov ax, es:[di]
>   (etc)
>   (how do I setup es:[di], ds:[si] for 32-bit addressing?)
>   rep movsd ??
> end;

ES and DS are the same, so you don't have to worry about those.
So:
mov edi, Buffer.
mov eax, [edi]

rep movsd works just fine. Just set ECX to whatever.

Note that using the standard calling convention of Delphi 2,
buffer (above) is pointed to by EAX, and not by bp - 4
(or whatever).

M.

--
Martin Larsson, author of several unknown utilities for DOS and Windows.
mailto:martin.lars...@delfi-data.msmail.telemax.no
http://www.delfidata.no/users/~martin
X.400:G=martin;S=larsson;O=delfi-data;P=msmail;A=telemax;C=no

Re:ASM in Delphi 2??


Quote
Kenneth Teo wrote:

> How do I implement the following in Delphi 2?

> Procedure do_it (var buffer);
> asm
>   les di, buffer
>   mov ax, es:[di]
>   (etc)
>   (how do I setup es:[di], ds:[si] for 32-bit addressing?)
>   rep movsd ??
> end;

> Thanks in advance, from Ken

Try something like this:

procedure do_it(var Buffer); pascal;
asm
  mov eax, [buffer]
  mov edi, eax
  mov ax, [edi]
  (etc)
  mov eax, [mypointer]
  mov esi, eax
  mov eax, [mydestpointer]
  mov edi, eax
  cld
  rep movsd
end;

If you use the register calling convention, the pointer to Buffer is
passed in EAX, so you can skip the mov eax, [buffer] line.

In a 32-bit environment, a Pointer is just a 32-bit number. No more
messing with segments! :-)

John.

--
***          *****          *******
*  mailto:joh...@tornado.be       *
*  http://www.tornado.be/~johnfg/ *
*******          *****          ***

Re:ASM in Delphi 2??


Quote
Mike Welch wrote:

> John,

> Would it be too much to ask you to discuss this on the delphi forum in a
> little more detail?  From the looks of your example there, you don't
> have PUSH any stack frames or anything before jumping right into Asm?  I
> take it then that it must be done for you.

Yes, Delphi sets up the stack frame for you.

Quote
> And what about preservation of register values?  Do they need to be restored to > their original value upon exit?

Yes, I forgot to mention that in the example.
You must preserve EDI, ESI, EBP and EBX.
You can freely modify EAX, EDX and ECX.

You can preserve the registers by pushing them on the stack and popping
them off afterwards:

procedure MyASM; assembler;
asm
  PUSH EDI; PUSH ESI; PUSH EBP; PUSH EBX
  // do your thing...
  POP EBX; POP EBP; POP ESI; POP EDI
end;

Of course, registers that you don't use in your code don't need to be
pushed and popped.
You must also remember that if you call another routine in your assembly
code, you cannot assume anything about the values in the registers other
than EDI, ESI, EBP and EBX when the routine returns.

Quote
> I haven't been able to find much on assembler in Delphi and anything you
> may have learned would probably be of benefit to more than just myself.

The assembler in Delphi works like any other assembler, so if you want
do to assembler in Delphi you should get a book on assembler for the
i486.
Of course, Delphi doesn't have fancy features like macro's, etc.

You must only remember that:
  * Delphi sets up the stack frame for you (ENTER and LEAVE
instructions),
  * You must preserve EDI, ESI, EBP and EBX
  * Delphi's calling conventions are different (see Object Pascal
Language Guide, chapter 17)
  * You need to use Delphi-style comments, not semicolons
  * Multiple assembler statements on a single line must be separated by
semicolons
  * Windows 95 will not allow you to do just anything. Interrupts, ports
and the like will not be accessible. You need to write a VxD to do that.

Regards,
John.
--
***          ******          *******
*  mailto:joh...@tornado.be        *
*  http://www.tornado.be/~johnfg/  *
*******          ******          ***

Other Threads