bin2asm.c 531 B

1234567891011121314151617181920212223242526272829303132
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. int main(int argc, char **argv) {
  4. size_t count;
  5. if(argc<1) {
  6. fprintf(stderr, "Usage: %s <infile> \n", argv[0]);
  7. return 1;
  8. }
  9. FILE* in;
  10. if((in=fopen(argv[1], "rb"))==NULL) {
  11. perror("could not open input file");
  12. return 1;
  13. }
  14. printf("chgme ");
  15. count=0;
  16. while(1) {
  17. uint8_t c = fgetc(in);
  18. if(feof(in)) break;
  19. if(!(count%8)) {
  20. if(count) printf("\n ");
  21. printf(".byt $%02x", c);
  22. } else {
  23. printf(", $%02x", c);
  24. }
  25. count++;
  26. }
  27. fclose(in);
  28. return 0;
  29. }