write() error code

Reply

Join Date: Jul 2009
Posts: 2
Reputation: calef13 is an unknown quantity at this point 
Solved Threads: 0
calef13 calef13 is offline Offline
Newbie Poster

write() error code

 
0
  #1
Jul 2nd, 2009
Hi,

I'm writing a small application which reads and writes to some files. MY problem is that when I write to the file in my program, I get an error, %eax is set to -14. strerror(-14) returns unknown error, and I was told on irc that posix write() doesn't return -14. As far as I can tell everything is fine with the syscall, I've triple checked everything, but it keeps failing, nothing is written to the file.

  1. .equ SYS_WRITE, 4
  2. .equ ST_BR_WOUT_DESC, -8
  3. .equ LINUX_SYSCALL, 0x80
  4.  
  5. ...
  6.  
  7. #write 7 to file
  8. movl $SYS_WRITE, %eax
  9. movl ST_BR_WOUT_DESC(%ebp), %ebx
  10. movl $7, %ecx
  11. #convert to ascii
  12. addl $48, %ecx
  13. movl $1, %edx
  14. int $LINUX_SYSCALL

Thanks in advance for any help
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: write() error code

 
0
  #2
Jul 2nd, 2009
Can you add more then that snippet. And add comments! That 80x86 assembler you're using is camouflaging the assembly code making it harder to read due to its abstraction methodology.
Last edited by wildgoose; Jul 2nd, 2009 at 5:30 pm. Reason: typo
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: write() error code

 
0
  #3
Jul 2nd, 2009
Been doing some research. You're using a Linux assembler that uses the AT&T syntax?

It uses a reverse encoding and different operands.

You're passing the character and not the address of the character to the file I/O.

  1. .equ SYS_WRITE, 4
  2. .equ ST_BR_WOUT_DESC, -8
  3. .equ LINUX_SYSCALL, 0x80 ...
  4.  
  5. tmp .long 0
  6.  
  7.  
  8. #write 7 to file
  9. movl $SYS_WRITE, %eax # Linux SYSTEM - WRITE
  10. movl ST_BR_WOUT_DESC(%ebp), %ebx # Set ebx file Handle on stack?
  11. movl $7, %edx # binary digit 7
  12.  
  13.  
  14. #convert to ascii
  15. addl $48, %edx # char = '7' = '0'+7
  16. movl $tmp, %ecx # get memory address containing character
  17. mov %ecx,(%edx) # copy your character into it!
  18.  
  19.  
  20. movl $1, %edx # write a single byte
  21.  
  22. # Sys_Write( uint ebx, const char *ecx, size_t edx )
  23. ecx is suppose to be the pointer to the data, not the data itself!
  24.  
  25. int $LINUX_SYSCALL

I've used a multitude of assemblers before but never LINUX.
This is untested so hope it works.
Last edited by wildgoose; Jul 2nd, 2009 at 5:57 pm. Reason: twiddle
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 2
Reputation: calef13 is an unknown quantity at this point 
Solved Threads: 0
calef13 calef13 is offline Offline
Newbie Poster

Re: write() error code

 
0
  #4
Jul 2nd, 2009
yeah I'm using GAS, GNU assembler which uses AT&T syntax.

You're right, I'm passing the number instead of a pointer, man I've missed how useless the error messages are in assembly thanks a lot that fixed the problem.

Below is the updated code for clarity. I have a buffer, of size 1 byte, which I used earlier in the program to read in a number.

  1. #write 7(max) to file
  2. movl $SYS_WRITE, %eax #put 4 in %eax, syscall code for write()
  3. movl ST_BR_WOUT_DESC(%ebp), %ebx #file descriptor for our file, saved to the stack earlier
  4. movl $55, BUFFER #put the ascii code for 7 into our buffer
  5. movl $BUFFER, %ecx #put a pointer to our buffer in ecx
  6. movl $BUFFER_SIZE, %edx #put the length of our Buffer in edx
  7. int $LINUX_SYSCALL
Last edited by calef13; Jul 2nd, 2009 at 6:13 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC