学习 PIC 单片机汇编语言的最佳资源是什么

发布于 2024-08-06 13:59:36 字数 296 浏览 2 评论 0 原文

我将开始一个项目,在这个项目中我需要对 PIC 微控制器的汇编语言有一个很好的了解。我非常熟悉 C/C++,所以我知道如何编写大部分代码,而且我已经为 PIC 完成了许多项目,所以我了解其架构,但我所有的编程都是用“C”完成的。

是否有一本好书或网站可以很好地解释所有汇编命令的含义以及如何为 PIc 微控制器执行相当简单的任务(闪烁 LED、基本数学等)?

编辑:这篇文章的主要目的是请求学习汇编的资源,而不是争论 PIC 中 C 与汇编的优点,或者 PIC 是否是一个“好的”微控制器。如果这有什么区别的话,我正在使用 PIC18 微控制器。

I'm going to start working on a project where I need to have a decent understanding of Assembly language for the PIC microcontroller's. I'm intimately familiar with C/C++, so I know how to code for the most part, and I have done many projects for the PIC already so I understand the architecture, but have done all my programming for it in 'C'.

Is there a good book or website which does a good job explaining what all the Assembly commands mean and how to do fairly simple tasks (blink LED's, basic math, etc...) for the PIc microcontroller?

Edit: The primary purpose of this post is to request resources for learning Assembly, not debating the merits of C vs Assembly in the PIC's, or whether the PIC is a 'good' microcontroller to use. I am using a PIC18 microcontroller if that makes any difference.

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

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

发布评论

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

评论(5

无人问我粥可暖 2024-08-13 13:59:36

PIC 架构不止一种,其指令集也截然不同。例如,Microchip 不具备 Atmel AVR 的架构一致性。因此,您需要指定您使用的是什么 - 例如 PIC12、16、24、32。

因此,首先我建议避免使用 PIC 汇编器,因为您在 PIC12 上学到的知识可能不太适用于 PIC24。其次,作为软件开发人员,如果可能的话,我会完全避免使用 PIC - 尽管我承认还有其他考虑因素,而且您可能别无选择。

您可以选择的是不使用汇编程序。虽然低端 PIC 可能不是最适合 C 代码生成,但这是编译器编写者的问题;就开发时间而言,尽可能使用 C 仍然更具成本效益。另一方面,对于大批量产品,如果您可以使用汇编器将代码放入较小的部分,这可能是一个因素。在测试 C 解决方案之前决定需要汇编程序通常是“过早的优化”。即使 C 实现未达到大小或时间限制,您也可以将其称为原型,并重新编码以满足限制。这样做可能仍然比从头开始汇编程序编码并同时处理设计和指令集要快。告诉你的老板你将用 C 语言对其进行原型设计,然后当它满足要求时,没有人会愿意浪费金钱重新编码它是一种不可移植、不可维护的汇编代码。

最后回答您的问题,假设您需要快速高效地完成工作,请尽可能使用 Microchip 的示例和应用笔记,并从制造商指令集参考中熟悉指令集。低端部分的指令集并不大。对于日常工作,我喜欢使用“指令集参考卡”作为备忘录 - 它总结了每条指令的所有基本细节,通常在几页内 - 双面打印并层压它! ;)。这是一个 PIC16 示例

There is more that one PIC architecture, with significantly different instruction sets. Microchip do not have the architectural consistency of Atmel AVR for example. So you need to specify what you are using - PIC12, 16, 24, 32 for example.

So first of all I would suggest avoiding PIC assembler on the basis that what you learn on say a PIC12, that may not be very applicable to a PIC24. Secondly I would avoid using a PIC at all if I possibly could as a software developer - though I concede there are other considerations, and you may have no choice.

What you may have a choice over is not using assembler. While the lower end PICs are not perhaps best suited to C code generation, that's the compiler writer's problem; it is still more cost effective in terms of development time to use C where possible. On the other hand for high volume products, if you can fit the code into a smaller part by using assembler, that may be a factor. Deciding you need assembler before you have tested a C solution is often a 'premature optimisation'. Even if the C implementation fails size or time constraints, you can just call it a prototype, and recode it to meet constraints. Doing than may still be faster than starting assembler coding from scratch and struggling with both design and instruction set at the same time. Tell your boss you'll prototype it in C, then when it meets requirements, no one will want to waste money re-coding it is sone non-portable, unmaintainable assembler code.

Finally to answer your question, assuming you need to get work done quickly and efficiently, use Microchip's examples and app-notes as much as possible, and familiarise yourself with the instruction set from the manufacturers instruction set reference. The instruction set for the lower-end parts is not large. For day-to-day work I like to use an "Instruction set reference card" as an aide-mémoire - it summarises all the essential details of each instruction, usually in a couple of pages - print it double sided and laminate it! ;). Here is a PIC16 example

你的他你的她 2024-08-13 13:59:36

我会尝试这个:
图片教程

I would try this:
Pic Tutorial

你穿错了嫁妆 2024-08-13 13:59:36

这可能是一个很晚的答复,但您可以从这个主要为通过应用程序学习 PIC 汇编而编写的实验课程中受益。

检查: http://embedded-ju.ucoz.com/

检查实验选项卡,它包括:

实验 0 -(MPLAB 简介)

实验 1 -(PIC 汇编指令集简介)

实验 2 -(有关指令集和模块化的更多信息编程技术)

实验3 -(基本系统分析与设计)
3.1.硬件指南 I

实验 4 - ( LCD - HD44780 )

实验 5 - (键盘)

实验 6 - (使用 HI-TECH C 编译器MPLAB)
6.1.使用 ICD2 指南进行 PIC 编程。

实验 7 - (定时器(Timer0 和 Timer2))

实验 8 - (USART)

实验 9 - (软件 PWM 和 A/D)


它基于 PIC 16 系列,尤其是 16f84A、16F877A 和 16F917 .. 对示例进行了充分注释,并对实验进行了充分解释。

It might be quite a late reply, but you could benefit from this lab course written primarily for learning PIC Assembly through applications.

Check: http://embedded-ju.ucoz.com/

Check the experiments tab, it includes:

Experiment 0 - (Introduction to MPLAB)

Experiment 1 - (Introduction to PIC Assembly Instruction Set)

Experiment 2 - (More on Instruction Set and Modular Programming Techniques)

Experiment 3 - (Basic System Analysis and Design)
3.1. Guide to Hardware I

Experiment 4 - ( LCD - HD44780 )

Experiment 5 - (Keypad)

Experiment 6 - (Using HI-TECH C Compiler in MPLAB)
6.1. PIC Programming with ICD2 Guide.

Experiment 7 - (Timers (Timer0 and Timer2))

Experiment 8 - (USART)

Experiment 9 - (Software PWM & A/D)


It is based on the PIC 16 series, most notably, 16f84A, 16F877A and 16F917 .. the examples are fully commented, and the experiments fully explained.

错々过的事 2024-08-13 13:59:36

我坚信编写反汇编程序。从一个非常简单的一两行程序开始,该程序可能会加载一个常量的寄存器(必须阅读教程或其他内容来学习该步骤)。组装起来。以您能够或愿意编写程序来读取的格式保存二进制文件(也许是英特尔十六进制,或者如果他们支持的话,也可以是精灵)。

编写一个程序来读取二进制文件并提取程序,然后获取这些字节并编写反汇编程序(即使供应商有反汇编程序,您仍然应该编写一个)。

现在开始迭代该过程,学习一条新指令或使用该指令的新方法,一次一条指令。编写代码来反汇编该指令或选项。尝试编写汇编程序来操作指令中的每个位。

当您完成指令集时,您将比大多数每天使用它的人更了解指令集,您将知道如何为每个操作码的每个选项编写汇编程序,您还可以了解为什么这条指令只能从其位置寻址 N 个字节,而其他人可以访问任何内容,或者该指令只能使用 N 位立即数,而其他人可以使用任何值。诸如此类的事情。

这个过程我已经用过很多次了,学习了很多指令集,ymmv。在前两三个之后,上述过程可能只需要一个下午即可完成。

编辑:

这里的目标是教育而不是下一个伟大的 Sourceforge 项目。输出可以是丑陋的或不完整的,因为你是唯一一个会阅读它的人。

注意:用于可变长度指令集的通用反汇编程序可能有些困难,在您想要遵循所有执行路径的情况下,您不希望线性反汇编二进制文件。我会避免它。即使在可变长度指令集上,采用执行某种线性汇编然后反汇编的简单程序也不困难。您可以通过反汇编和检查 C 编译器(或其他高级语言)的输出来了解有关指令集的大量信息,如果编译器没有汇编器输出选项或没有反汇编器,您可能无法获得利用这一点(除非它是固定长度的指令集)。

另请注意,一旦您学习了一个处理器的汇编程序,第二个处理器就会容易得多,依此类推。你需要从一个到下一个学习的东西通常是这个跳转可以有多大,立即数的规则是什么,间接寻址,基本上所有与检查操作码直接相关的东西。您可以在不查看操作码的情况下学习它,但您必须依赖高质量的文档或汇编器错误消息。

I am a believer in writing a disassembler. Start with a very simple one or two line program that loads a register with a constant perhaps (gotta read a tutorial or something to learn that step). Assemble it. Save the binary in a format you are capable or willing to write a program to read (intel hex perhaps, or elf if they support that).

Write a program to read the binary file and extract the program then take those bytes and write a disassembler (even if the vendor has a disassembler you should still write one).

Now start iterating the process, learn a new instruction or a new way to use that instruction, one instruction at a time. Write code to disassemble that instruction or option. Try to write assembler to manipulate each of the bits in the instruction.

By the time you get through the instruction set you will know the instruction set better than most people that use it every day, you will know how to write assembler for each of the options for each of the opcodes, you may also learn why this instruction can only address N bytes from its location and others can access anything, or that instruction can only use an N bit immediate and others can use any value. That sort of thing.

I have used this process many times and learned many instruction sets, ymmv. After the first couple-three the process above may only take an afternoon to complete.

EDIT:

The goal here is education not the next great sourceforge project. The output can be as ugly or incomplete as you like you are the only one going to read it.

Note: A generic disassembler for variable length instruction sets can be somewhat difficult, you don't want to linearly disassemble the binary in that case you want to follow all the execution paths. I would avoid it. Taking simple programs that execute somewhat linearly assembling then disassembling is not difficult even on a variable length instruction set. You can learn quite a bit about an instruction set by disassembling and examining the output of a C compiler (or other high level language), if the compiler doesn't have an assembler output option or doesn't have a disassembler you may not get to take advantage of this (unless it is a fixed length instruction set).

Also note once you learn assembler for one processor, the second one is much easier, and so on. The things you need to learn from one to the next often become how big can this jump be, what are the rules on immediates, indirect addressing, basically all the things that are directly tied to examining the opcodes. You can learn it without looking at the opcodes, but you have to rely on the documentation or assembler error messages being high quality.

谜泪 2024-08-13 13:59:36

PICList:http://piclist.com/

特别是

The PICList: http://piclist.com/ .

In particular,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文