osx - Open and write to file in assembly on mac -


i'm learning 32 bit assembly on mac, , i've have been trying write file on desktop. used code:

global _start section .data path:   db  "/users/jackliu/desktop/test.txt",0 string: db  "hello",0 .len:   equ $ - string  section .text  _start: mov eax, 5 push dword 2 push dword path sub esp, 8 int 0x80 add esp, 16 mov ebx, eax  mov eax, 4 push dword string.len push dword string push dword ebx sub esp, 4 int 0x80 add esp, 16  mov eax, 1 push 0 sub esp, 12 int 0x80 

the file empty , exists on desktop. after running it, doesn't change file @ all.

is there wrong code?

on mac os int 0x80 open system call is:

5 aue_open_rwtc { int open(user_addr_t path, int flags, int mode); }

your code passes 2 parameters:

mov eax, 5       ; open system call = 5 push dword 2     ; read/write flag push dword path  ; path sub esp, 8       ; alignment int 0x80 

since opening existing file specify mode of 0 third parameter. code this:

mov eax, 5       ; open system call = 5 push dword 0     ; mode = 0 push dword 2     ; read/write flag push dword path  ; path sub esp, 4       ; alignment int 0x80 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -