Je suis en train de faire un simple "créer un fichier avec invite" code du tutoriel que j'ai récupéré ici Assembly - File Management. Mais chaque fois que je saisis quelque chose, les chaînes de sortie dans le terminal seront mélangées et coupées ensemble. Et le fichier qui serait créé est également mélangé.NASM chaîne mixte dans la sortie
codeest ici:
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
Le terminal est comme ça si je l'entrée "Jack"
Masukkan nama Anda
Jack
ck
e telah dibuat
Comment ça devrait être
Masukkan nama Anda
Jack
File telah dibuat
Et le nom du fichier est
Jack e telah dibuat
Comment ça devrait être
Jack
Désolé, je suis nouveau à l'Assemblée. Maintenant, je suis encore en train d'essayer d'éditer autour des choses eax, ebx. Publiera si je sais quelque chose. Un grand merci!
Mise à jour Il semble que j'utilisais du code 32 bits pour l'assemblage 64 bits. J'ai donc changé la plupart de la syntaxe (mais le problème n'est pas celui-ci). Le code final a fonctionné (merci à ce gars en bas).
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
Vous avez seulement alloué assez pour un seul caractère à 'Name '. Tu as besoin de plus. – Jester