Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error in backend: 32-bit absolute addressing is not supported in 64-bit mode

Hi I'm working on ASM intel_syntax noprefix on a mac using gcc, for some reason I keep getting this error in backend: 32-bit absolute addressing is not supported in 64-bit mode Does this has to do with the variables, at the moment is been use on 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);
}
like image 389
Miguel Guerra Avatar asked Mar 07 '16 01:03

Miguel Guerra


1 Answers

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.

like image 191
Jester Avatar answered Oct 27 '22 04:10

Jester