today i started to learn x86_64 Assembly with NASM on linux. I successful code a hello world program. Now i want to code another simple program. The program should ask the user for his name and then print "hi [name]". My problem is that the program doesn't ask for a name. If i start the program it doesn't print anything and stops without an error. Here is my Code:
section .data
msg1 db "Type in ur Name? ", 10
len1 equ $ - msg1 ; Get the Size of msg1
msg2 db "Hi, "
len2 equ $ - msg2 ;Get the Size of msg2
section .bss
name resb 16 ;16 Bytes for name
section .text
global _start
_start:
;Call Functions
call _printMsg1
call _getName
call _printMsg2
call _printName
mov eax, 60
mov ebx, 0
int 0x80
_printMsg1:
mov eax, 1
mov ebx, 1
mov ecx, msg1
mov edx, len1
int 0x80
ret
_printMsg2:
mov eax, 1
mov ebx, 1
mov ecx, msg2
mov edx, len2
int 0x80
ret
_printName:
mov eax, 1
mov ebx, 1
mov ecx, name
mov edx, 16 ; reserve 16 Bytes for the name
int 0x80
ret
_getName:
mov eax, 0 ;Syscall 0 = User Input
mov ebx, 0
mov ecx, name
mov edx, 16 ;16 Bytes for the name
int 0x80
ret
Thanks for your help!
EDIT: I found the problem. The program works if i replace the following registers with: eax to rax ebx to rdi ecx to rsi edx to rdx
Seems like i use the false registers.
mov eax, 4
to call thewrite
system call. – Barmarint 0x80
ABI instead ofsyscall
. You're using 64-bit call numbers but absolutely everything else is 32-bit. – Peter Cordes