Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. ./program 3 'ax ab cd fg'
  2.  
  3. cd
  4.  
  5. .intel_syntax noprefix
  6. .text
  7. .globl main
  8.  
  9. .data
  10. m1 db '' , 0
  11.  
  12. main:
  13. // compile: gcc prog.s -o prog -m32 -nostdlib
  14.  
  15. // 0 to eax, ebx
  16. mov eax, 0
  17. mov ebx, 0
  18.  
  19. // run ./programm 3 'ax ab cd fg'
  20.  
  21. mov eax , [esp+8] // "argv[1]" -> 3
  22. mov ebx, [esp+12] // "argv[2]" -> 'ax ab cd fg'
  23.  
  24. cld
  25.  
  26.  
  27. search:
  28. // load to AL bite from ESI
  29. lodsb
  30. // check end of string (char '')
  31. cmp AL, 0
  32. // if yes -> out
  33. je out
  34. // check if number of spaces == 1?
  35. cmp eax, 1
  36. je nthWord
  37. cmp al, ' '
  38. je space
  39. lodsb // load next bit
  40. jmp search
  41.  
  42.  
  43. space:
  44. dec eax // dec number of spaces
  45. jmp search // go back to search
  46.  
  47. nthWord:
  48. //copy chars to m1
  49. //and show var m1 at the console
  50.  
  51.  
  52. out:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement