This is the code (rid of most comments '#' for readability. "..._nude.s" in example namefile refers to this):
1 #PURPOSE: This program is to demonstrate how to call printf
2
3 .section .data
4
5 firststring:
6 .ascii "Hello! % is a %s who loves the number %d\n\0"
7 name:
8 .ascii "Jonathan\0"
9 personstring:
10 .ascii "person\0"
11 numberloved:
12 .long 3
13
14 .section .text
15 .globl _start
16 _start:
17 pushl numberloved #This is the %d
18 pushl $personstring #This is the second %s
19 pushl $name #This is the first %s
20 pushl $firststring #This is the format string in the prototype
21 call printf
22
23 pushl $0
24 call exit
$ as printf-example_nude.s -o printf-example_nude.o
$ ld printf-example_nude.o -o printf-example_nude -lc -dynamic-linker /lib/ld-linux.so.2
$ ./printf-example_nude
zsh: segmentation fault (core dumped) ./printf-example_nude
(As we can see and i followed the assembly/linking instructions from the book:
- Assembly went well.
- Linking went well.
- Execution failed. Machine: Linux (Debian) 32-bit.)
Any idea? Thank you.