是否有任何工具可以将 PIC 16F877A 的 ASM 转换为 C

发布于 2024-09-02 09:26:23 字数 69 浏览 1 评论 0原文

我想将 ASM 文件转换为 C 程序。有没有可用的工具。 我的目的是将PIC 16F877A程序的汇编程序转换为C程序...

I want to convert ASM file to C program. is there any tools available for this.
My intention is to convert assembly program of PIC 16F877A program to C program...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾挽 2024-09-09 09:26:23

自动将汇编语言转换为C语言的工具是一种反编译器。
有多个针对 x86 汇编语言的反编译器。
虽然我没有使用过,但我听说 IDA(交互式反汇编器)具有反编译为 C 的选项,并且支持 Microchip PIC 汇编语言。

了解 PIC 汇编的人可以很好地手动将代码从 PIC 汇编移植到 C。
第一步是将“.asm”文件的内容复制到“.c”文件并用“asm”关键字包装它。使用 SDCC 语法,生成的文件如下所示

// the_program.c
__asm  
    ; some assembler code
    goto $0056
__endasm;

:能够编译该“.c”文件并使用“diff”来确认它编译为相同的可执行文件。
有时,人们可以将汇编程序片段翻译成 C 函数,然后编译成相同的可执行文件(使用“diff”进行比较)。
下一步通常看起来像这样

// the_program.c
__asm  
    ; some assembler code
__endasm; 
int main(void){
    for(;;){ // forever
    __asm  
        ; more assembler code
    __endasm;
    };
}
__asm  
    ; yet more assembler code
    goto $0056
__endasm;

从这里开始,您可以采取两条路径:

  • 如果您想向这个预先存在的汇编应用程序添加一些 C 代码,并在相同 16F877A 处理器上运行它,不必费心尝试翻译大段汇编语言——将新代码粘贴到普通的 C 子例程中并从主 for() 循环中调用它。随着时间的推移,为了修复错误和添加功能,您可能会发现一次从 asm 翻译几行到 C 很方便,也许有一天它会完全转换为纯 C。但没有理由这样做一下子就完成了。
  • 如果您想将此应用程序移植到某个完全不同的处理器,最好注释掉“.c”文件中的所有汇编语言,并添加一个简单的闪烁主循环程序。使用汇编语言作为一般指导,一次编写一两个 C 函数,每次添加后在新处理器上运行和测试程序,直到拥有足够的功能。

A tool that automatically converts assembly to C is a kind of decompiler.
There are several decompilers for x86 assembly language.
While I haven't used it, I hear that IDA, the Interactive Disassembler, has a decompile-to-C option, and supports Microchip PIC assembly language.

People who know PIC assembly can do a pretty good job manually porting code from PIC assembly to C.
The first step is copying the contents of the ".asm" file to a ".c" file and wrapping it with the "asm" keyword. With SDCC syntax, the resulting file looks something like:

// the_program.c
__asm  
    ; some assembler code
    goto $0056
__endasm;

You should be able to compile that ".c" file and use "diff" to confirm that it compiles to an identical executable.
A person can sometimes translate pieces of assembler into C functions that compile to identical executable (using "diff" to compare).
The next step often looks something like

// the_program.c
__asm  
    ; some assembler code
__endasm; 
int main(void){
    for(;;){ // forever
    __asm  
        ; more assembler code
    __endasm;
    };
}
__asm  
    ; yet more assembler code
    goto $0056
__endasm;

From here, there are two paths you can take:

  • If you want to add some C code to this pre-existing assembly application, and run it on the same 16F877A processor, don't bother trying to translate the big blobs of assembly language -- stick your new code in normal C subroutines and call it from the main for() loop. As time goes on, in order to fix bugs and add features, you may find it convenient to translate a few lines at a time from asm to C, and perhaps someday it will be entirely converted to pure C. But there's no reason to do it all at once.
  • If you want to port this application to some completely different processor, it's probably best to comment out all the assembly language in the ".c" file, and add a simple blinky-light main loop program. Use the assembly language as general guidance to write one or two C functions at a time, running and testing the program on the new processor after each addition, until you have adequate functionality.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文