//---------------------------------------------------------------- // tty2file.s // // This program creates a file (named 'tty2file.dat') in the // current directory and writes this task's 'struct termios' // data-structure for the standard input device to that file // so that we might conveniently examine this data-structure // with our 'fileview' utility-program. That program allows // viewing of binary files in several (hexadecimal) formats, // which helps us determine which memory-offsets to use when // we want to modify specific flag-bits or array-bytes in an // assembly language application (such as in our Project 3). // // assemble using: $ as tty2file.s -o tty2file.o // and link using: $ ld tty2file.o -o ttyfile // // programmer: ALLAN CRUSE // written on: 18 APR 2006 //---------------------------------------------------------------- # manifest constants .equ STDIN, 0 .equ TCGETA, 0x5401 .equ sys_exit, 1 .equ sys_write, 4 .equ sys_creat, 8 .equ sys_close, 6 .equ sys_ioctl, 54 .section .data fname: .asciz "tty2file.dat" # the filename string fmode: .int 0666 # the file-permissions fsize: .int 36 # the file's length handle: .int -1 # the file's 'handle' .section .bss tty: .space 36 # struct termios data .section .text _start: # get the 'termios' data-structure mov $sys_ioctl, %eax # system-call ID-number mov $STDIN, %ebx # device-file ID-number mov $TCGETA, %ecx # ioctl function-ID lea tty, %edx # address of buffer int $0x80 # enter Linux kernel # open our output-file for writing mov $sys_creat, %eax # system-call ID-number lea fname, %ebx # address of name string mov fmode, %ecx # file's access-mode int $0x80 # enter Linux kernel mov %eax, handle # save the file's handle # check for file-creation error cmpl $-1, handle # was file created? je exit # no, we cannot proceed # write data-structure to the file mov $sys_write, %eax # system-call ID-number mov handle, %ebx # the file's 'handle' lea tty, %ecx # address of buffer mov $36, %edx # the buffer's size int $0x80 # enter Linux kernel # close the file (to "commit" its data) mov $sys_close, %eax # system-call ID-number mov handle, %ebx # the file's 'handle' int $0x80 # enter Linux kernel exit: # terminate this program mov $sys_exit, %eax # system-call ID-number mov $0, %ebx # value for 'exit-code' int $0x80 # enter Linux kernel .global _start # makes entry-point visible .end # no more lines to assemble