|
From: Frank K. <fbk...@zy...> - 2009-08-18 17:22:57
|
Holger Hanrath wrote:
> Hi all,
>
> i want to write 3 bytes of argv[0] on stdout but it doesn't work.
> Return code -14 (EFAULT Bad address). Am i missing something here?
>
> System is archlinux 2009.08 x86_64 kernel 2.6.31-rc6
> nasm 2.05.01 Binutils 2.19.1.20090418
>
>
>
> stdout equ 1
> write equ 4
> exit equ 1
>
> section .text
> global _start
> _start:
> pop rax ; rax = argc
> pop rax ; rax = argv[0]
>
> mov rdx, 3 ; write 3 bytes
> mov rcx, rax ; rcx = rax = argv[0]
> mov rbx, stdout
> mov rax, write
> int 0x80
>
> mov rbx, 0
> mov rax, exit
> int 0x80
64-bit does it a "bit" differently (from the late and sorely missed
Chuck Crayne:
section .data
string1 db "Hello World!",10,0
section .text
global _start
_start:
; calculate the length of string
mov rdi, string1
mov rcx, -1
xor al,al
cld
repnz scasb
; place the length of the string in RDX
mov rdx, -2
sub rdx, rcx
; print the string using write() system call
mov rsi, string1
push 0x1
pop rax
mov rdi,rax
syscall
; exit from the application here
xor rdi,rdi
push 0x3c
pop rax
syscall
That won't do what you want, of course, but will give you an idea which
registers are used. (the push/pop is just shorter - probably want to use
"-Ox" to use it) I assume the stack is set up the same for 64-bit as for
32-bit(?). Let us know how it works - 64-bit examples are in short
supply, still...
Best,
Frank
|