-
Notifications
You must be signed in to change notification settings - Fork 0
/
strRefAssignDemo.hla
56 lines (42 loc) · 1.51 KB
/
strRefAssignDemo.hla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Program to demonstrate the problem
// with string assignment by reference.
program strRefAssignDemo;
#include( "stdlib.hhf" );
static
string1: string;
string2: string;
begin strRefAssignDemo;
// Get a value into string1
forever
stdout.put( "Enter a string with at least three characters: " );
stdin.a_gets();
mov( eax, string1 );
breakif( (type str.strRec [eax]).length >= 3);
stdout.put( "Please enter a string with at least three chars." nl);
endfor;
stdout.put( "You entered: '", string1, "'" nl );
// Do the string assignment by copying the pointer
mov( string1, ebx );
mov( ebx, string2 );
stdout.put( "String1 = '", string1, "'" nl);
stdout.put( "String2 = '", string2, "'" nl);
// Okay, modify the data in string1 by overwriting
// the first three characters of the string (note that
// a string pointer always points at the first characters
// position in the string and we know we've got at least
// three characters here).
mov( 'a', (type char [ebx]) );
mov( 'b', (type char [ebx+1]) );
mov( 'c', (type char [ebx+2]) );
// Okay, demonstrate the problem with assignment via
// pointer copy.
stdout.put
(
"After assigning 'abc' to the first three characters in string1:"
nl
nl
);
stdout.put( "String1 = '", string1, "'" nl);
stdout.put( "String2 = '", string2, "'" nl);
strfree( string1 ); // Don't free string2 as well!
end strRefAssignDemo;