简体   繁体   English

使用中断减慢程序(在 c 和汇编中)

[英]Slowing down a program (in c and assembly) using interrupts

I want to slow down a program using interrupts according to these conditions :我想根据这些条件使用中断减慢程序的速度:

  • if I press the up arrrow on the keyboard the speed will increase如果我按键盘上的向上箭头,速度会增加
  • if I press the down arrow on the keyboard the speed will decrease如果我按下键盘上的向下箭头,速度会降低

I want to do it by using interrupts : if the speed should decrease I will mask more interrupts and if the speed should increase I will unmask interrupts.我想通过使用中断来做到这一点:如果速度应该降低,我将屏蔽更多的中断,如果速度应该增加,我将取消屏蔽中断。
I know how to reach to the keyboard interrupt and to mask and unmask interrupts.我知道如何到达键盘中断并屏蔽和取消屏蔽中断。
I just don't know how to reach the program speed.我只是不知道如何达到程序速度。 I am writing the code in c and assembly.我正在用 c 和汇编编写代码。

One thing you can do is to intercept one of the interrupts such as the BIOS clock tick int 08h or (better) MS-DOS int 1Ch handler called at about 18 hertz.您可以做的一件事是拦截中断之一,例如以大约 18 赫兹调用的 BIOS 时钟滴答int 08h或(更好的)MS-DOS int 1Ch处理程序。 Then add time-wasting loops based on a variable that is controlled by certain keyboard events.然后根据由某些键盘事件控制的变量添加浪费时间的循环。

Make sure you re-enable interrupts before each delay.确保在每次延迟之前重新启用中断。

At the end of the program you are responsible for restoring the original interrupt vector.在程序结束时,您负责恢复原始中断向量。

You can't speed a program up faster than its starting speed without adjusting the emulation.在不调整仿真的情况下,您无法将程序加速到比其启动速度更快的速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM