是否有汇编代码约定(主要是 PIC)?
是否有汇编代码约定(主要是 PIC)?
Are there a Code Conventions for Assembly (mainly PIC)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
是否有汇编代码约定(主要是 PIC)?
Are there a Code Conventions for Assembly (mainly PIC)?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
我找到了 汇编语言风格指南(PDF)您可能对此感兴趣。
I was able to find the Assembly Language Style Guide(PDF) which you might be interested in.
编写汇编时,注释每一行非常有帮助,而且一点也不夸张。
When writing assembly, it's pretty helpful and not at all overboard to Comment Every Line
这取决于您是否使用汇编编程或使用 ac 编译器为您创建程序集,如果性能很重要,请不要使用 ac 编译器,而是自己编写汇编。
但一般来说,约定是注释每一行,使用具有有意义的指针名称的简单子例程。 您可以在块上评论一些内容,即
这是典型的编码,地址指针的第一列,命令和相关变量的下一列您通常在实际程序之前的标头部分中定义变量,但这是特殊的到您正在使用的汇编器。 有些不给你变量指针选项,你必须使用直接内存位置。 如果你看看从反汇编器中返回的注释代码,它看起来像这样。
然后将其注释掉,确保对代码进行分组,使用“nop”将代码偏移到良好的整数,例如开始使用 20 的地址,为中断等保留 2 到 20 之间的地址。 根据芯片的不同,我为 12f675 编写了很多代码,所以这是我通常使用的型号。
还将代码保存在简单清晰的子例程中,地址应该是很好的整数,在初始子例程之间留下 10 个左右的 nop 块,您可以随时返回并在以后压缩代码。 并且总是注释你的代码,你怎么注释都不够。
另外,我通常将 init 路由尽可能靠近内存末尾,为实际程序留下最大空间。
希望对一些人有所帮助。
It depends on if your programming in assembly or using a c compiler to create the assembly for you, If performance is important don't use a c compiler, write the assembly yourself.
but in general the conventions are to comment every line, use simple subroutines with meaningful pointer names. there are somethings you would comment on the block, ie
this is the typical coding, the first column for the address pointers the next for the command and associated vars you usually define the vars in the header section before the actual program, but that is particular to the assembler you are using. some don't give you the variable pointer option and you have to use a direct memory location. if you look at the commented code coming back out of the disassembler it would look like.
then you comment it out make sure to group your code use 'nop' s to offset code to good round numbers like start having an address of 20 leaving addresses between 2 and 20 clear for interrupts and the like. depending on the chip I write a lot of code for the 12f675's so that's the model I usually use.
also keep code in simple clear subroutines and there addresses should be nice round numbers leaving blocks of 10 or so nop's between your initial subroutines you can always go back and compress your code later. and always comment your code you cannot comment it enough.
also I usualy put my init routeen as close to the end of memory as posible leaving the maximum space for that actual program.
Hope that helps some.
我不认为有什么正式的东西,但是阅读他们网站上的编码示例可以让您了解常用的习惯用法。 请注意,许多不同的爱好者有很多“贡献”,而且他们可能不是那么好。
还检查其他项目,大多数都会有丑陋的代码; 但你会发现一两颗宝石。
我从来没有在 PIC 上编程过,但喜欢阅读代码。 我依稀记得有一个“实时操作系统”,它有一个非常漂亮和干净的执行流程。 不记得编码风格有多一致,但我会从那里开始。
最好阅读其中的大部分内容,当它像散文一样简单时,你就会找到你的风格
i don't think there's anything formal, but reading the coding samples on their website gives you a taste of the usual idioms. just be aware that there are lots of 'contributions' from many different hobbyists, and they might not be so nice.
also check other projects, most will have ugly code; but you'll find a gem or two.
i never did program on PIC, but liked to read the code. i vaguely remember a "real time OS" with a really nice and clean execution flow. don't remember how consistent was the coding style, but i'd start there.
it's better to read most of them and when it's as easy as prose, then you'll find your style
我同意 Jason S——如果可能的话,请使用 C 编译器,即使您最终使用“__asm”关键字在“.c”文件中嵌入了几行汇编语言。
如果您必须用汇编程序为 PIC 编写整个程序,建议的函数调用约定为
PIClist:PIC 分页和 PCLATH。
I'm with Jason S -- use a C compiler if at all possible, even if you end up embedding a few lines of assembly language in your ".c" file using the "__asm" keyword.
If you must write entire programs in assembler for the PIC, the recommended function call convention is at
PIClist: PIC Paging and PCLATH.
这实际上取决于您使用的 PIC 型号。 例如,PIC16 和 PIC18 有很多汇编示例,可以在网上轻松找到。
然而,像 PIC24 和 PIC32 这样的模型更适合 C。它们有很多 C 语言的 PIC 示例,可以在特定 PIC 模型的网站上找到。 这些 PIC 模型仍然可以在 Assembly 中进行编程,但关于如何编程的 Web 示例很少。 最好的资源是 MPLAB 中的“帮助”,检查您的 PIC 型号使用的任何汇编器的“帮助内容”。 这将向您展示一些示例以及有关如何在 PIC 汇编中进行编程以及完成简单的 PIC 任务(例如定义内存或编写宏)的说明。
It would really depend on the model of PIC you are using. For example, PIC16s and PIC18s have a lot of assembly examples that can easily be found on the web.
However models like PIC24 and PIC32 are much more geared towards C. Their are a lot of PIC examples in C that can be found on the website for your specific PIC model. These PIC models can still be programmed in Assembly, but their are very few web examples on how to. The best resource for that is in MPLAB under "Help", check the "Help Contents" of whatever Assembler your PIC model uses. This will show you some examples as well as instructions on how to program in PIC assembly and accomplish simple PIC tasks such as defining memory or writing macros.