Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int main( int argc, char *argv[] ){
- char* s;
- if(argc==1)
- {
- s="";
- }else{
- s = argv[1];
- }
- //char* s = " aqr b qabxx xryc pqr"; example
- int x;
- asm volatile(
- ".intel_syntax noprefix;"
- "mov eax,%1;"
- "xor edx,edx;"
- "jmp petla;"
- "petla0:"
- "inc eax;"
- "petla:"
- "cmp [eax],byte ptr 0;"
- "jz wyjscie;"
- "cmp [eax],byte ptr 32;"
- "jz petla0;"
- "inc edx;"
- "petla1:"
- "inc eax;"
- "cmp [eax],byte ptr 0;"
- "jz wyjscie;"
- "cmp [eax],byte ptr 32;"
- "jz petla;"
- "jmp petla1;"
- "wyjscie:"
- "mov %0,edx;"
- ".att_syntax prefix;"
- : "=r" (x)
- : "r" (s)
- : "eax","edx"
- );
- printf("%hdn",x);
- return 0;
- }
- .intel_syntax noprefix
- .globl main
- .text
- main:
- mov ecx,?
- xor edx,edx
- jmp petla
- petla0:
- inc ecx
- petla:
- cmp byte ptr [ecx],0
- jz wyjscie
- cmp byte ptr [ecx],32
- jz petla0
- inc edx
- petla1:
- inc ecx
- cmp byte ptr [ecx],0
- jz wyjscie
- cmp byte ptr [ecx], 32
- jz petla
- jmp petla1
- wyjscie:
- push edx
- push offset msg
- call printf
- add esp, 8
- mov edx,0
- ret
- .data
- msg: .ascii "number of words=%dn"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement