In linux you can print something using the system call number 4:
mov eax,4 ;system call number
mov ebx,0 ;file descriptor
mov ecx,msg ;adress of message in data segment
mov edx,length ;length of message
But, How do you print something from stack segment?
I tried this:
push 'H'
push 'e'
push 'l'
push 'l'
push 'o'
push ' '
push 'w'
push 'o'
push 'r'
push 'l'
push 'd'
mov eax,4 ;system call number
mov ebx,0 ;file descriptor
mov ecx,ebp ;adress of message
mov edx,11 ;length of message
But doesn't print anything.
EDIT: I made some changes to my code and now it is so:
section .data
msg: db "Hola mundo",0Ah
ok: db "OK",0Ah
section .text
global _start
_start:
push 'leH'
push 'w ol'
push 'dlro'
mov eax,4 ;system call number
mov ebx,1 ;file descriptor
mov ecx,esp ;adress of message in data segment
mov edx,11 ;length of message
mov eax,1
xor ebx,ebx ;same as move ebx,0 but better
int 0x80
EDIT 2 (still not working)
section .data
msg: db "Hello world",0Ah
section .text
global _start
_start:
push 'leH'
push 'w ol'
push 'dlro'
mov eax,4 ;system call number
mov ebx,1 ;file descriptor
mov ecx,esp ;adress of message in data segment
mov edx,11 ;length of message
int 0x80
mov eax,1
xor ebx,ebx ;same as move ebx,0 but better
int 0x80
Responding to the comment, I assemble and compile with:
nasm -f elf64 hello.asm && ld hello.o && ./a.out
I'm working in Ubuntu 64-bit Linux.