Index: /trunk/filefigli.c
===================================================================
--- /trunk/filefigli.c	(revision 24)
+++ /trunk/filefigli.c	(revision 24)
@@ -0,0 +1,83 @@
+/* Copyright (C) 2012 by Mattia Monga <mattia.monga@unimi.it> */
+/* $Id$ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <limits.h>
+
+void lsofd(const char* name){
+        int i;
+        for (i=0; i<_POSIX_OPEN_MAX; i++){
+                struct stat buf;
+                if (fstat(i, &buf) == 0){
+                        printf("%s fd:%d i-node: %d\n", name, i, buf.st_ino);
+                }
+        }
+}
+
+main(){
+        pid_t pid;
+        int f,  off;
+        char    string[] = "Hello, world!\n";
+        
+        lsofd("padre (senza figli)");
+        printf("padre (senza figli) pipe *\n");
+        f = open("provaxxx.dat", O_CREAT|O_WRONLY|O_TRUNC, S_IRWXU);
+        if (f == -1){
+                perror("pipe");
+                exit(1);
+        }
+        lsofd("padre (senza figli)");
+        if (write(f, string, (strlen(string)+1)) != (strlen(string)+1) ){
+                perror("write");
+                exit(1);
+        }
+        
+        off = lseek(f, 0, SEEK_CUR);
+        printf("padre (senza figli) seek: %d\n", off);
+
+        printf("padre (senza figli) fork *\n");
+        if ( (pid = fork()) < 0){
+                perror("fork");
+                exit(1);
+        }
+        if (pid > 0){
+                lsofd("padre");
+                printf("padre close *\n");
+                printf("padre write *\n");
+                off = lseek(f, 0, SEEK_CUR);
+                printf("padre seek prima: %d\n", off);
+                if (write(f, string, (strlen(string))) != (strlen(string)) ){
+                        perror("write");
+                        exit(1);
+                }
+                lsofd("padre");
+                off = lseek(f, 0, SEEK_CUR);
+                printf("padre seek dopo: %d\n", off);
+                exit(0);
+        }
+        else {
+                lsofd("figlio");
+                printf("figlio close *\n");
+                printf("figlio write *\n");
+                off = lseek(f, 0, SEEK_CUR);
+                printf("figlio seek prima: %d\n", off);
+                if (write(f, string, (strlen(string))) != (strlen(string)) ){
+                        perror("write");
+                        exit(1);
+                }
+                lsofd("figlio");
+                off = lseek(f, 0, SEEK_CUR);
+                printf("figlio seek dopo: %d\n", off);
+                exit(0);
+        }
+}
+
+/* Local Variables: */
+/* compile-command: "make -k " */
+/* End: */
Index: /trunk/hello-mod.s
===================================================================
--- /trunk/hello-mod.s	(revision 24)
+++ /trunk/hello-mod.s	(revision 24)
@@ -0,0 +1,49 @@
+	.section	.rodata
+.LC0:
+	.string	"Hello world! (%d)\n"
+formato:                         /* la stringa di formato per la scanf */
+	.string "%d"      
+
+        .data
+x:                               /* una variabile x */
+        .int
+
+        .text
+	.globl	main
+	.type	main, @function
+main:
+.LFB0:
+	.cfi_startproc
+	pushl	%ebp
+	.cfi_def_cfa_offset 8
+	.cfi_offset 5, -8
+	movl	%esp, %ebp
+	.cfi_def_cfa_register 5
+	andl	$-16, %esp
+	subl	$32, %esp
+	push $x                  /* oppure: movl $x, 4(%esp) */
+        push $formato            /* oppure: movl $formato, (%esp) */
+	call scanf
+	subl $1, (x)             /* da 0 a x-1 */
+	movl	$0, 28(%esp)
+	jmp	.L2
+.L3:
+	movl	28(%esp), %eax
+	addl	$1, %eax
+	movl	%eax, 4(%esp)
+	movl	$.LC0, (%esp)
+	call	printf
+	movl	$1, (%esp)
+	call	sleep
+	addl	$1, 28(%esp)
+.L2:
+        movl (x), %eax          /* compara con x */
+	cmpl %eax, 28(%esp)
+	jle	.L3
+	movl	$0, (%esp)
+	call	exit
+	.cfi_endproc
+.LFE0:
+	.size	main, .-main
+	.ident	"GCC: (Debian 4.7.2-5) 4.7.2"
+	.section	.note.GNU-stack,"",@progbits
Index: /trunk/hello.s
===================================================================
--- /trunk/hello.s	(revision 23)
+++ /trunk/hello.s	(revision 24)
@@ -1,38 +1,38 @@
-.sect .text; .sect .rom; .sect .data; .sect .bss
-.extern _main
-.sect .text
-_main:
-push ebp
-mov ebp,esp
-push esi
-xor esi,esi
-I1_6:
-cmp esi,10
-jge I1_3
-mov edx,esi
-inc edx
-push edx
-push I_1
-call _printf
-pop ecx
-pop ecx
-push 1
-call _sleep
-pop ecx
-inc esi
-jmp I1_6
-I1_3:
-push 3
-call _exit
-pop ecx
-pop esi
-leave
-ret
-.sect .rom
-I_1:
-.data4	1819043144
-.data4	1870078063
-.data4	560229490
-.data4	1680156704
-.data4	2601
-.sect .text
+	.file	"hello.c"
+	.section	.rodata
+.LC0:
+	.string	"Hello world! (%d)\n"
+	.text
+	.globl	main
+	.type	main, @function
+main:
+.LFB0:
+	.cfi_startproc
+	pushl	%ebp
+	.cfi_def_cfa_offset 8
+	.cfi_offset 5, -8
+	movl	%esp, %ebp
+	.cfi_def_cfa_register 5
+	andl	$-16, %esp
+	subl	$32, %esp
+	movl	$0, 28(%esp)
+	jmp	.L2
+.L3:
+	movl	28(%esp), %eax
+	addl	$1, %eax
+	movl	%eax, 4(%esp)
+	movl	$.LC0, (%esp)
+	call	printf
+	movl	$1, (%esp)
+	call	sleep
+	addl	$1, 28(%esp)
+.L2:
+	cmpl	$9, 28(%esp)
+	jle	.L3
+	movl	$0, (%esp)
+	call	exit
+	.cfi_endproc
+.LFE0:
+	.size	main, .-main
+	.ident	"GCC: (Debian 4.7.2-5) 4.7.2"
+	.section	.note.GNU-stack,"",@progbits
