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.

109 lines
2.3 KiB

пре 5 година
пре 5 година
пре 5 година
  1. void strcpy (destination, destination_segment, source, source_segment );
  2. void memcpy (destination, destination_segment, source, source_segment, num_bytes );
  3. void strcpy (destination, destination_segment, source, source_segment )
  4. char *destination;
  5. int destination_segment;
  6. char *source;
  7. int source_segment;
  8. {
  9. #asm
  10. ; copy two strings
  11. ; IN si: the first (zero terminated) string
  12. ; IN di: the second (zero terminated) string
  13. ; OUT SF and ZF (same semantics as cmp)
  14. #define DESTINATION 4[bp];
  15. #define DESTINATION_SEGMENT 6[bp];
  16. #define SOURCE 8[bp];
  17. #define SOURCE_SEGMENT 10[bp];
  18. push bp
  19. mov bp,sp
  20. stringcompare:
  21. push ax
  22. push bx
  23. push di
  24. push es
  25. push si
  26. push ds
  27. mov ax, DESTINATION;
  28. mov di, ax
  29. mov ax, DESTINATION_SEGMENT;
  30. mov es, ax
  31. mov ax, SOURCE;
  32. mov si, ax
  33. mov ax, SOURCE_SEGMENT;
  34. mov ds, ax
  35. mov cx, 0x050 // TODO(Jørn) Hardcded number of bytes to copy
  36. .loop:
  37. movsb
  38. cmp cx, 0x0
  39. je .end
  40. dec cx
  41. jmp .loop
  42. .end:
  43. pop ds
  44. pop si
  45. pop es
  46. pop di
  47. pop bx
  48. pop ax
  49. pop bp
  50. #endasm
  51. }
  52. void memcpy (destination, destination_segment, source, source_segment, num_bytes)
  53. void *destination;
  54. int destination_segment;
  55. void *source;
  56. int source_segment;
  57. int num_bytes;
  58. {
  59. #asm
  60. ; copy two strings
  61. ; IN si: the first (zero terminated) string
  62. ; IN di: the second (zero terminated) string
  63. ; OUT SF and ZF (same semantics as cmp)
  64. #define DESTINATION 4[bp];
  65. #define DESTINATION_SEGMENT 6[bp];
  66. #define SOURCE 8[bp];
  67. #define SOURCE_SEGMENT 10[bp];
  68. #define NUM_BYTES 12[bp];
  69. push bp
  70. mov bp,sp
  71. memcpy:
  72. push ax
  73. push bx
  74. push di
  75. push es
  76. push si
  77. push ds
  78. mov ax, DESTINATION;
  79. mov di, ax
  80. mov ax, DESTINATION_SEGMENT;
  81. mov es, ax
  82. mov ax, SOURCE;
  83. mov si, ax
  84. mov ax, SOURCE_SEGMENT;
  85. mov ds, ax
  86. mov cx, NUM_BYTES
  87. .memcpy_loop:
  88. movsb
  89. cmp cx, 0x0
  90. je .end
  91. dec cx
  92. jmp .loop
  93. .memcpy_end:
  94. pop ds
  95. pop si
  96. pop es
  97. pop di
  98. pop bx
  99. pop ax
  100. pop bp
  101. #endasm
  102. }