using libc from nasm
From: Adam Bozanich (adambozanich_at_sbcglobal.net)
Date: 02/12/04
- Next message: Terje Mathisen: "Re: Divide by constant"
- Previous message: PlasmaDragon: "Re: Caching data"
- Next in thread: Frank Kotler: "Re: using libc from nasm"
- Reply: Frank Kotler: "Re: using libc from nasm"
- Reply: Ulf Andersson: "Re: using libc from nasm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 12 Feb 2004 20:38:23 +0000 (UTC)
Hi all. I am trying to learn asm with NASM on a FreeBSD system. I really need
to debug my programs while I learn, so I want to use printf. This is what I am
using to assemble and link:
nasm -f elf use_printf.asm
ld -s -o use_printf use_printf.asm -lc
but then when I run the program:
$./use_printf
/usr/libexec/ld-elf.so.1: /lib/libc.so.5: Undefined symbol "environ"
Can somebody see where I am going wrong? This is kindof holding me back. I
added the 'extern environ' and 'extern __progname' beause I get this otherwise:
/usr/lib/libc.so: undefined reference to `environ'
/usr/lib/libc.so: undefined reference to `__progname'
Here's what I have( I think I have commented out the bsd specific stuff... ):
extern printf
extern environ
extern __progname
section .data
mesg db 'the number is %d\n',0
mesglen equ $-mesg
errormesg db 'libc error',0ah,0
errormesglen equ $-errormesg
newline db 10
number dw 0x10
;kernel:
; int 80h
; ret
align 4
section .text
global _start
_start:
push dword number
push dword mesg
call printf
; error if eax < 1 ( we should have wrote some chars )
cmp eax , 0x1
jl .error
; use write() system call to print message
; push dword mesglen
; push dword mesg
; push dword 0x1 ; stdout
; mov eax , 0x4 ; 4 == write system call
; call kernel
; ; output a newline
; push dword 1
; push dword newline
; push dword 0x1
; mov eax , 0x4
; call kernel
; mov eax , 0x1 ; exit syscall number
; push dword 0x0 ; exit status
; call kernel
.error:
; push dword errormesglen
; push dword errormesg
; push dword 0x1
; mov eax , 0x4
; call kernel
; mov eax , 0x1
; push dword 0xff
; call kernel
- Next message: Terje Mathisen: "Re: Divide by constant"
- Previous message: PlasmaDragon: "Re: Caching data"
- Next in thread: Frank Kotler: "Re: using libc from nasm"
- Reply: Frank Kotler: "Re: using libc from nasm"
- Reply: Ulf Andersson: "Re: using libc from nasm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|