Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. SECTION .data ; Section containing initialized data
  2. isEqual: dw "Perfect median occurs at maximum %d, median %d",10,0
  3.  
  4. SECTION .global
  5. SECTION .bss ; Section containing uninitialized data
  6. lo resw 2
  7. hi resw 2
  8. deci resw 2
  9. SECTION .text ; Section containing code
  10. extern printf ; Print function from glibc
  11. global main ; Linker needs this to find the entry point
  12. main:
  13. nop ; This no-op keeps gdb happy
  14. push ebp ; Set up stack frame for debugger
  15. mov ebp,esp
  16. push ebx ; Must preserve EBP, EBX, ESI & EDI
  17. push esi
  18. push edi
  19. ; Everything before this is boilerplate; use it for all apps
  20. ;Set initial values
  21. mov ebx, 3 ;L1.
  22. mov esi, 2 ;L2
  23. L1:
  24. mov dword[lo], 1
  25. add dword[hi], ebx
  26. mov edi, dword[hi]
  27. mov dword[deci], edi
  28. L2:
  29. sub edi, dword[lo]
  30. jnz L3
  31. push esi
  32. push ebx
  33. push isEqual
  34. call printf
  35. add esp, 12
  36. L3:
  37. add dword[lo], esi ;Reset num2
  38. sub dword[deci], esi ;Reset edi
  39. sub dword[deci], 1
  40. mov edi, dword[deci]
  41.  
  42. inc esi ;Increment esi (L2 looper)
  43. cmp esi, ebx ;
  44. jl L2 ;
  45. mov esi, 2 ;Reset esi
  46.  
  47. inc ebx ;Increment ebx (L1 looper)
  48. cmp ebx, 10000 ;
  49. jl L1 ;
  50. ; Everything after this is boilerplate; use it for all apps
  51. pop edi ; Restore saved registers
  52. pop esi
  53. pop ebx
  54. mov esp,ebp ; Destroy stack frame before returning
  55. pop ebp
  56. ret ; Return control to Linux
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement