码迷,mamicode.com
首页 > Windows程序 > 详细

delphi inline assembly {asm}

时间:2020-05-14 12:45:52      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:art   lib   anything   before   block   tac   extra   one   rap   

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}

标签:art   lib   anything   before   block   tac   extra   one   rap   

原文地址:https://www.cnblogs.com/marklove/p/12887746.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!