Advertisement
SVXX

AT&T Assembly Code

Jan 6th, 2014
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. _test:
  2.         pushl %ebp ;Push old %ebp
  3.         movl %esp, %ebp ;Set %ebp as frame pointer
  4.         subl $24, %esp ;Allocate 24 bytes on the stack
  5.         movl 8(%ebp), %eax ;Get the first argument which was provided to function
  6.         movl %eax, -4(%ebp) ;Store test's argument as arg1 for strlen
  7.         movl -4(%ebp), %eax ;Load back into register
  8.         movl %eax, (%esp) ;Store on stack
  9.         call _strlen ;Call to procedure stringlength.
  10.         movl %eax, -16(%ebp) ;Obtained length of string.
  11.         movl -16(%ebp), %eax ;Load address %ebp-16, i.e., length value back in accumulator.
  12.         cmpl $1, %eax ;Stringlength minus 1?
  13.         jg LBB1_2 ;Jump to LBB1_2 if the result is positive.
  14.         movl $1, -12(%ebp) ;Move immediate operand 1 to location ebp-12
  15.         jmp LBB1_5
  16.        
  17. LBB1_2:
  18.         movl -4(%ebp), %eax ;Load string's address back into accumulator.
  19.         movb (%eax), %al ;Move string's address given by %eax to %al.
  20.         movl -16(%ebp), %ecx ;Load address %ebp-16, i.e, of length value into %ecx.
  21.         subl $1, %ecx ;Subtract value by 1.
  22.         movl -4(%ebp), %edx ;Load address %ebp-4 into %edx (the string).
  23.         movb (%edx,%ecx), %cl ;Moves the LAST character (string address + length - 1) to cl.
  24.         cmpb %cl, %al ;Compares the first character(string address points to first char) and last char.
  25.         je LBB1_4 ;If the two are equal, jump to LBB1_4
  26.         movl $0, -12(%ebp) ;Write a 0 value to ebp-12.
  27.         jmp LBB1_5 ;Jump to LBB1_5.
  28.        
  29. LBB1_4:
  30.         movl -16(%ebp), %eax ;Length address.
  31.         subl $1, %eax ;Subtract one from length.
  32.         movl -4(%ebp), %ecx ;String address
  33.         movb $0, (%ecx,%eax) ;Stores a zero over the last character.
  34.         movl -4(%ebp), %eax ;String address to accumulator
  35.         addl $1, %eax
  36.         movl %eax, (%esp) ;Store on stack
  37.         call _test ;Recursion??
  38.         movl %eax, -12(%ebp) ;Move the result (1 or 0) from accumulator to ebp-12
  39.  
  40. LBB1_5:
  41.         movl -12(%ebp), %eax ;Load value 1 or 0 back into accumulator
  42.         movl %eax, -8(%ebp) ;Move accumulator value to ebp-8
  43.         movl -8(%ebp), %eax ;Set return value
  44.         addl $24, %esp ;Delete 24 bytes from stack
  45.         popl %ebp ;Pop the current frame.
  46.         ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement