This question already has an answer here:
; NASM
push 30 ; '0'
mov rax, 4 ; write
mov rbx, 1 ; stdout
mov rcx, rsp ; ptr to character on stack
mov rdx, 1 ; length of string = 1
int 80h
The code above does not print anything to stdout. It works when i give it a ptr to a character in section .data
. What am i doing wrong?
30 decimal is the code of the ASCII "record separator". Whatever that is, it's probably not a printable character.
30 hexadecimal (30h or 0x30 in NASM parlance), on the other hand, is the code of the ASCII "0".
Also, you need to use the 64-bit ABI.
amd64
uses a different method for system calls thanint 0x80
, although that might still work with 32-bit libraries installed, etc. Whereas onx86
one would do:on
amd64
one would instead do this:For what you want to do, consider the following example: