1 #include <stdio.h>
2 
3 char buffer[] ="0123456789abcdef";
4 char target[] ="XXXXXXXXXXXXXXXX";
5 
main(void)6 int main(void)
7 {
8    setbuf(stdout, NULL);
9 
10    printf("------- Copy 10+1 bytes from buffer to target\n");
11    printf("------- EX to OR in the length\n");
12    printf("before: buffer = |%s|\n", buffer);
13    printf("before: target = |%s|\n", target);
14    asm volatile( "larl 1, 1f\n\t"
15                  "lghi 2, 10\n\t"
16                  "ex   2, 0(1)\n\t"
17                  "j    2f\n\t"
18                  "1:\n\t"
19                  "mvc  0(1,%0),0(%1)\n\t"
20                  "2:\n\t"
21                  : : "a" (target), "a" (buffer): "1", "2", "memory");
22    printf("after:  buffer = |%s|\n", buffer);
23    printf("after:  target = |%s|\n", target);
24    printf("\n");
25 
26    printf("------- EX 0,... has no effect (writes out target)\n");
27    printf("        target = |");
28    asm volatile( "lghi 0, 0xff\n\t" // fill nonsense in r0
29                  "larl 1, 1f\n\t"
30                  "lghi 2, 1\n\t"    // stdout
31                  "lgr  3, %0\n\t"   // target
32                  "lghi 4, %1\n\t"   // len
33                  "ex   0, 0(1)\n\t"
34                  "j    2f\n\t"
35                  "1:\n\t"
36                  "svc  4\n\t"
37                  "2:\n\t"
38                  : : "a" (target), "i" (sizeof target - 1)
39                  : "0", "1", "2", "3", "4");
40    printf("|\n");
41    printf("\n");
42 
43    printf("------- EX to OR in the syscall number (writes out target)\n");
44    printf("        target = |");
45    asm volatile( "lghi 5, 4\n\t"    // NR_write
46                  "larl 1, 1f\n\t"
47                  "lghi 2, 1\n\t"    // stdout
48                  "lgr  3, %0\n\t"   // target
49                  "lghi 4, %1\n\t"   // len
50                  "ex   5, 0(1)\n\t"
51                  "j    2f\n\t"
52                  "1:\n\t"
53                  "svc  0\n\t"       // changed to NR_write
54                  "2:\n\t"
55                  : : "a" (target), "i" (sizeof target - 1)
56                  : "1", "2", "3", "4", "5");
57    printf("|\n");
58    printf("\n");
59 
60    return 0;
61 }
62 
63