fork(2) download
  1. #include <cstring>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. char *trimRight(char *s)
  7. {
  8. register char *p asm("rax") = s;
  9. register char *spc asm("rbx") = 0;
  10.  
  11. __asm__ (
  12. "LOOP: \n"
  13. " test BYTE PTR [rax] 255 \n"
  14. " jz DONE \n"
  15. " \n"
  16. " cmp BYTE PTR [rax] 32 \n"
  17. " jz SPC \n"
  18. " inc rax \n"
  19. " jmp LOOP \n"
  20. " \n"
  21. " SPC: \n"
  22. " mov rbx rax \n"
  23. " SPC_LOOP: \n"
  24. " inc rax \n"
  25. " cmp BYTE PTR [rax] 32 \n"
  26. " jz SPC_LOOP \n"
  27. " jmp LOOP \n"
  28. " \n"
  29. "DONE: \n"
  30. );
  31.  
  32. if (spc && p!=s && p[-1]==' ') *spc = 0;
  33.  
  34. return s;
  35. }
  36.  
  37. int main()
  38. {
  39. char s[256];
  40.  
  41. cout << '"' << trimRight(strcpy(s, "")) << '"' << endl;
  42. cout << '"' << trimRight(strcpy(s, "abc qwe zzz ")) << '"' << endl;
  43. cout << '"' << trimRight(strcpy(s, "abc qwe zzz ")) << '"' << endl;
  44. cout << '"' << trimRight(strcpy(s, "abc qwe zzz u")) << '"' << endl;
  45.  
  46. return 0;
  47. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: Assembler messages:
prog.cpp:31: Error: junk `PTR [rax]255' after expression
prog.cpp:31: Error: number of operands mismatch for `test'
prog.cpp:34: Error: junk `PTR [rax]32' after expression
prog.cpp:34: Error: number of operands mismatch for `cmp'
prog.cpp:36: Error: no instruction mnemonic suffix given and no register operands; can't size instruction
prog.cpp:40: Error: junk `rax' after expression
prog.cpp:40: Error: number of operands mismatch for `mov'
prog.cpp:42: Error: no instruction mnemonic suffix given and no register operands; can't size instruction
prog.cpp:43: Error: junk `PTR [rax]32' after expression
prog.cpp:43: Error: number of operands mismatch for `cmp'
stdout
Standard output is empty