Quarg
May 25th, 2010, 05:25 AM
Hello again (if you've already seen my other post pertaining to this problem)
I have done some more research (maybe it could be called banging my head on a wall) into printing arguments from the command line in x86_64 assembly language using NASM syntax. this works:
section .data
section .bss
Text_file: resb 50
global _start
_start:
mov rsi, [rsp+8] ; Since the stack starts out with
; argc on top, then argv[0] this
; moves argv[0] into source index.
mov rdi, Text_file ; pointer to where we want to
; move the string
mov rcx, 6 ; how may times to we increment? 6
cld ; clear direction flag
rep movsb ; blast string at [rsp+8]to Text_file
mov rcx, Text_file ; The following prints out Text_file
mov rbx, 1
mov rdx, 6
mov rax, 4
int 80h
every time that works. It prints out the first argument. My question is, why, if I do this:
mov rax, 4 ;write to file linux syscall
mov rbx, 1 ; file descriptor - 1 for STDOUT, console.
mov rcx, [rsp+8] ;SHOULD move the pointer for argv[0] into rcx.
;rcx is the location to read from.
mov rdx, 5 ; size of buffer to read - 5 is good, doesn't
; matter yet.
int 80h ; call Linux in and have it do the dirty work.
It DOESN'T WORK! I simply do not get it - and I've spent the last hour on this problem. Any ideas as to what I'm doing wrong?
I have done some more research (maybe it could be called banging my head on a wall) into printing arguments from the command line in x86_64 assembly language using NASM syntax. this works:
section .data
section .bss
Text_file: resb 50
global _start
_start:
mov rsi, [rsp+8] ; Since the stack starts out with
; argc on top, then argv[0] this
; moves argv[0] into source index.
mov rdi, Text_file ; pointer to where we want to
; move the string
mov rcx, 6 ; how may times to we increment? 6
cld ; clear direction flag
rep movsb ; blast string at [rsp+8]to Text_file
mov rcx, Text_file ; The following prints out Text_file
mov rbx, 1
mov rdx, 6
mov rax, 4
int 80h
every time that works. It prints out the first argument. My question is, why, if I do this:
mov rax, 4 ;write to file linux syscall
mov rbx, 1 ; file descriptor - 1 for STDOUT, console.
mov rcx, [rsp+8] ;SHOULD move the pointer for argv[0] into rcx.
;rcx is the location to read from.
mov rdx, 5 ; size of buffer to read - 5 is good, doesn't
; matter yet.
int 80h ; call Linux in and have it do the dirty work.
It DOESN'T WORK! I simply do not get it - and I've spent the last hour on this problem. Any ideas as to what I'm doing wrong?