Öffne eine Datei aus dem Kommandozeilenargument
Ich versuche, ein Assembly-Programm zu erstellen, das eine in der Befehlszeile angegebene Datei erstellt (argv [1]). Es funktioniert einwandfrei, wenn die Zeichenfolge bereits in gespeichert ist, aber wenn ich es so ausführe, wie es ist, wenn der Dateiname nicht nach rbx verschoben wurde, funktioniert es einwandfrei.
section .text
global _start
_start:
; Equivalent to mov rsp, [rsp+8]
pop rbx; argc
pop rbx; argv[0]
pop rbx; argv[1]
mov rax, 8
;mov rbx, file_name ; Commented out
mov rcx, 0744
syscall
; Exit
mov rax, 1
mov rbx, 0
syscall
section .data
file_name db'file.txt'
Ich habe das auch versucht vonHie und mir ist jetzt klar, dass dies ein Sprung zum Beenden ist, obwohl argc 2 ist, aber ich habe es trotzdem erfolglos versucht:
pop rcx
cmp rcx, 2
jne exit
add rsp, 8
pop rbx
mov rax, 8
mov rcx, 0744
syscall
Wie kann ich das beheben?
Edit 1:
Auf 64-Bit-Systemaufrufe umgestellt. Hier ist meine Hallo Welt Praxis:
section .text
global _start
_start:
mov rax, 1
mov rdi, 1
mov rsi, string
mov rdx, strlen
syscall
; Exit
mov rax, 60
mov rbx, 0
syscall
section .data
string db 'Hello, World!', 10
strlen equ $ - string
Jetzt mit Datei erstellen:
section .text
global _start
_start:
mov rax, 85
mov rdi, file_name
mov rsi, 0744
syscall
; Exit
mov rax, 60
mov rbx, 0
syscall
section .data
file_name db 'File.txt'
Und schließlich mit Dateiargumenten:
section .text
global _start
_start:
pop rbx
pop rbx
pop rbx
mov rdi, rbx
mov rax, 85
mov rsi, 0744
syscall
; Exit
mov rax, 60
mov rbx, 0
syscall