Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. int main( int argc, char *argv[] ){
  4. char* s;
  5. if(argc==1)
  6. {
  7. s="";
  8. }else{
  9. s = argv[1];
  10. }
  11. //char* s = " aqr b qabxx xryc pqr"; example
  12.  
  13.  
  14.  
  15. int x;
  16. asm volatile(
  17. ".intel_syntax noprefix;"
  18.  
  19. "mov eax,%1;"
  20.  
  21.  
  22. "xor edx,edx;"
  23.  
  24. "jmp petla;"
  25.  
  26. "petla0:"
  27. "inc eax;"
  28.  
  29. "petla:"
  30. "cmp [eax],byte ptr 0;"
  31. "jz wyjscie;"
  32. "cmp [eax],byte ptr 32;"
  33. "jz petla0;"
  34.  
  35.  
  36. "inc edx;"
  37.  
  38. "petla1:"
  39. "inc eax;"
  40.  
  41. "cmp [eax],byte ptr 0;"
  42. "jz wyjscie;"
  43. "cmp [eax],byte ptr 32;"
  44. "jz petla;"
  45. "jmp petla1;"
  46.  
  47.  
  48. "wyjscie:"
  49. "mov %0,edx;"
  50.  
  51.  
  52.  
  53. ".att_syntax prefix;"
  54. : "=r" (x)
  55. : "r" (s)
  56. : "eax","edx"
  57. );
  58. printf("%hdn",x);
  59. return 0;
  60. }
  61.  
  62. .intel_syntax noprefix
  63. .globl main
  64. .text
  65.  
  66.  
  67. main:
  68.  
  69. mov ecx,?
  70.  
  71. xor edx,edx
  72.  
  73. jmp petla
  74.  
  75. petla0:
  76. inc ecx
  77.  
  78. petla:
  79. cmp byte ptr [ecx],0
  80. jz wyjscie
  81. cmp byte ptr [ecx],32
  82. jz petla0
  83.  
  84.  
  85. inc edx
  86.  
  87. petla1:
  88. inc ecx
  89.  
  90. cmp byte ptr [ecx],0
  91. jz wyjscie
  92. cmp byte ptr [ecx], 32
  93. jz petla
  94. jmp petla1
  95.  
  96.  
  97. wyjscie:
  98.  
  99.  
  100. push edx
  101. push offset msg
  102. call printf
  103. add esp, 8
  104. mov edx,0
  105. ret
  106.  
  107.  
  108.  
  109. .data
  110. msg: .ascii "number of words=%dn"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement