Reputation: 165
I'm working on ASM intel_syntax noprefix on a mac using gcc, and for some reason I keep getting this error in backend: 32-bit absolute addressing is not supported in 64-bit mode
Does this have something to do with the variables, since, at the moment, I've been using the ASM inline?
Here's my code:
#include <stdio.h>
char c, b;
int main() {
printf("Give me letter: ");
scanf(" %c", &c);
_
_asm( ".intel_syntax noprefix;"
"xor eax, eax;" // clear eax
"mov al, byte ptr [c];" // save c in eax
"cmp eax, 65;" // eax ? "A"
"jl Fin;" // eax < "A" -> Fin
"cmp eax, 90;" // eax ? "Z"
"jg UpC;" // eax >= Z -> Up Case
"add eax, 32;" // make low case
"jmp Fin;" // -> Fin
"UpC: cmp eax, 97;" // eax ? "a"
"jl Fin;" // eax < "a" -> Fin
"cmp eax, 122;" // eax ? "z"
"jg Fin;" // eax > "z" -> Fin
"sub eax, 32;" // make Up Case
"Fin: mov byte ptr [b], al;" // save res in b
".att_syntax");
printf("Case changed : %c\n", b);
}
Upvotes: 8
Views: 8159
Reputation: 58762
Yes, as the error says, on osx you are not allowed to use absolute references which byte ptr [c]
assembles to. As a workaround you could try byte ptr c[rip]
.
Note that it is very bad practice to switch syntax in inline assembly block, you should use -masm=intel
compiler switch. Also, gcc inline asm is not supposed to be used like that, normally you use the constraint mechanism to reference arguments.
Upvotes: 6