这段代码中参数 num 的用途是什么?

What is the use of the argument num in this code?

os161”操作系统包含以下代码。具体来说,系统调用的定义位置:

...

#include <kern/syscall.h>
...

#define SYSCALL(sym, num) \
   .set noreorder       ; \
   .globl sym           ; \
   .type sym,@function      ; \
   .ent sym         ; \
sym:                ; \
   j __syscall                  ; \
   addiu v0, [=10=], SYS_##sym  ; \
   .end sym         ; \
   .set reorder

...

SYSCALL(fork, 0)
SYSCALL(vfork, 1)
SYSCALL(execv, 2)
SYSCALL(_exit, 3)
SYSCALL(waitpid, 4)
SYSCALL(getpid, 5)
...

在底部,每个系统调用都有一个编号。我似乎无法弄清楚这些数字有什么用。

我不是在询问系统调用编号的使用,我是在询问对宏 SYSCALL 的参数 num 的使用。我找不到它的使用位置。

即使将系统调用编号移至 v0,也不会使用参数 num。相反,它移动文件中定义的常量 kern/syscall.h:

...

#define SYS_fork         0
#define SYS_vfork        1
#define SYS_execv        2
#define SYS__exit        3
#define SYS_waitpid      4
#define SYS_getpid       5
...

论点 num 有什么用?

用于其他工具,方便源代码的维护。
以下引自Understanding System Calls

syscalls.S: This file is created from syscalls-mips.S at compile time and is the actual file assembled into the C library. The actual names of the system calls are placed in this file using a script called callno-parse.sh that reads them from the kernel's header files. This avoids having to make a second list of the system calls. In a real system, typically each system call stub is placed in its own source file, to allow selectively linking them in. OS/161 puts them all together to simplify the makefiles. Adding new entries to callno.h automatically causes new user-level system call procedures to be defined when you re-build the user-level code. Each "SYSCALL(name,num)" macro statement in this file is expanded by the C pre-processor into a declaration of the appropriate system call function.

kern/syscall.h 很可能是由其中一种工具生成的。