简体   繁体   English

如何从程序集nasm x86 linux 8086调用printf

[英]how to call printf from assembly nasm x86 linux 8086

I'm trying, unsuccessfully, to call printf from an assembly program as follows: 我正在尝试从汇编程序中调用printf ,但未成功,如下所示:

section .rodata
preffix: db "calc >",0
preffix_length: equ $-preffix

section .text
align 16
global main


extern printf

main:
  push preffix
  push preffix_length
  call printf
  ret

But I keep getting segmentation fault. 但我一直在分割错误。

I'm writing in Linux (ubuntu) for NASM assembly 80x86. 我正在Linux(ubuntu)中编写NASM程序集80x86。

You don't want to push the length - strings in C is just the address of the text with a zero byte to mark the end. 你不想推长度 - C中的字符串只是文本的地址,用零字节标记结尾。

You can use gdb to figure out where something like this crashes. 你可以使用gdb找出这样的东西崩溃的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM