Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. char* removerng(char* s, char a, char b);
  4.  
  5. int main(int argc, char** argv)
  6. {
  7. if(argc < 4)
  8. {
  9. printf("Too few input arguments (need 3)\n");
  10. return 1;
  11. }
  12. if(argc > 4)
  13. {
  14. printf("Excess arguments will be ignored.\n");
  15. }
  16. printf("%s - ", argv[1]);
  17. printf("%s\n", removerng(argv[1], *argv[2], *argv[3]));
  18.  
  19. return 0;
  20. }
  21.  
  22.  
  23.  
  24.  
  25. ; char* removerng(char* s, char a, char b)
  26. ; removes (in place) characters from a to b in string s
  27. section .text
  28. global removerng
  29. removerng:
  30. ; prologue
  31. push ebp
  32. mov ebp, esp
  33. push ebx
  34. push esi
  35. push edi
  36.  
  37. ; body
  38. mov eax, [ebp+8]; load string into return address
  39. mov esi, [ebp+8]; last char bhecked
  40. mov edi, [ebp+8]; last char placed
  41.  
  42. loop:
  43. mov bh, [esi]; current char
  44. inc esi
  45. test bh, bh; test for end of string
  46. jz fin
  47. cmp bh, [ebp+12]
  48. jl keep
  49. cmp bh, [ebp+16]
  50. jg keep
  51. jmp loop
  52.  
  53. keep:
  54. mov [edi], bh
  55. inc edi
  56. jmp loop
  57.  
  58. fin:
  59. mov [edi], bh
  60.  
  61. ;epilogue
  62. pop edi
  63. pop esi
  64. pop ebx
  65. mov esp, ebp
  66. pop ebp
  67. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement