Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. section .rodata
  2. MSG: DB "welcome to sortMe, please sort me",10,0
  3. S1: DB "%d",10,0 ; 10 = '\n' , 0 = '\0'
  4.  
  5. section .data
  6.  
  7. array DB 5,1,7,3,4,9,12,8,10,2,6,11 ; unsorted array
  8. len DB 12
  9.  
  10. section .text
  11. align 16
  12. global main
  13. extern printf
  14.  
  15. main:
  16. push MSG ; print welcome message
  17. call printf
  18. add esp,4 ; clean the stack
  19.  
  20. call printArray ;print the unsorted array
  21.  
  22. ; write your code here
  23. ; you can add functions at the end of this file,
  24. ; and call them from here
  25.  
  26. mov eax, 1 ;exit system call
  27. int 0x80
  28.  
  29. printArray:
  30. push ebp ;save old frame pointer
  31. mov ebp,esp ;create new frame on stack
  32. pusha ;save registers
  33.  
  34. mov eax,0
  35. mov ebx,0
  36. mov edi,0
  37.  
  38. mov esi,0 ;array index
  39. mov bl,byte[len]
  40. add edi,ebx ; edi = array size
  41.  
  42. print_loop:
  43. cmp esi,edi
  44. je print_end
  45. mov al ,byte[array+esi] ;set num to print in eax
  46. push eax
  47. push S1
  48. call printf
  49. add esp,8 ;clean the stack
  50. inc esi
  51. jmp print_loop
  52. print_end:
  53. popa ;restore registers
  54. mov esp,ebp ;clean the stack frame
  55. pop ebp ;return to old stack frame
  56. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement