I’m new to assembly coding and I have a question about the null character in .data section.
I tested a few codes:
Code 1:
section .data
out: db "%s",10,0
mes1: db "a",0
mes2: db "b",0
section .text
extern printf
global main
main:
push rbp
mov rdi,out
mov rsi,mes1
mov rax,0
call printf
mov rdi,out
mov rsi,mes2
mov rax,0
call printf
pop rbp
mov rax,0
ret
Output is:
a
b
Code 2: changed the .data section to:
section .data
out: db "%s",10 ; no 0
mes1: db "a",0
mes2: db "b",0
Output is:
a
ab
a
Code 3: changed the .data section to:
section .data
out: db "%s",10,0
mes1: db "a"
mes2: db "b"
Output is:
ab
b
So what does the null character do?
I tried to debug it in pwndbg but I didn’t get anything interesting.
New contributor
Leo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.