I've written this code just to learn how to use gas assembler:
.code32
.section .data
values:
.int 1,2,3,4,5,6,7,8,9
output:
.asciz "current value %d"
.section .text
.globl _start
_start:
movl $10, %edi
loop:
movl values(,%edi,4),%eax
pushl %eax
pushl $output
call printf
addl $8, %esp
dec %edi
jnz loop
pushl $0
call exit
It uses two C lib functions (printf and exit). I'm on x64, but this code is 32bit, so I assembled using this command:
as --32 -o test.o test.asm
It looks like it produce a valid obj file. The problem is that I'm not able to link this file...
I use this command:
ld -dynamic-linker /lib/ld-linux.so.2 -lc -o test test.o
but it says that the arch is not compatible, so I've tried:
ld -dynamic-linker /lib/ld-linker.so.2 -lc -o test test.o -melf_i386
but then it says:
ld: skipping /usr/lib64/libc.so not compatible -lc
How should I link that obj file ? Many thanks for the help!