2011-03-27 6 views
1

간단한 상단 casifier 루프는 무한간단한 상단 casifier 루프 무한

내 코드 문제점은 무엇입니까?

어떤 조언이 필요합니까?

내 프로그래밍 환경 & t 구문이 read(2)0복귀하여 파일의 끝 상태 신호 것을

.section .data 
    .section .bss 
    .lcomm buffer,1 
    .section .text 
    .global _start 
_start: 
    movl %esp,%ebp 
    subl $8,%esp 
    #8(%ebp) is 2nd arg == input 
    #12(%ebp) is 3rd arg == output 

    #open,read,open,write,close 
    movl $5,%eax 
    movl 8(%ebp),%ebx 
    movl $0,%ecx 
    movl $0666,%edx 
    int $0x80 
    #%eax contains input's fd 
    #movl to first local var 
    movl %eax,-4(%ebp) 

    movl $5,%eax 
    movl 12(%ebp),%ebx 
    movl $03101,%ecx 
    movl $0666,%edx 
    int $0x80 
    #eax contains output's fd 
    #movl to second local var 
    movl %eax,-8(%ebp) 
loop:   
    #read 1 byte from file 1st byte of data 
    movl $3,%eax 
    movl -4(%ebp),%ebx 
    movl $buffer,%ecx 
    movl $1,%edx 
    int $0x80 
    #buffer contains 1 byte of file 
    cmpb $0,buffer 
    je program_exit 

    pushl buffer 
    call convert #will return converted to %al 
    addl $4,%esp 
    movb %al,buffer 

    #write 1 byte from buffer to file 
    movl $1,%edx 
    movl $buffer,%ecx 
    movl -8(%ebp),%ebx 
    movl $4,%eax 
    int $0x80 
    jmp loop 
program_exit: 
    movl buffer,%ebx 
    movl $1,%eax 
    int $0x80 

    .type convert,@function 
convert: 
    pushl %ebp 
    movl %esp,%ebp 
    movb 8(%ebp),%al #1 byte data in the buffer 
    cmpb $'a',%al 
    jl convert_end 
    cmpb $'z',%al 
    jg convert_end 
    addb $32,%al #convert to upper 

convert_end: 
    movl %ebp,%esp 
    popl %ebp 
    ret 
+0

파일 끝 부분에 null 문자가 없기 때문에 코드가 맞습니까? 입력 파일을 마우스 패드로 입력하고 abcdefghij를 입력하십시오. 종료 조건 0을 'j'로 변경하면 무한대로 반복되지 않습니다. 무엇이 잘못 되었습니까? –

답변

1

참고로, 리눅스, 이맥스 조립된다. 유닉스 계열 시스템에서 매우 드문 아스키 NUL을 찾고 파일의 끝을 찾으려고합니다. 당신은 테라 바이트 크기의 파일을 만들 수있는 쉬운 방법을 원하는 경우에 (, dd if=/dev/zero of=/tmp/huge bs=1048576 seek=1048576 count=1. 모든 것은. 아스키 NUL 문자로 채워집니다 (또는 정수 0, 그러나 당신은 그것을 해석하고 싶다.)

당신은 수정해야 버퍼에 수신 한 데이터를 보지 말고 read(2) 시스템 호출의 반환 값을 비교하여 파일의 끝을 찾는 코드