나는 여기 Assembly - File Management을 가져온 튜토리얼의 간단한 "create prompt with file"코드를 작성하려고합니다. 하지만 매번 입력 할 때마다 터미널의 출력 문자열이 혼합되어 함께 잘립니다. 그리고 생성 될 파일도 섞여 있습니다.출력에 NASM 혼합 문자열
코드는 여기에 있습니다 : I 입력 "잭"
Masukkan nama Anda
Jack
ck
e telah dibuat
이
Masukkan nama Anda
Jack
File telah dibuat
되어야하는지 그리고 파일 이름이
경우 터미널이 같다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
Jack e telah dibuat
이
Jack
죄송합니다 어떻게해야
, 나는 총회에 새로운 해요. 이제 eax, ebx에 대한 편집을 계속하려고합니다. 내가 뭔가를 안다면 게시 할 것이다. 대단히 감사합니다!
업데이트 64 비트 어셈블리에 32 비트 코드를 사용하고있는 것처럼 보입니다. 그래서 대부분의 문법을 변경했습니다 (그러나 문제는 그렇지 않습니다). 최종 코드가 작동했습니다 (맨 아래에있는 사람 덕분에). 메모리 레이아웃을 감안할 때
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'에 한 문자 만 할당했습니다. 당신은 더 필요합니다. – Jester