程序集如何访问CPU外部的东西,例如HDD或RAM? [英] How can assembly access things outside the CPU, like the HDD or RAM?

查看:87
本文介绍了程序集如何访问CPU外部的东西,例如HDD或RAM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我了解了x86汇编语言.所有命令都非常清楚,但是:我看不到任何可以实际触发计算机的内容,例如:访问RAM,不仅可以访问CPU寄存器,还可以从HDD中读取数据,等等.

So I took a look at the x86 assembly language; All the commands are pretty clear but: I don't see anything that can actually trigger something in the computer like: Access RAM and not only CPU registers, read from the HDD, etc.

  • 您如何超越使用汇编程序在CPU中进行计算?

推荐答案

在x86程序集中,MOV指令用于从RAM中获取数据并将其放入CPU的寄存器之一中,您可以在其中进行操作. MOV指令还可以将数据写回RAM.要使用计算机上的设备,那就是另一回事了.

In x86 assembly, the MOV instruction is used to get data from RAM and put it in one of the CPU's registers, where you can manipulate it. The MOV instruction can also write data back to RAM. To use the devices on the computer, that's another story.

设备使用所谓的中断,即设备希望引起您(CPU)注意时触发的事件.在代码中,您注册了函数以在激发时处理该中断.要在设备之间获取数据,可以使用INOUT指令,它们在数据总线上移动数据.这样,您可以为设备提供说明,例如:从硬盘扇区X到Y获取数据.然后,硬盘旋转起来,获取一些数据并触发中断.您为该中断注册的代码必须处理它,获取数据并将其写入某个适当的RAM位置.大多数CPU和设备还支持DMA(直接内存访问),您只需在其中指定位置即可在RAM中,设备必须在其中写入数据,然后在不中断其间CPU的情况下执行该操作.只有在设备完成后,它才会引发中断,并且您的汇编代码才能相应地做出响应.

Devices use so called interrupts, which are events that are fired when the device wants your (the CPU's) attention. In you code you register your function to handle the interrupt when it fires. To get data to and from the device, you can use the IN and OUT instructions, which move data over the data bus. This way, you can provide the device with instructions, for example: get the data from hard disk sectors X to Y. Then the hard disk spins up, fetches some of the data and fires an interrupt. Your code, which you registered for that interrupt, has to handle it, get the data and write it to some appropriate RAM location. Most CPU's and devices also support DMA (Direct Memory Access), in which you only specify a location in RAM where the device has to write it's data, which it then does without interrupting the CPU in between. Only as soon as the device is done, it raises an interrupt and your assembler code can respond accordingly.

这篇关于程序集如何访问CPU外部的东西,例如HDD或RAM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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