I am trying to use printf
to print the first character of the string str_1
to stdout in x86-assembly
within a 64bit
Ubuntu 20
environment, here is my attempt:
; nasm -f test.asm && gcc -m32 -o test test.asm.o
section .text
global main
extern printf
some_proc:
mov esi, str_1
mov eax, [esi]
push eax
push argv_str
call printf
pop eax
ret
main:
call some_proc
ret
section .data
str_1 db `three`
argv_str db `%c\n`
This outputs:
t
Segmentation fault (core dumped)
Expected stdout:
t
Why is this code resulting in segmentation fault and how do I modify the code to output the expected stdout?