delphi inline assembly {asm}

Posted marklove

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了delphi inline assembly {asm}相关的知识,希望对你有一定的参考价值。

https://community.idera.com/developer-tools/programming-languages/f/c-libraries/72223/inline-assembly
this code compiles well

int UTF8_avance(unsigned char*& srcUTF8, int nombre)
{
__asm {
		push	esi
		push	ebx

		mov		eax, nombre
		mov		esi, [srcUTF8]

nvCaractere:
		movzx	ebx, BYTE PTR [esi]		// le caractère courant
		jz		finChaine
		inc		esi
s0:
		bt		ebx, 7
		jnc		finCar					// un seul octet
		and		ebx, 0xC0				// b7-6
		cmp		ebx, 0xC0				// premier octet d‘une suite commence par 0b11xxxxxx
		je		s1
		neg		eax						// erreur
		jmp		fin
s1:
		movzx	ebx, BYTE PTR [esi]		// le caractère courant
		jz		finChaine
		inc		esi
		and		ebx, 0xC0				// b7-6
		cmp		ebx, 0x80				// tous les octets aprés le premier d‘une suite commencent par 0b10xxxxxx
		je		s1
		jmp		s0

finCar:
		dec		eax
		jne		nvCaractere
finChaine:
		mov		[srcUTF8], esi
fin:
		pop		esi
		pop		ebx
	}
}

see line "[srcUTF8], esi"

int UTF8_trouveExtrait(unsigned char* srcUTF8, unsigned char*& debutUTF8, unsigned char*& finUTF)
{

  __asm	{
		push	esi
		push	ebx
		push	ecx


		mov		esi, [debutUTF8]
		mov		edi, [srcUTF8]
		mov		ecx, 120			   // la longeur de la première chaine
		cld
		REPNE	cmpsb
		jnz		s1
		mov		eax, -1
		jmp		sortie
s1:
		mov		ebx, eax
		mov		esi, [finUTF]
		push	esi
		push	eax
	//	call	strrchr
		pop		ecx					   	// nettoyer la pile on modifier directement esp
		pop		ecx
		cmp		eax, 0
		jnz		s2
		mov		eax, -2
		jmp		sortie
s2:
    	mov		[debutUTF8], ebx
		mov		[finUTF], eax

		xor		eax, eax
sortie:
		pop     ecx
		pop		ebx
		pop		esi
	}

}

this one indicates an error (MSBUILD : error E1059: instantiated into assembly here )

Anyone have an explanation? I‘m moving from Visual Studio to CAD Builder but problems like this are many !

Why is this written in assembly to begin with? This can easily be written in C and run just as efficiently, and be easier to management and port between compilers.

Votre réponse indique une certaine soumission aux "standards" mais elle à le mérite d‘être. Il se trouve que j‘aime programmer en assembleur (et ce n‘est guère plus long qu‘autre chose) et que j‘ai des dizaines de routines qui fonctionnent bien, alors avant de passez à un autre compilateur de VS je regardes ce qu‘il en est. Quand à penser que du C sera aussi rapide que de l‘assembleur, c‘est inexact, même si la différence dans ce cas sera faible. Mais j‘ai du écrire un solveur il y a quelques années, je vous assure que la version QT, puis C étaient largement distancée par la version en assembleur.

Your answer indicates a low submission at "standards" but it exist ! I to like to program in assembler (and it‘s not much longer than anything else) and I have dozens of routines that work well, so before I switch from VS to another compiler I look at what‘s going on. Well comes to thinking that C will be as fast as the assembler, it‘s inaccurate, even if the difference in this case will be small. But I had to write a solver a few years ago, I assure you that the QT version, then C were largely distanced by the assembler version.

"instantiated into assembly here" is a Clang error message. C++Builder‘s Clang-based compilers have caveats with using inline assembly, see Embarcadero‘s documentation:

Differences Between Clang-enhanced C++ Compilers and Previous-Generation C++ Compilers: Inline_Assembly

In particular:

"Clang-enhanced C++ compilers allow inline assembly with these caveats:

You cannot mix assembly with C++ code.
Do not touch the stack pointer (RSP).
The assembler must use the AT&T line-by-line syntax, not the more familiar block-of-Intel syntax. For more information, see GCC-Inline-Assembly-HOWTO.

http://docwiki.embarcadero.com/RADStudio/Rio/en/Clang-enhanced_C%2B%2B_Compilers

http://docwiki.embarcadero.com/RADStudio/en/Differences_Between_Clang-enhanced_C%2B%2B_Compilers_and_Previous-Generation_C%2B%2B_Compilers#Inline_Assembly

http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html




以上是关于delphi inline assembly {asm}的主要内容,如果未能解决你的问题,请参考以下文章

Delphi inline编译器优化问题

实现win10下Delphi 10.3和易语言 inline hook之GetLocalTime

3.4 ParameterMap and Inline Parameter

delphi 计算函数执行时间 TStopwatch

A non-collectible assembly may not reference a collectible assembly异常

Change Assembly Version in a compiled .NET assembly