Take the 2-minute tour ×

I made a program called embed

The source code is below.

The Problem : I don't know why this program runs infinitely.

My development environment is linux, emacs, assembly, x86, at&t syntax

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

    .section .data
    .section .bss
        .lcomm buff,1
    .section .text
    .global _start
    movl %esp,%ebp
    movl $0,%edi
    subl $8,%esp    #cleared at the exit_program
    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)
    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)
    movl $3,%eax
    movl -4(%ebp),%ebx
    movl buff,%ecx
    movl $1,%edx
    int $0x80
    cmpl $0,%eax
    je exit_program
    pushl 16(%ebp)  #16(%ebp) is message
    call checkNconvert  #this will change buffer
    movl $4,%eax
    movl -8(%ebp),%ebx
    movl buff,%ecx
    movl $1,%edx
    int $0x80
    jmp loop
    addl $8,%esp
    movl $1,%eax
    movl $0,%ebx
    int $0x80

    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
    movl %ebp,%esp
    popl %ebp
share|improve this question
Have you tried using a debugger? –  Peter G. Mar 28 '11 at 14:36
sorry, I didn't try that. unfortunately, I don't know how to use GDB. do you have any idea how to solve this problem? –  kim taeyun Mar 28 '11 at 14:42
What do you mean by "run infinitely"? Does it write any output? Does it consume CPU time or appear to hang? If it hangs, what happens if you press Ctrl-D? –  Jim Garrison Mar 28 '11 at 16:16
add comment

2 Answers

up vote 2 down vote accepted

In rfd_read (and wfd_read as well), you're loading the contents of buff as the second argument to the syscall:

movl buff,%ecx

...but what you want is the address of buff:

movl $buff,%ecx

So you're passing a bad pointer to the read syscall, which will almost certainly return with %eax = -EFAULT (-14) - but the code at check_EOF doesn't check for errors.

share|improve this answer
add comment

There is a single condition to exit the loop. If you're right saying it loops indefinitely, this is because the exit condition is never met !

Try to use a single table as input data. When this solved the issue, try to figure out what's wrong with the syscall.

share|improve this answer
add comment

Your Answer


