• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

delphiinlineassembly{asm}

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MATLAB入门学习-#5-M文件(MATLAB)程序基础发布时间:2022-07-18
下一篇:
delphi用API实现窗体半透明效果发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap