如何格式化汇编代码? [英] How to format an assembly code?

查看:231
本文介绍了如何格式化汇编代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用汇编语言编写的相当长的代码,我想使用 asm()函数在C程序中使用它,但代码中的每一行都必须是引用并且必须在每行的末尾插入换行符号('\ n')以使其可用。是否有任何文本编辑工具可以做到这一点,或者我必须手动完成?

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?

推荐答案

我写了一个程序来获取汇编代码从文件作为并将格式化文本保存到文件 bs

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;
    }

这篇关于如何格式化汇编代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆