1 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 6 /* Apparently the "b" register constraint is like "r" except that it 7 disallows the use of r0, which means it is safe to use in places 8 where the appearance of r0 would cause a problem due to it being 9 read as zero. */ 10 11 static void announce ( char* str ) 12 { 13 printf("------ %s ------\n", str); 14 } 15 16 int main ( void ) 17 { 18 int i; 19 char* a1 = malloc(100); 20 char* a2 = malloc(100); 21 strcpy(a1,"here is a stringHERE IS A STRING"); 22 23 announce("lswi n == 8 (fe special cased)"); 24 asm volatile("li 5,0\n\t" 25 "lswi 3,%0, 8\n\t" 26 "stw 3,0(%1)\n\t" 27 "stw 4,4(%1)\n\t" 28 "stw 5,8(%1)\n\t" 29 : : "b"(a1), "b"(a2) : "r3", "r4", "r5", 30 "cc", "memory" ); 31 printf("%s\n", a2); 32 for (i = 0; i < 12; i++) 33 printf("%d = 0x%2x\n", i, a2[i]); 34 printf("\n"); 35 36 37 announce("lswi n /= 8"); 38 asm volatile("lswi 3,%0, 9\n\t" 39 "stw 3,0(%1)\n\t" 40 "stw 4,4(%1)\n\t" 41 "stw 5,8(%1)\n\t" 42 : : "b"(a1), "b"(a2) : "r3", "r4", "r5", 43 "cc", "memory" ); 44 printf("%s\n", a2); 45 for (i = 0; i < 12; i++) 46 printf("%d = 0x%2x\n", i, a2[i]); 47 printf("\n"); 48 49 50 announce("lswx"); 51 free(a2); 52 a2 = malloc(100); 53 asm volatile("li 8, 11\n\t" 54 "mtxer 8\n\t" 55 "lswx 3,%0,%2\n\t" 56 "stw 3,0(%1)\n\t" 57 "stw 4,4(%1)\n\t" 58 "stw 5,8(%1)\n\t" 59 : : "b"(a1), "b"(a2), "b"(16) : "r3", "r4", "r5", "r8", 60 "cc", "memory" ); 61 printf("%s\n", a2); 62 for (i = 0; i < 12; i++) 63 printf("%d = 0x%2x\n", i, a2[i]); 64 printf("\n"); 65 66 67 announce("stswi n == 8 (fe special cased)"); 68 free(a2); 69 a2 = calloc(100,1); 70 asm volatile("lswi 3,%0, 19\n\t" 71 "stswi 3,%1, 8\n" 72 : : "b"(a1), "b"(a2) : "r3","r4","r5","r6","r7", 73 "cc", "memory" ); 74 printf("%s\n", a2); 75 printf("\n"); 76 77 78 announce("stswi n /= 8"); 79 free(a2); 80 a2 = calloc(100,1); 81 asm volatile("lswi 3,%0, 19\n\t" 82 "stswi 3,%1, 17\n" 83 : : "b"(a1), "b"(a2) : "r3","r4","r5","r6","r7", 84 "cc", "memory" ); 85 printf("%s\n", a2); 86 printf("\n"); 87 88 89 announce("stswx"); 90 free(a2); 91 a2 = calloc(100,1); 92 asm volatile("li 8, 11\n\t" 93 "mtxer 8\n\t" 94 "lswx 3,%0,%2\n\t" 95 "stswx 3,%1,%2\n\t" 96 : : "b"(a1), "b"(a2), "b"(16) : "r3", "r4", "r5", "r8", 97 "cc", "memory" ); 98 printf("%s\n", a2+16); 99 printf("\n"); 100 101 return 0; 102 } 103