1 #include <features.h>
2 #include <signal.h>
3 #include <sys/types.h>
4 #include <pthread.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 
10 char source[40] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\0";
11 char target[40] = "                                       \0";
12 
13 pthread_t thread;
14 
threadfunc(void * arg)15 void *threadfunc(void *arg)
16 {
17 	char buf2[40];
18 	int i;
19 
20 	memset(buf2, 0, sizeof(buf2));
21 	for (i=0; i<5000; i++)
22 		asm volatile(
23 			"lghi 2,0\n"
24 			"lghi 3,0\n"
25 			"lgr 4,%0\n"
26 			"lgr 5,%1\n"
27 			"larl 1,1f\n"
28 			"0: ex 0,0(1)\n"
29 			"j 2f\n"
30 			"1: mvc 0(30,4),0(5)\n"
31 			"2:\n"
32 		::"a" (buf2), "a" (source)
33 		: "1", "2", "3", "4", "5", "memory");
34 	printf("%s\n", buf2);
35 	pthread_exit(0);
36 }
37 
main()38 int main()
39 {
40 	int i;
41 
42 	pthread_create(&thread, NULL, threadfunc, NULL);
43 
44 	for (i=0; i<5000; i++)
45 		asm volatile(
46 			"lghi 4,0\n"
47 			"lghi 5,0\n"
48 			"lgr 2,%0\n"
49 			"lgr 3,%1\n"
50 			"larl 1,1f\n"
51 			"0: ex 0,0(1)\n"
52 			"j 2f\n"
53 			"1: mvc 0(20,2),0(3)\n"
54 			"2:\n"
55 		::"a" (target), "a" (source)
56 		: "1", "2", "3", "4", "5", "memory");
57 	pthread_join(thread, NULL);
58 	printf("%s\n", target);
59 	pthread_exit(0);
60 }
61