Hi,
I wanna do for some learning reasons a little cat replacement. But in order to show a file on a screen I first wanna get out its size , so that I know how big the buffer needs to be.
I wanna do this with the sys_stat call. But before I try to get out juts the size from all this infos sys_stat gives I tried to print all infos of sys_stat on the screen. So I wrote this here:
section .bss

struc stat

.st_dev:        resd 1 
.st_ino:        resd 1
.st_mode:      resw 1
.st_nlink:      resw 1
.st_uid:        resw 1
.st_gid:        resw 1
.st_rdev:      resd 1
.st_size:      resd 1
.st_blksize:    resd 1
.st_blocks:    resd 1
.st_atime:      resd 1
.st_atime_nsec: resd 1
.st_mtime:      resd 1
.st_mtime_nsec: resd 1
.st_ctime:      resd 1
.st_ctime_nsec: resd 1
.__unused4:    resd 1
.__unused5:    resd 1

endstruc

section .text
global _start

_start:
nop
pop ebx
pop ebx
pop ebx
mov eax,106
mov ecx, stat
int 80h
mov eax,4
mov ebx,1
mov ecx,stat
mov edx,100
int 80h
mov eax,1         
mov ebx,0           
int 80h


But I get no output. Nothing happens. And when I debug it I can see an error code 0xfffffff2 in eax after the sys_stat call. B ut I don't know why :( Can u help me?

System: Ubuntu (Linux), 32bit, Compiler: nasm.


greets
Posted on 2007-01-12 09:08:49 by Adnarim
After declaring structure prototype you need to create an instance of it and then reference the instance and not the prototype (currently ecx points to null location). I am not familiar with NASM very well, but I think something like 'mystat resb stat_size' should work.

Also before printing data to stdout it should be converted to ascii. Search the board for "to ascii" or somethin like that.
Posted on 2007-01-12 20:07:16 by arafel
He is right, I am familiar with nasm and can help
; usefull macro
%define sizeof(x) x %+ _size

struc STAT
...
endstruc

segment .bss
stat: resb sizeof(STAT) ; nasm is case sensitive, so 'stat' is different from 'STAT'

segment .text
_start: ; no changes
Posted on 2007-01-13 04:36:02 by sapero
Hi thanks for your help :D
That stat: resb sizeof(STAT) ; seems to work, is at least compiling without any errors. The output is this here: *???????E?f?E?f?E what should be the size of an other little app. But I think is like you say  Arafel that  I have to convert it to ascii. But all the explanations I find here are not with the nasm synthax and I'm stuck with that... has someone a good nasm example or are there even macros to do this job?


greets
Posted on 2007-01-13 06:23:00 by Adnarim