2011-03-28 4 views
1

내가 라는 프로그램을 만들어 실행하는 소스 코드는 다음과 같습니다왜 내 ASM 프로그램은 무한

포함 않습니다.

문제점 :이 프로그램이 무한히 실행되는 이유를 알 수 없습니다.

내 개발 환경은 루프를 종료 할 수있는 하나의 조건이 있습니다 & t 구문

#usage : embed input output message 
    #this program embed message to input's text and make an output file 
    #example1: 
    #input: "abcde" 
    #message: dc 
    #output: "abcDe" 
    #example2: 
    #input: "abcde" 
    #message: bcd 
    #output: "aBCDe" 

    .section .data 
    .section .bss 
     .lcomm buff,1 
    .section .text 
    .global _start 
_start: 
initialize: 
    movl %esp,%ebp 
    movl $0,%edi 
    subl $8,%esp #cleared at the exit_program 
open_r: 
    movl $5,%eax 
    movl 8(%ebp),%ebx 
    movl $0,%ecx 
    movl $0666,%edx 
    int $0x80 
save_rfd: #save to -4(%ebp) 
    movl %eax,-4(%ebp) 
open_w: 
    movl $5,%eax 
    movl 12(%ebp),%ebx 
    movl $03101,%ecx 
    movl $0666,%edx 
    int $0x80 
save_wfd: #save to -8(%ebp) 
    movl %eax,-8(%ebp) 
loop: 
rfd_read: 
    movl $3,%eax 
    movl -4(%ebp),%ebx 
    movl buff,%ecx 
    movl $1,%edx 
    int $0x80 
check_EOF: 
    cmpl $0,%eax 
    je exit_program 
call_func: 
    pushl 16(%ebp) #16(%ebp) is message 
    call checkNconvert #this will change buffer 
wfd_write: 
    movl $4,%eax 
    movl -8(%ebp),%ebx 
    movl buff,%ecx 
    movl $1,%edx 
    int $0x80 
jump_loop: 
    jmp loop 
exit_program: 
    addl $8,%esp 
    movl $1,%eax 
    movl $0,%ebx 
    int $0x80 

checkNconvert: 
    pushl %ebp 
    movl %esp,%ebp 
    movl 8(%ebp),%ebx #8(%ebp) is message that passed over 
    movb (%ebx,%edi,1),%bl #message's edi'th character to %bl 
    cmpb buff,%bl  #compare 
    jne end_checkNconvert 
    .equ n, 'a' - 'A' #n is just number should be used as $n 
    subb $n,buff 
    incl %edi 
end_checkNconvert: 
    movl %ebp,%esp 
    popl %ebp 
    ret 
+0

디버거를 사용해 보셨습니까? –

+0

미안하지만, 나는 그것을 시도하지 않았다. 불행히도, 나는 GDB 사용법을 모른다. 이 문제를 해결하는 방법을 알고 있습니까? –

+0

"무한히 달리십시오"란 무엇을 의미합니까? 출력을 씁니까? 그것은 CPU 시간을 소비하거나 정지 한 것처럼 보입니까? 멈 추면 Ctrl-D를 누르면 어떻게됩니까? –

답변

2

, 당신은 콜에 두 번째 인수로 buff의 내용을로드하는 :

movl buff,%ecx 

...하지만 당신이 원하는 것은buff주소는 :

movl $buff,%ecx 

그래서 당신은 거의 확실 %eax = -EFAULT (-14)로 반환됩니다 read 콜에 나쁜 포인터를 전달하는 -하지만, check_EOF의 코드는 오류를 확인하지 않습니다.

0

에서, 리눅스, 이맥스, 조립, 86이다. 네가 무한 루프를 반복한다고 말하면, 이것은 출구 조건이 결코 맞지 않기 때문이다!

단일 테이블을 입력 데이터로 사용하십시오. 이것이 문제를 해결했을 때, 시스템 콜의 문제점을 찾아내는 것이 좋습니다. (도 및 wfd_read) rfd_read에서