data2s.c (791B)
1 /* 2 * New file, replaces the Plan 9 version of data2s. 3 * This one emits GNU assembler syntax. 4 */ 5 6 #include <stdio.h> 7 #include <stdlib.h> 8 9 #ifdef __APPLE__ 10 #define prefix "_" /* go back in time */ 11 #else 12 #define prefix "" 13 #endif 14 15 int 16 main(int argc, char *argv[]) 17 { 18 long len, slen; 19 int c; 20 21 if(argc != 2){ 22 fprintf(stderr, "usage: data2s name\n"); 23 exit(1); 24 } 25 printf(".data\n"); 26 printf(".globl %s%scode\n", prefix, argv[1]); 27 printf(".globl %s%slen\n", prefix, argv[1]); 28 printf("%s%scode:\n", prefix, argv[1]); 29 for(len=0; (c=fgetc(stdin))!=EOF; len++){ 30 if((len&7) == 0) 31 printf(".byte"); 32 else 33 printf(","); 34 printf(" %#x", c&0xff); 35 if((len&7) == 7) 36 printf("\n"); 37 } 38 printf("\n\n.p2align 2\n%s%slen:\n", prefix, argv[1]); 39 printf(".long %d\n", (int)len); 40 return 0; 41 }