Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Can you help me get my Hello World program to work?


Hi All

I am just learning how to program in assembler. I am using 64 bit Mepis 8.5 on an AMD Athlon 3200+ PC.

I cannot get my basic environment to work to assemble and link a Hello World program. I think it is something to do with 32 bit vs 64 bit and/or perhaps something to do with being on an AMD processor.

I have posted my various attempts below.

Can anybody help please and give me something else to try? Hopefully it is something simple but I do not know where to look.

Best wishes

John

#test1.s Simple printf call and exit
# System Mepis 8.5
# AMD 64 3200+

# as -o test1.o test1.s
# test1.s: Assembler messages:
# test1.s:33: Error: suffix or operands invalid for `push'
# test1.s:36: Error: suffix or operands invalid for `push'

# Error line numbers will not match now. But they refer to the pushl statements.
# Conclusion: May need to assemble 32 bit.
# Thoughts: Not sure why pushl is not compatible with 64 bit.


# as --32 -o test1.o test1.s # assembles no visible errors
# Conclusion: Looks OK

# ld -dynamic-linker /lib/ld-linux.so.2 -o test1 -lc test1.o
# ld: i386 architecture of input file `test1.o' is incompatible with i386:x86-64 output
# Thoughts: OK, cannot mix 32 and 64. Change the output?


# ld -dynamic-linker /lib/ld-linux.so.2 -mi386linux -o test1 -lc test1.o
# ld: skipping incompatible /usr/bin/../lib/libc.a when searching for -lc
# ld: cannot find -lc
# Thoughts: Linked OK. But cannot find 32 bit libc library? Or AMD compatible libc?
# Is this the correct output format?

# ld -V
# GNU ld (GNU Binutils for Debian) 2.18.0.20080103
# Supported emulations:
# elf_x86_64
# elf_i386
# i386linux

# Thoughts: Perhaps try the 64 bit loader? Perhaps it is smarter.
# ld -dynamic-linker /lib/ld-linux-x86-64.so.2 -mi386linux -o test1 -lc test1.o
# ld: skipping incompatible /usr/bin/../lib/libc.a when searching for -lc
# ld: cannot find -lc
# Conclusions: No improvement.

# Thoughts: Try and improve linker search? Only one other libc on the system in /emul/ia32-linux/
# ld -dynamic-linker /lib/ld-linux-x86-64.so.2 -L/emul/ia32-linux/lib -mi386linux -o test1 -lc test1.o
# ld: skipping incompatible /usr/bin/../lib/libc.a when searching for -lc
# ld: cannot find -lc
# Conclusions: Run out of ideas. I need help.

# Thoughts: Switch back to the original loader.
# ld -dynamic-linker /lib/ld-linux.so.2 -L/emul/ia32-linux/lib -melf_i386 -o test1 -lc test1.o
# ld: skipping incompatible /usr/bin/../lib/libc.so when searching for -lc
# ld: skipping incompatible /usr/bin/../lib/libc.a when searching for -lc
# Thoughts: At least it is looking for a dynamic library.

# Thoughts: Try the 64 bit loader with elf_i386 output
# ld -dynamic-linker /lib/ld-linux-x86-64.so.2 -L/emul/ia32-linux/lib -melf_i386 -o test1 -lc test1.o
# ld: skipping incompatible /usr/bin/../lib/libc.so when searching for -lc
# ld: skipping incompatible /usr/bin/../lib/libc.a when searching for -lc

# Thoughts: ?
# ld -dynamic-linker /lib/ld-linux-x86-64.so.2 -L/emul/ia32-linux/lib -mi386linux -o test1 -lc test1.o
# ld: skipping incompatible /usr/bin/../lib/libc.so when searching for -lc
# ld: skipping incompatible /usr/bin/../lib/libc.a when searching for -lc
# Conclusion: Help!

# ld -dynamic-linker /lib/ld-linux-so.2 -L/emul/ia32-linux/lib -melf32-i386 -o test1 -lc test1.o

#/emul/ia32-linux/lib/libc-2.7.so

.section .datatext
output:
.asciz "Hello World!
"

.section .text
.globl _start
_start:
pushl $output
call printf
addl $8, %esp
pushl $0
call exit





Sign In or Register to comment.