简体   繁体   English

在MIPS Assembly中,为什么要使用syscall? 为什么程序不按照自动给出的指令进行操作?

[英]In MIPS Assembly why do we use syscall? Why doesn't the program operate on the instructions given automatically?

由于像'li $ v0,4'这样的函数已经告诉程序打印字符串,所以为什么需要syscall?

syscall allows you to access the system library. syscall允许您访问系统库。 The instruction that you point out, li $v0,4 is simply used to request that syscall perform the relevant operation. 您指出的指令li $v0,4仅用于请求syscall执行相关操作。

This is a very common programming pattern. 这是一种非常常见的编程模式。 Rather than allow direct access to the physical devices, the kernel, operating at the highest privilege level, brokers access to the devices through syscall , int 0x80 , sysenter or whichever mechanism is used for the architecture and operating system that you are working under. 以最高特权级别运行的内核不是允许直接访问物理设备,而是通过syscallint 0x80sysenter或您所使用的体系结构和操作系统所使用的任何机制来代理对设备的访问。 This helps the system to be more stable overall. 这有助于系统整体上更加稳定。

While you don't state what your actual platform/OS is, an example set of standard system calls for MIPS can be found here . 虽然您没有说明实际的平台/操作系统是什么,但是可以在此处找到 MIPS的一组标准系统调用示例。 If you look at it, you'll see that it allows for a number of operations with devices to which you otherwise would not have access: 如果您看一下它,将会发现它允许您通过其他方式无法使用的设备进行大量操作:

  1. print integer 打印整数
  2. print float 打印浮动
  3. print double 打印双
  4. print string 打印字符串
  5. read int 读int
  6. read float 读浮点
  7. read double 阅读双
  8. read string 读取字串
  9. sbrk (memory allocation) sbrk(内存分配)
  10. exit 出口
  11. print character 打印字符
  12. read character 读字符
  13. Open - file, device, etc. 打开-文件,设备等
  14. read from a file descriptor (previously opened with open) 从文件描述符读取(以前以open打开)
  15. write to a file descriptor (previously opened with open) 写入文件描述符(以前以open打开)
  16. close - file, device, etc. 关闭-文件,设备等。

A platform may have as many or as few system library functions as are deemed necessary by the designers. 平台可能具有设计人员认为必要的任何数量的系统库功能。 You will find that this is true of Windows, Linux, BSD, Solaris, etc. 您会发现Windows,Linux,BSD,Solaris等都是如此。

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

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