File tree 4 files changed +38
-11
lines changed
4 files changed +38
-11
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ ;
2
+ ; Colin Leroy-Mira, 4 Sept. 2024
3
+ ;
4
+ ; char* stpcpy (char* dest, const char* src);
5
+ ;
6
+
7
+ .export _stpcpy
8
+ .import _strcpy
9
+
10
+ .importzp tmp1, ptr2
11
+
12
+ _stpcpy:
13
+ jsr _strcpy
14
+
15
+ ldx ptr2+1 ; Load dest pointer's last high byte
16
+ tya ; Get the last offset strcpy wrote to
17
+
18
+ clc
19
+ adc ptr2 ; Add to low byte value
20
+ bcc :+
21
+ inx
22
+ : rts ; Return pointer to dest's terminator
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ L1: lda (ptr1),y
25
25
inc ptr2+1
26
26
bne L1
27
27
28
- L9: lda ptr2 ; X still contains high byte
29
- rts
28
+ L9: lda ptr2 ; X still contains dest's original high byte
30
29
30
+ ; On exit, we want AX to be dest (as this is what strcpy returns).
31
+ ; We also want (ptr2),y to still point to dest's terminator, as this
32
+ ; is used by stpcpy().
33
+ rts
Original file line number Diff line number Diff line change 8
8
#define STR_SHORT "Hello, World!"
9
9
#define STR_LONG "This is a longer test string for stpcpy."
10
10
11
+ char dest [512 ];
12
+ char multi_page [300 ];
13
+
11
14
int
12
15
main ()
13
16
{
14
- char dest [50 ];
15
17
const char * src_empty ;
16
18
const char * src_short ;
17
19
const char * src_long ;
@@ -38,7 +40,14 @@ main ()
38
40
assert (end == & dest [sizeof (STR_LONG ) - 1 ]);
39
41
printf ("Test 3 passed.\n" );
40
42
43
+ memset (multi_page , 'a' , sizeof (multi_page )- 1 );
44
+ multi_page [sizeof (multi_page )- 1 ] = '\0' ;
45
+ end = stpcpy (dest , multi_page );
46
+ assert (!strcmp (dest , multi_page ));
47
+ assert (!* end );
48
+ assert (end == & dest [sizeof (multi_page ) - 1 ]);
49
+ printf ("Test 4 passed.\n" );
50
+
41
51
printf ("All tests passed.\n" );
42
52
return EXIT_SUCCESS ;
43
53
}
44
-
You can’t perform that action at this time.
0 commit comments