Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X86 IA32 Assembly, Bad Register name

Tags:

assembly

I am quite new to assembly so forgive me if I am asking a bad question. I am using a GCC compiler on a Linux machine to run my codes. So I have a simple hello world C code that works perfectly and then I use this command to turn it into assembly:

gcc -S hello.s

When I run it using this command, I get a few bad register name errors:

gcc -m32 hello.s -o hello

Error messages I get are:

hello.s:11: Error: bad register name '%rbp'
hello.s:14: Error: bad register name '%rsp'
hello.s:19: Error: bad register name '%rbp'

C code:

#include <stdio.h>
int main(void)
{     

printf("hello, world\n");   
return 0;
}

Assembly:

    .file   "hello.c"
    .section    .rodata
.LC0:
    .string "hello, world"
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    pushq   %rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    movq    %rsp, %rbp
    .cfi_def_cfa_register 6
    movl    $.LC0, %edi
    call    puts
    movl    $0, %eax
    popq    %rbp
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size   main, .-main
    .ident  "GCC: (Debian 4.7.2-5) 4.7.2"
    .section    .note.GNU-stack,"",@progbits

Apologies for the trouble and many thanks in advance for any feedback.

like image 891
Yozuru Avatar asked Oct 12 '25 17:10

Yozuru


1 Answers

%rxx registers are only available in x86_64, not in ia32. Use -m64 when executing gcc.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!