| | |
write() error code
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 2
Reputation:
Solved Threads: 0
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.
Thanks in advance for any help
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.
asm Syntax (Toggle Plain Text)
.equ SYS_WRITE, 4 .equ ST_BR_WOUT_DESC, -8 .equ LINUX_SYSCALL, 0x80 ... #write 7 to file movl $SYS_WRITE, %eax movl ST_BR_WOUT_DESC(%ebp), %ebx movl $7, %ecx #convert to ascii addl $48, %ecx movl $1, %edx int $LINUX_SYSCALL
Thanks in advance for any help
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.
I've used a multitude of assemblers before but never LINUX.
This is untested so hope it works.
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.
Assembly Syntax (Toggle Plain Text)
.equ SYS_WRITE, 4 .equ ST_BR_WOUT_DESC, -8 .equ LINUX_SYSCALL, 0x80 ... tmp .long 0 #write 7 to file movl $SYS_WRITE, %eax # Linux SYSTEM - WRITE movl ST_BR_WOUT_DESC(%ebp), %ebx # Set ebx file Handle on stack? movl $7, %edx # binary digit 7 #convert to ascii addl $48, %edx # char = '7' = '0'+7 movl $tmp, %ecx # get memory address containing character mov %ecx,(%edx) # copy your character into it! movl $1, %edx # write a single byte # Sys_Write( uint ebx, const char *ecx, size_t edx ) ecx is suppose to be the pointer to the data, not the data itself! 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
•
•
Join Date: Jul 2009
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
asm Syntax (Toggle Plain Text)
#write 7(max) to file movl $SYS_WRITE, %eax #put 4 in %eax, syscall code for write() movl ST_BR_WOUT_DESC(%ebp), %ebx #file descriptor for our file, saved to the stack earlier movl $55, BUFFER #put the ascii code for 7 into our buffer movl $BUFFER, %ecx #put a pointer to our buffer in ecx movl $BUFFER_SIZE, %edx #put the length of our Buffer in edx int $LINUX_SYSCALL
Last edited by calef13; Jul 2nd, 2009 at 6:13 pm.
![]() |
Similar Threads
- Computer keeps crashing- error code help plz (Windows NT / 2000 / XP)
- Error 'not all code paths return a value' (C#)
- Error code COOD11CD (Windows NT / 2000 / XP)
- find out the error in my code (Java)
- javax.comm write error (Java)
- deleting registry key for error code 19 (Windows NT / 2000 / XP)
Other Threads in the Assembly Forum
- Previous Thread: protected mode switch
- Next Thread: Problem assembling with Nasm-IDE
| Thread Tools | Search this Thread |





