How to format an assembly code?

强颜欢笑 提交于 2019-12-24 20:32:40

问题


I have a rather long code written in assembly language and I want to use it inside a C program using asm() function, but every line in the code must be quoted and a new line character ('\n') must be inserted at the end of each line in order to make it usable. Is there any text editing tool that can do that or I have to do it manually?


回答1:


I wrote a program that gets the assembly code from file a.s and saves the formatted text into file b.s.

#include <stdio.h>
#include <stdlib.h>
int main ()
    {
    FILE *pFileA=fopen("a.s","r"),
         *pFileB=fopen("b.s","w");
    if(pFileA==NULL || pFileB==NULL)
        {
        printf("ERROR!\n");
        system("pause");
        return 1;
        }
    char a;
START:
    a=getc(pFileA);
    while(a==' ' || a=='\t' || a=='\n')
        {
        putc(a,pFileB);
        a=getc(pFileA);
        }
    if(a==EOF)
        goto END;
    putc('"',pFileB);
MID:
    while(a!='\n' && a!='"')
        {
        putc(a,pFileB);
        a=getc(pFileA);
        }
    if(a=='"')
        {
        putc(92,pFileB);
        putc(a,pFileB);
        a=getc(pFileA);
        goto MID;
        }
    putc(92,pFileB);
    putc('n',pFileB);
    putc('"',pFileB);
    putc(a,pFileB);
    goto START;
END:
    fclose(pFileA);
    fclose(pFileB);
    printf("SUCCESS!\n");
    system("pause");
    return 0;
    }


来源:https://stackoverflow.com/questions/48836769/how-to-format-an-assembly-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!