Advertisement
Guest User

Untitled

a guest
May 10th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .global _inAsm
  2. .extern print
  3. _inAsm:
  4.     pushl %ebp
  5.     movl %esp, %ebp
  6.  
  7.     movl 8(%ebp), %eax #get n
  8.     movl %eax, %ecx # resave n
  9.  
  10.    # movl $1, %ebx # last=1
  11.     movl $2, %esi # i=2
  12.  
  13.     while:
  14.     cmpl $1, %eax # n-1 ? 0
  15.     jle exit
  16.  
  17.     idiv %esi # n/i, eax shi unda sheinaxos ganayofi, edx shi nashti
  18.     cmpl $0, %edx # nashti-0 ? 0
  19.     jne endIf
  20.     movl %esi, %ebx # last=i
  21.     movl %ecx, %eax # save n in eax again
  22.     idiv %esi # n/i, saidanac minda ganayofi anu eax
  23.     movl %eax, %ecx # isev ecx shi shevinaxo ganayofi
  24.     endIf:
  25.  
  26.     inc %esi
  27.     jmp while
  28.  
  29.     movl %ebx, %eax
  30.     pushl %eax
  31.     call _print # print 'last', last is in ebx
  32.  
  33.     exit:
  34.     popl %ebp
  35.     movl %ebp, %esp
  36.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement