发新话题
打印

[讨论]如何在UNIX-nasm下调用C标准库函数?

[讨论]如何在UNIX-nasm下调用C标准库函数?

议题作者:llehotnwod  
信息来源:邪恶八进制信息安全团队(www.eviloctal.com

我写了如下:
复制内容到剪贴板
代码:
%include   'system.inc'

section .data
myint     dw  1234
mystring   db  &#39;This is number -> %d <- should be 1234&#39;,10,0

section .bss

section .text
global  _start
_start:
   extern  _printf
   ;and then, further down...
   push   word[myint]
   push   word   mystring
   call   _printf
   add sp,byte 8

   xor    eax,   eax
   push   eax
   sys.exit;;;;;;;;;;是个宏,在system.inc里面
不知道怎么链接,makefile如下,但make时报错
复制内容到剪贴板
代码:
asm:aa.o
   ld -s -o asm aa.o
aa.o:hi.asm system.inc
   nasm -f elf hi.asm -o aa.o
报错信息如下:
复制内容到剪贴板
代码:
make
ld -s -o asm aa.o
aa.o(.text+0xc): In function `_start&#39;:
: relocation truncated to fit: R_386_16 .data
aa.o(.text+0xf): In function `_start&#39;:
: undefined reference to `_printf&#39;
*** Error code 1

TOP

发新话题