如何在C程序(AVR)中编写汇编ISR?

发布于 2024-11-01 20:56:58 字数 587 浏览 0 评论 0原文

继我的其他问题之后,帮助优化此 C (AVR) 代码? :),我刚刚意识到我并不真正了解如何在我的 C 程序中以汇编方式实现 ISR 的机制。我用谷歌搜索,但没有发现任何有用的东西。

基本上我想在我的 C 项目中设置所有其他内容(包括触发中断的寄存器),但我希望中断执行我编写的一些汇编代码。

如果有帮助的话,我正在 Windows 上使用 AVR studio 6。有人告诉我需要使用 .s 文件,但除此之外我不太确定该怎么做。基本结构就是下面这样吗?

#include <avr\io.h> 
TIMER1_COMPA_vect:
    ; assembly instructions here

如果我希望程序集在 TIMER1_COMPA_vect 中断触发时运行(这是 C 中 ISR 的名称)。还是我完全偏离了轨道?我需要做什么的基本模板是什么?或者,如果这是一个愚蠢的问题,是否有一个链接可以让我找到更多信息?

Following on from my other question, Help optimising this C (AVR) code? :), I just realised that I don't really know the mechanics of how to implement an ISR in assembly within my C program. I googled, but I didn't find anything too useful.

Basically I want to set up everything else in my C project (including the registers to get the interrupt to fire), but I want the interrupt to execute some assembly code that I've written.

I'm using AVR studio 6 on Windows if that helps. I've been told I need to use .s files but apart from that I'm not really sure what to do. Is the basic structure just the following?

#include <avr\io.h> 
TIMER1_COMPA_vect:
    ; assembly instructions here

If I want the assembly to run when the TIMER1_COMPA_vect interrupt is fired (this is the name of the ISR in C). Or am I totally off track? What is a basic template of what I need to do? Or if it's a dumb question, is there a link where I can find more information?

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

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

发布评论

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

评论(1

水溶 2024-11-08 20:56:58

《汇编语言的艺术》(Randall Hyde 着)有两章关于 ISR(第 17 章和第 18 章,特别是第 18.5 和 18.6 节可能对您有帮助)。很快:

  1. 转到 IVT(中断向量表)并使用 ISR 段和偏移量对其进行修改,保存旧值
  2. 您应该执行 TSR(终止并保持驻留)程序,以便即使用户中断操作,ISR 也能驻留在内存中关闭窗口
  3. 记住在完成工作后调用旧的 ISR(这称为中断链接),
  4. 您的 ISR 应该是可重入的(这样,当您的 ISR 仍在运行计算机时,如果再次触发中断不会爆炸;) )

顺便说一句,您可以获得那本伟大书的 pdf 副本此处

The Art of Assembly Language (by Randall Hyde) has two chapters about ISRs (17th and 18th, specifically sections 18.5 and 18.6 might help you). Shortly:

  1. Go to the IVT (interrupt vector table) and modify it with your ISR segment and offset, saving the old values
  2. You should do a TSR (terminate and stay resident) program, so that your ISR stays resident into memory even when the user closes the window
  3. Remember to call the old ISR after you're done with the work (this is called interrupt chaining)
  4. your ISR should be re-entrant (so that if the interrupt is fired again when your ISR is still running the pc won't explode ;) )

By the way, you can obtain a pdf copy of that great book here

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