//--------------------------------------------------------------- // out2file.s // // This demo shows the basic steps needed to create a file. // // to assemble: $ as out2file.s -o out2file.o // and to link: $ ld out2file.o -o out2file // // programmer: ALLAN CRUSE // written on: 26 MAR 2007 //--------------------------------------------------------------- .equ sys_EXIT, 1 .equ sys_WRITE, 4 .equ sys_OPEN, 5 .equ sys_CLOSE, 6 .equ S_ACCESS, 00600 .equ O_CREAT, 0100 .equ O_TRUNC, 01000 .equ O_WRONLY, 01 .section .data handle: .int -1 flags: .int O_CREAT | O_WRONLY | O_TRUNC access: .int S_ACCESS fname: .asciz "mycookie.txt" info: .ascii "Computer Science 210\n" .ascii "Spring 2007\n" .ascii "University of San Francisco\n" size: .int . - info .section .text _start: # open the file for writing mov $sys_OPEN, %eax lea fname, %ebx mov flags, %ecx mov access, %edx int $0x80 mov %eax, handle # write information to the file mov $sys_WRITE, %eax mov handle, %ebx lea info, %ecx mov size, %edx int $0x80 # close the file mov $sys_CLOSE, %eax mov handle, %ebx int $0x80 # terminate this program mov $sys_EXIT, %eax mov $0, %ebx int $0x80 .global _start .end