I'm trying to make a simple "create file with prompt" code from the tutorial I fetched here Assembly - File Management. But everytime I input something, the output strings in the terminal will be mixed and cut together. And the file that would be created is mixed too.
Code is here:
section .data
Msg1: db 'Masukkan nama Anda ',0xa
Msg1ln equ $-Msg1
Name: db ' ', 0xa ; space characters
msg_done: db 'File telah dibuat ', 0xa
;msg_doneln equ $-msg_done
section .text
global _start
_start:
; Output 'Masukkan nama Anda '
mov eax, 4 ; write…
mov ebx, 1 ; to the standard output (screen/console)…
mov ecx, Msg1 ; the information at memory address prompt
mov edx, Msg1ln ; 19 bytes (characters) of that information
int 0x80 ; invoke an interrupt
; Accept input and store the user’s name
mov eax, 3 ; read…
mov ebx, 1 ; from the standard input (keyboard/console)…
mov ecx, Name ; storing at memory location name…
mov edx, 23 ; 23 bytes (characters) is ok for my name
int 0x80
;create the file
mov eax, 8
mov ebx, Name
mov ecx, 0777 ;read, write and execute by all
int 0x80 ;call kernel
mov [fd_out], eax
;write the message indicating end of file write
mov eax, 4
mov ebx, 1
mov ecx, msg_done
mov edx, 18
int 0x80
mov [fd_in], eax
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .bss
fd_out resb 1
fd_in resb 1
The terminal is like this if I input "Jack"
Masukkan nama Anda
Jack
ck
e telah dibuat
How it should be
Masukkan nama Anda
Jack
File telah dibuat
And the file name is
Jack e telah dibuat
How it should be
Jack
Sorry, I'm new to the Assembly. Now I'm still trying editing around the eax,ebx things. Will post if I know something. Great thanks!
Update It looks like I was using 32bit code for 64bit assembly. So I changed most of the syntax (But the problem is not this). Final code worked (thanks to that guy on the bottom).
section .data
Msg1: db 'Masukkan nama Anda',0xa
Msg1ln equ $-Msg1
Name: times 23 db ' ',0
msg_done: db 'File telah dibuat ', 0xa
;msg_doneln equ $-msg_done
fd dq 0
section .text
global _start
_start:
; Output 'Masukkan nama Anda '
mov rax, 1 ; write…
mov rdi, 0 ; to the standard output (screen/console)…
mov rsi, Msg1 ; the information at memory address prompt
mov rdx, Msg1ln ; 19 bytes (characters) of that information
syscall ; Interrupt buat 64bit Linux adalah syscall, sedangkan 32bit int 0x80
; Accept input and store the user’s name
mov rax, 0 ; read…
mov rdi, 1 ; from the standard input (keyboard/console)…
mov rsi, Name ; storing at memory location name…
mov rdx, 23 ; 23 bytes (characters) is ok for my name
syscall
;create the file
mov rax, 85
mov rdi, Name
mov rsi,777o ;Permission tipe data oktal -rwxrwxrwx
syscall
mov [fd], rax
;write the message indicating end of file write
mov rax, 1
mov rdi, 1
mov rsi, msg_done
mov rdx, 18
syscall
mov [fd], rax
mov rax, 60
mov rdi, 0
syscall
Name. You need more.