1
votes

I'm trying, unsuccessfully, to call printf from an assembly program as follows:

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.

1

1 Answers

4
votes

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.

You can use gdb to figure out where something like this crashes.