Advertisement
MichaelPetch

Win32 compare 2 strings MASM32

Sep 17th, 2022 (edited)
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. .386
  2. .model flat, stdcall
  3. option casemap :none
  4.  
  5. include \masm32\include\masm32rt.inc
  6.  
  7. .data
  8. prompt db "Insert string:",0
  9. same_msg db "Both string are the same.",0
  10. diff_msg db "The strings are different.",0
  11. string db 50 dup(?)
  12. string2 db 50 dup(?)
  13.  
  14. .code
  15.  
  16. main:
  17. push offset prompt
  18. call StdOut
  19.  
  20. push 50
  21. push offset string
  22. call StdIn
  23.  
  24. push offset prompt
  25. call StdOut
  26.  
  27. push 50
  28. push offset string2
  29. call StdIn
  30.  
  31. push offset string2 ; Push both string offsets (pointers)
  32. push offset string
  33. call crt__stricmp
  34. add esp, 8 ; Remove 8 bytes from stack (2 string pointers)
  35. ; crt_stricmp is CDECL "C" calling convention
  36. ; which requires the caller to clean the stack
  37. cmp eax, 0
  38. ; je same ; Not needed
  39. jne diff
  40.  
  41. same:
  42. push offset same_msg
  43. call StdOut
  44. jmp fin ; We want to exit, not to fall into "diff" code
  45.  
  46. diff:
  47. push offset diff_msg
  48. call StdOut
  49.  
  50. fin:
  51. ret ; Return to exit or do: call ExitProcess
  52.  
  53. end main
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement