SteveOS for 16 bit processors (286)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

79 lines
1.0 KiB

  1. bits 16
  2. ;; Strings in cx and dx
  3. ;; Returns 1(true), 0(false) in cl
  4. strcmp:
  5. pusha
  6. strcmp_cont:
  7. mov bx, cx
  8. mov al, [bx]
  9. mov bx, dx
  10. mov ah, [bx]
  11. cmp ah, al
  12. jne strdif
  13. cmp ah, 0 ;Both strings have terminated
  14. je strsame
  15. add cx, 1
  16. add dx, 1
  17. jmp strcmp_cont
  18. strdif: ;strings are different
  19. popa
  20. mov cl, 0
  21. ret
  22. strsame:
  23. popa
  24. mov cl, 1
  25. ret
  26. ;; input(string pointer) in bx
  27. ;; input(delimeter) in al
  28. ;; input(points to array of pointers) in dx (output)
  29. strsplit:
  30. pusha
  31. ;; put start of string in dx array
  32. mov cx, bx
  33. mov bx, dx
  34. mov [bx], cx
  35. mov bx, cx
  36. add dx, 2
  37. inc bx
  38. mov cx, bx ;points to beginning of next "section"
  39. strsplit_loop:
  40. cmp [bx], byte 0
  41. je strsplit_done
  42. cmp [bx], al
  43. je strsplit_match
  44. add bx, 1 ;inc pointer
  45. jmp strsplit_loop
  46. strsplit_match: ;delimeter found
  47. mov [bx], byte 0 ;replaces delimeter w/ null char
  48. push bx
  49. mov cx, bx
  50. mov bx, dx
  51. inc cx
  52. mov [bx], cx
  53. pop bx
  54. inc bx
  55. add dx, 2
  56. jmp strsplit_loop
  57. strsplit_done:
  58. popa
  59. ret