ISR和函数调用之间的区别? [英] Difference between ISR and Function Call?

查看:282
本文介绍了ISR和函数调用之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解ISR(中断服务程序)和函数调用之间的区别。



从硬件的角度来看,我觉得函数调用和ISR都是一样的。请纠正我错了
我可以找到有关ISR和函数调用的内容如下:



ISR:




  • 程序


  • 执行
    期间可能发生的异步事件>将PC,标志和寄存器保存在堆栈中,
    禁用所有中断并加载ISR的地址


  • ISR不能有参数可以传递给它


  • 无法返回值

  • 启用中断

  • 一般小因为他们正在花时间进行一些其他的处理

  • 一些ISR有自己的堆栈



功能:




  • 有一个函数调用发生


  • 将PC和寄存器保存在堆栈


  • 可以有参数


  • 可以返回值


  • 对执行的大小和持续时间没有限制




除此之外还有什么区别吗?请告诉我。
我也读过关于如何从ISR发出一个函数调用。请重点介绍。

解决方案

它们不一定与ISR中第一点的静态相同:中断是异步的因此,必须以某种方式中断主处理器的工作。



例如,让我们看看这个MIPS代码用地址进行装饰,这不会产生任何东西有用的:

  4000。添加$ 1,$ 2,$ 3 
4004. sw $ ra,0($ sp)
4008. jal subr#函数调用,将$ ra设置为4012并跳转到4024
4012. lw $ ra,0($ sp)
4016. jr $ ra
4020.
4024. subr:sub $ 2,$ 1,$ 3
4028. jr $ ra

该代码可以从主处理器处理:算术运算(第1,7行)由算术单元完成,存储器控制器的存储器访问(第2,4行),跳转(行3,5,8)也由主CPU执行。 (在绑定目标文件期间, jal 的实际地址设置。)



这是用于函数调用的。在任何时候,确定代码现在在哪里,哪个代码在下一个时间点执行(即当程序计数器递增时:PC + = 4)。



现在有一点,当你的功能做一些复杂的事情,但你仍然希望软件在一个关键的时刻做出反应。然后一个所谓的协处理器发挥作用。该协处理器等待直到发生一些事件(如键盘上的关键笔划),然后调用中断处理程序。这是一个位于内存中某个地址的代码块。



想想,处理器在上面的计算中,但在此期间,您要存储数字地址之间的关键笔划。然后,您从地址 0x80000180 (这被定义为MIPS中的exeption处理程序地址)编写程序:

  lw $ at,keys 
addi $ at,$ at,1
sw $ at,keys
eret

现在,按键会发生什么?


  1. 协处理器了解击键

  2. 主程序的当前PC被保存

  3. 主处理器的PC设置为0x80000180,中断代码执行

  4. eret 之前,中断发生之前,PC被设置为主处理器的PC

  5. 主程序的执行继续执行。

这里有一个从正常执行到步骤2之间的中断处理的切换注意:我已经简化了很多,但应该很清楚,中断如何与函数调用有所不同,以及如何硬件必须添加itionall中断处理能力。


I want to understand difference between ISR (Interrupt Service Routine) and Function call.

I feel both the function call and ISR are the same from the hardware perspective. Please Correct me if I am wrong. All I could found about ISR and Function call is as follows:

ISR:

  • Asynchronous event that can occur any time during the execution of the program

  • Saves the PC, Flags and registers on the stack and disables all the interrupts and loads the address of the ISR

  • ISR cannot have arguments that can be passed to it

  • Cannot return values
  • Enables the interrupts
  • Generally small as they are taking the time of some other process
  • Some of ISR have have their own stack

Function:

  • Occurs when ever there is a function call

  • Saves the PC and registers on the stack

  • Can have arguments

  • Can return values

  • No restriction on the size and duration of execution

Is there any more difference other than this ? Please let me know. I have also read about having a function call from ISR how does that take place. Please highlight on it.

解决方案

They are not necessarily the same as you statet in the first point on ISRs: Interrupts are asynchronous and therefore have to somehow 'interrupt' the work of the main processor(s).

For example, lets look at this MIPS code decorated with addresses, which does not make anything useful:

4000.       add $1, $2, $3
4004.       sw $ra, 0($sp)
4008.       jal subr   # function call, sets $ra to 4012 and jumps to 4024
4012.       lw $ra, 0($sp)
4016.       jr $ra
4020.
4024. subr: sub $2, $1, $3
4028.       jr $ra

This code can be handeled from the main processor: the arithmetic operations (lines 1, 7) are done by the arithmetic unit, memory access (lines 2, 4) by the memory controller, and the jumps (lines 3, 5, 8) are done by the main cpu as well. (The actual address of jal is set during binding of the object file.)

This is for function calls. At any time it is determined, where the code is right now and which code is executed at the next point in time (i.e. when the programm counter is incremented: PC+=4).

Now there comes the point, when your functions do something complicated but you still want the software to react on a key stroke. Then a so called coprocessor comes into play. This coprocessor waits until some event (like a key stroke on your keyboard) occurs, and then calls the interrupt handler. This is a block of code located on a certain address in the memory.

Think, the processor is in the computation above, but in the meantime you want to store the number of key strokes on address keys. Then you write a programm starting at address 0x80000180 (this is defined as the exeption handler address in MIPS):

lw $at, keys
addi $at, $at, 1
sw $at, keys
eret

Now what happens at a keystroke?

  1. The coprocessor gets aware of the keystroke
  2. The current PC of the main procesor is saved
  3. The PC of the main processor is set to 0x80000180, the interrupt code is executed
  4. On eret the PC is set to the PC of the main processor before the interrupt occured
  5. The execution of the main progamm continues there.

Here there is a switch from normal execution to interrupt handling between steps 2 and 3 and back again from 4 to 5.

Note: I have simplified this a lot, but it should be clear, how interrupts are different from function calls, and how the hardware has to have additionall capabilities for interrupt handling.

这篇关于ISR和函数调用之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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