You should be able to eliminate the null bytes by using a JMP
(or similar) instruction instead. For instance something like :
jmp $+8
writestring db "BBBB",0x0d, 0x0a
writer:
pop rsi
Produce the following machine code using nasm -f elf64
:
0000000000000000 <writestring-0x2>:
0: eb 06 jmp 8 <writer>
0000000000000002 <writestring>:
2: 42 rex.X
3: 42 rex.X
4: 42 rex.X
5: 42 rex.X
6: 0d .byte 0xd
7: 0a .byte 0xa
0000000000000008 <writer>:
8: 5e pop %rsi
You probably noticed that I didn't setup anything for a RET
instruction. But if you need such an instruction you can easily do the procedure prologue yourself.