Segmentation Fault in Assembly Program Using AT&T Syntax and GNU Assembler

I've written a test program using AT&T syntax for use with GNU assembler. The program is supposed to print the value 1 using printf.
attachment 0
1 Reply
Marvee Amasi
Marvee Amasi5mo ago
I assemble and link the program with GCC using the following command:
gcc -o main main.s
gcc -o main main.s
So when I run the program using ./main, I get a segmentation fault . Debugging with gdb reveals that printf is not found. I've tried using .extern printf without success. Someone suggested I should store the stack pointer before calling printf and restore it before RET. Right now I'm unsure how to implement this in AT&T syntax. I'm not including any specific linker flags with GCC. Can anyone help me understand why I'm getting the segmentation fault and how to fix it? Also, if storing the stack pointer is necessary, how would I do that in AT&T syntax?
Want results from more Discord servers?
Add your server