Assembly language > Assembly discussions

nested __asm

(1/4) > >>

czerny:
Hi,

I have to compile a package which  uses the following to convert a double to int:


--- Code: ---int main(void)
{
int i;
double num = 5.0;

__asm { __asm fld num   __asm fistp i}

return 0;
}

--- End code ---

This should be MS compatible.

In PellesC both is allowed, eiter an __asm  in front of a inline block or __asm in front of each assembly instruction, but both simultaneously is not working.

Is this a known difference to MS or should this treated as a bug and corrected?

czerny

Bitbeisser:
Why would you use the __asm prefix on a single instruction when you are already in an __asm {} block?  ???

Sorry, that just doesn't make any sense to me...  :-\

Ralf

czerny:
This code is not mine. It is used in lua 5.2. Don't know if others write it the same way or not.

czerny

Vortex:
Hi czerny,

Bitbeisser is right. You should avoid multiple __asm prefixes. A single __asm {} block is much easy to type and read :


--- Code: ---#define WIN32_LEAN_AND_MEAN
#include <windows.h>

char *szUpper(char *text)
{
__asm{
mov ecx,1
mov eax,text
sub eax,ecx

@repeat:

add eax,ecx
cmp BYTE PTR [eax],0
je @end
cmp BYTE PTR [eax],97
jb @repeat
cmp BYTE PTR [eax],122
ja @repeat
sub BYTE PTR [eax],32
jmp @repeat

@end:
}

return text;
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
char msg[]="inline assembly programming";
MessageBox(0,szUpper(msg),"Hello!",MB_OK);
return 0;
}

--- End code ---

Stefan Pendl:
Since you are using the open source scripting language Lua, have you asked the Lua development team, why they coded it this way?

In the end you could always change the line to
--- Code: ---#ifndef _POCC_
__asm { __asm fld num   __asm fistp i}
#else
__asm {
   fld num
   fistp i
}
#endif

--- End code ---

The reason could be that they wanted to avoid multiple line ASM code, so they used this way.

Navigation

[0] Message Index

[#] Next page

Go to full version