Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _test:
- pushl %ebp ;Push old %ebp
- movl %esp, %ebp ;Set %ebp as frame pointer
- subl $24, %esp ;Allocate 24 bytes on the stack
- movl 8(%ebp), %eax ;Get the first argument which was provided to function
- movl %eax, -4(%ebp) ;Store test's argument as arg1 for strlen
- movl -4(%ebp), %eax ;Load back into register
- movl %eax, (%esp) ;Store on stack
- call _strlen ;Call to procedure stringlength.
- movl %eax, -16(%ebp) ;Obtained length of string.
- movl -16(%ebp), %eax ;Load address %ebp-16, i.e., length value back in accumulator.
- cmpl $1, %eax ;Stringlength minus 1?
- jg LBB1_2 ;Jump to LBB1_2 if the result is positive.
- movl $1, -12(%ebp) ;Move immediate operand 1 to location ebp-12
- jmp LBB1_5
- LBB1_2:
- movl -4(%ebp), %eax ;Load string's address back into accumulator.
- movb (%eax), %al ;Move string's address given by %eax to %al.
- movl -16(%ebp), %ecx ;Load address %ebp-16, i.e, of length value into %ecx.
- subl $1, %ecx ;Subtract value by 1.
- movl -4(%ebp), %edx ;Load address %ebp-4 into %edx (the string).
- movb (%edx,%ecx), %cl ;Moves the LAST character (string address + length - 1) to cl.
- cmpb %cl, %al ;Compares the first character(string address points to first char) and last char.
- je LBB1_4 ;If the two are equal, jump to LBB1_4
- movl $0, -12(%ebp) ;Write a 0 value to ebp-12.
- jmp LBB1_5 ;Jump to LBB1_5.
- LBB1_4:
- movl -16(%ebp), %eax ;Length address.
- subl $1, %eax ;Subtract one from length.
- movl -4(%ebp), %ecx ;String address
- movb $0, (%ecx,%eax) ;Stores a zero over the last character.
- movl -4(%ebp), %eax ;String address to accumulator
- addl $1, %eax
- movl %eax, (%esp) ;Store on stack
- call _test ;Recursion??
- movl %eax, -12(%ebp) ;Move the result (1 or 0) from accumulator to ebp-12
- LBB1_5:
- movl -12(%ebp), %eax ;Load value 1 or 0 back into accumulator
- movl %eax, -8(%ebp) ;Move accumulator value to ebp-8
- movl -8(%ebp), %eax ;Set return value
- addl $24, %esp ;Delete 24 bytes from stack
- popl %ebp ;Pop the current frame.
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement