假设我有以下内容可以从用户那里读取字符串:
li $v0,8
syscall
add $a0,$v0,$0
sw $a0,8($s1)
如果 $s1 将地址存储在分配的内存块的开头,那么偏移量 8 偏移了多少?它是 32 字节还是取决于我正在阅读的内容?例如,如果我正在读取每个 1 个字节的字符,那么 8 实际上代表 8 个字节?
好吧,首先,您使用错误的系统调用。您可以在此处找到有关系统调用的文档,但要解释一下,将其更改为:
la $a0 buffer #where buffer is the address of a pre-allocated buffer
li $a1 30 #where 30 is the length of said buffer
li $v0 8
syscall #no more than 30 characters now in $a0
其次,关于您的问题,偏移量始终以字节为单位。