Sign in Join

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

Mailing lists / fpc-pascal / 2006-07

inline assembler procedure

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Пётр Косаревский

How can I write inline assembler procedure?

(FPC accepts the word "inline", but generates "call" instruction etc.)

If there is a way, could anyone point to an example, please?

Or just remember rotating bits in fpc-devel (if I get it right, they were not implemented):

(it's i386, cyclic bitwise longword l shift to the left by c bits; c may be over 32)

function lrol(l: longword; c: byte): longword; assembler; inline; // this thing is not really inline asm
movb %dl,%cl
roll %cl,%eax

   end; // calling register conventions: l->eax, c->dl

(it generates
.globl P$P_LROL$LONGWORD$BYTE$$LONGWORD
P$P_LROL$LONGWORD$BYTE$$LONGWORD:
# Temps allocated between ebp-4 and ebp-4
# Register ebp allocated
pushl %ebp
movl %esp,%ebp
subl $4,%esp
# Var l located in register
# Var c located in register
# Temp -4,4 allocated
# Var $result located at ebp-4
# Register eax,ecx,edx allocated
# [97] movb %dl,%cl
movb %dl,%cl
# [98] roll %cl,%eax
roll %cl,%eax
# Register eax,ecx,edx released
# Temp -4,4 released
leave
# Register ebp released
ret
# Register eax released

and

(moving variables, which could already be in registers) call P$P_LROL$LONGWORD$BYTE$$LONGWORD

where it is expected to be inlined)

Reply by email

Michael Van Canneyt
to Пётр Косаревский
=?koi8-r?Q?=F0=A3=D4=D2 =EB=CF=D3=C1=D2=C5=D7=D3=CB=C9=CA?= wrote 5 lines
How can I write inline assembler procedure? (FPC accepts the word "inline", but generates "call" instruction etc.) If there is a way, could anyone point to an example, please?

Currently you cannot inline assembler routines, it is a known restriction.

Michael.

Reply by email

Tomas Hajny
to Michael Van Canneyt
Michael Van Canneyt wrote 10 lines
On Thu, 20 Jul 2006, =?koi8-r?Q?=F0=A3=D4=D2 =EB=CF=D3=C1=D2=C5=D7=D3=CB=C9=CA?= wrote: > How can I write inline assembler procedure? > > (FPC accepts the word "inline", but generates "call" instruction etc.) > > If there is a way, could anyone point to an example, please? Currently you cannot inline assembler routines, it is a known restriction.

If nothing else, you can skip the stack frame generation using "nostackframe" keyword. Not that it would help that much probably...

Tomas

Reply by email

Пётр Косаревский
> Currently you cannot inline assembler routines, it is a known restriction.

I didn't get this one message.

If nothing else, you can skip the stack frame generation using "nostackframe" keyword. Not that it would help that much probably... Tomas

Oh, well.

Thanks for the answers.

Reply by email

Florian Klaempfl
to Пётр Косаревский: How can I write inline assembler procedure? (FPC accepts the word "inline", but generates…
Пётр Косаревский wrote
How can I write inline assembler procedure? (FPC accepts the word "inline", but generates "call" instruction etc.)

Inline is only a recommendation.

If there is a way, could anyone point to an example, please?

Inlining assembler procedures efficently is rather hard, so we don't do so currently.

Show quoted text 50 lines
Or just remember rotating bits in fpc-devel (if I get it right, they were not implemented): (it's i386, cyclic bitwise longword l shift to the left by c bits; c may be over 32) function lrol(l: longword; c: byte): longword; assembler; inline; // this thing is not really inline asm movb %dl,%cl roll %cl,%eax end; // calling register conventions: l->eax, c->dl (it generates .globl P$P_LROL$LONGWORD$BYTE$$LONGWORD P$P_LROL$LONGWORD$BYTE$$LONGWORD: # Temps allocated between ebp-4 and ebp-4 # Register ebp allocated pushl %ebp movl %esp,%ebp subl $4,%esp # Var l located in register # Var c located in register # Temp -4,4 allocated # Var $result located at ebp-4 # Register eax,ecx,edx allocated # [97] movb %dl,%cl movb %dl,%cl # [98] roll %cl,%eax roll %cl,%eax # Register eax,ecx,edx released # Temp -4,4 released leave # Register ebp released ret # Register eax released and (moving variables, which could already be in registers) call P$P_LROL$LONGWORD$BYTE$$LONGWORD where it is expected to be inlined) _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email