简体   繁体   中英

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. The instruction that you point out, li $v0,4 is simply used to request that syscall perform the relevant operation.

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. 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 . 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
  6. read float
  7. read double
  8. read string
  9. sbrk (memory allocation)
  10. exit
  11. print character
  12. read character
  13. Open - file, device, etc.
  14. read from a file descriptor (previously opened with open)
  15. write to a file descriptor (previously opened with 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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