ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 어셈블리어 - Linux
    Platform/File(장치 IO) 2013. 5. 13. 23:18

    .section .data


    .equ SYS_OPEN, 5

    .equ SYS_WRITE, 4

    .equ SYS_READ, 3 

    .equ SYS_CLOSE, 6

    .equ SYS_EXIT, 1


    .equ O_RDONLY, 0

    .equ O_CREAT_WRONLY_TRUNC, 03101


    .equ STDIN, 0

    .equ STDOUT, 1

    .equ STDERR, 2


    .equ LINUX_SYSCALL, 0x80


    .equ END_OF_FILE, 0


    .section .bss

    .equ BUFFER_SIZE, 500

    .lcomm BUFFER_DATA, BUFFER_SIZE


    .section .text


    .equ ST_SIZE_RESERVE, 8

    .equ ST_FD_IN, -4 # input file descriptor

    .equ ST_FD_OUT, -8 # output file descriptor


    .equ ST_ARGC, 0 #Number of arguments ; argc

    .equ ST_ARGV_0, 4 #Name of program ; argv[0]

    .equ ST_ARGV_1, 8 #Input file name ; argv[1]

    .equ ST_ARGV_2, 12 #Output file name ; argv[2]


    .globl _start

    _start:

    movl %esp, %ebp

    subl $ST_SIZE_RESERVE, %esp


    #open_files:

    #open_fd_in:

    movl $SYS_OPEN, %eax

    movl ST_ARGV_1(%ebp), %ebx

    movl $O_RDONLY, %ecx

    movl $0666, %edx

    int $LINUX_SYSCALL

    #store_fd_in:

    movl %eax, ST_FD_IN(%ebp)

    #open_fd_out:

    movl $SYS_OPEN, %eax

    movl ST_ARGV_2(%ebp), %ebx

    movl $O_CREAT_WRONLY_TRUNC, %ecx

    movl $0666, %edx

    int $LINUX_SYSCALL

    #store_fd_out:

    movl %eax, ST_FD_OUT(%ebp)


    read_loop_begin:

    movl $SYS_READ, %eax

    movl ST_FD_IN(%ebp), %ebx

    movl $BUFFER_DATA, %ecx

    movl $BUFFER_SIZE, %edx

    int $LINUX_SYSCALL

    cmpl $END_OF_FILE, %eax

    jle end_loop

    #continue_read_loop:

    pushl $BUFFER_DATA

    pushl %eax

    call convert_to_upper

    popl %eax

    addl $4, %esp

    #addl $8, %esp

    movl %eax, %edx

    movl $SYS_WRITE, %eax

    movl ST_FD_OUT(%ebp), %ebx

    movl $BUFFER_DATA, %ecx

    #movl $BUFFER_SIZE, %edx

    int $LINUX_SYSCALL

    jmp read_loop_begin

    end_loop:

    movl $SYS_CLOSE, %eax

    movl ST_FD_OUT(%ebp), %ebx

    int $LINUX_SYSCALL

    movl $SYS_CLOSE, %eax

    movl ST_FD_IN(%ebp), %ebx

    int $LINUX_SYSCALL


    movl $SYS_EXIT, %eax

    movl $0, %ebx

    int $LINUX_SYSCALL


    참조 사이트:

    http://www.joinc.co.kr/modules/moniwiki/wiki.php/Site/Assembly/Documents/ProgrammingGroundUp/index.html


Designed by Tistory.