F
Hallo,
Ich möchte eine C-Funktion die einen reinen Assembler-Body besitzt so übersetzen, dass Sie mit GCC kompiliert werden kann. Mein Problem dabei ist, dass GCC by default AT&T-Syntax für den Inline-Assembler verwendet. Da ich weder Zeit noch Lust dazu habe mir die AT&T Syntax anzueignen habe ich folgendes versucht:
1. Den Compiler-Parameter -masm=intel zu werden (außer merkwürdigen Compiler-Errors hat das nichts gebracht)
2. Den Code so zu übersetzen
// MSVC 9.0
char* UpperCase(
char* Src,
char* Dest
)
{
__asm
{
[asm] push esi
push edi
mov esi, BYTE PTR [ebp+8] ; Src
lea edi, BYTE PTR [ebp+12] ; Dest
nextchar:
lodsb ; load byte from ESI to al
cmp al, 0x61
jb done ; below 'a' ?
cmp al, 0x7A
ja done ; above 'z' ?
xor al, 0x20 ; set bit 6
done:
stosb
cmp [esi], 0
je end
loop nextchar
end:
mov eax, [ebp+12]
pop edi
pop esi[/asm]
}
}
// GCC
char* UpperCase(
char* Src,
char* Dest
)
{
asm (".intel_syntax noprefix\n");
asm ("push esi\n");
asm ("push edi\n");
asm ("mov esi, BYTE PTR [ebp+8]\n");
asm ("mov edi, BYTE PTR [ebp+12]\n");
asm ("nextchar:\n");
asm ("lodsb\n");
asm ("cmp al, 0x61\n");
asm ("jb done\n");
asm ("cmp al, 0x7A\n");
asm ("ja done\n");
asm ("xor al, 0x20\n");
asm ("done:\n");
asm ("stosb\n");
asm ("cmp [esi], 0\n");
asm ("je end\n");
asm ("loop nextchar\n");
asm ("end:\n");
asm ("pop edi\n");
asm ("pop esi\n");
asm ("mov eax, [ebp+12]\n");
asm (".att_syntax noprefix");
}
Leider bekomme ich nun immer die Fehlermeldungen:
Error: '%esi' not allowed with 'movb'
Error: '%edi' not allowed with 'movb'
Warning: using '%al' instead of '%eax'due to 'b' suffix
Error: '%esi' not allowed with 'movb'
Error: '%edi' not allowed with 'movb'
Error: symbol 'nextchar' is already defined
Error: symbol 'done' is already defined
Error: symbol 'end' is already defined
Warning: using '%al' instead of '%eax'due to 'b' suffix
... die ich zwar allesamt nachvollziehen könnte, aber nur WENN ich denn die entsprechenden Instruktionen verwenden WÜRDE.
Ich zähle auf eure Unterstützung Irgendjemand arbeitet doch bestimmt mit GCC^^.
PS:
Es geht hier nicht um den Code. Den kann ich auch in C schreiben, sondern ums Prinzip. Wie verwende ich mit GCC Intel-Syntax?