Advertisement
Guest User

Untitled

a guest
May 10th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .global _inAsm
  2. .extern printShit
  3. _inAsm:
  4.     pushl %ebp
  5.     movl %esp, %ebp
  6.  
  7.     pushl %ebx
  8.     pushl %edi
  9.     pushl %esi
  10.  
  11.     xorl %edx, %edx
  12.  
  13.     movl 8(%ebp), %ebx    # GET n
  14.     movl $2, %esi         # int i=2;
  15.     movl $1, %edi         # last=1;
  16.  
  17.     # initial test for while loop
  18.     cmpl $1, %ebx         # compare n : 1
  19.     jle after_loop
  20.     loop:
  21.         #loop body
  22.         movl %ebx, %eax   # get Dividend n
  23.         xorl %edx, %edx
  24.         idivl %esi        # n%i
  25.  
  26.         # if test
  27.         cmpl $0, %edx     # compare n%i : 0
  28.         jne after_if
  29.  
  30.             # if body
  31.             movl %esi, %edi   # last=i;
  32.             movl %ebx, %eax    # get value of n
  33.             xorl %edx, %edx
  34.             idivl %esi         # n/i;
  35.             movl %eax, %ebx    # store quotient back to the register which must hold n
  36.  
  37.         after_if:
  38.         incl %esi         # i++;
  39.     cmpl $1, %ebx         # compare n : 1
  40.     jg loop
  41.  
  42.     after_loop:
  43.         movl %edi, %eax
  44.         pushl %eax
  45.         call _printShit
  46.         popl %eax
  47.  
  48.     end:
  49.  
  50.     popl %esi
  51.     popl %edi
  52.     popl %ebx
  53.  
  54.     movl %ebp, %esp
  55.     popl %ebp
  56.  
  57.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement