正如Luu Vinh Phuc建议的那样,你可以使用read int syscall来获得一个无符号的16位整数 . 系统调用实际上将读取32位有符号整数,但对于整个16位无符号整数范围,低16位将是相同的 . 您可以手动检查高16位是否为零,以验证没有溢出 .
li $v0, 5 # this is the code for reading an integer
syscall # execute the syscall, and read the int into $v0
srl $t0, $v0, 16 # get just the high 16 bits
bne $t0, $0, input_overflow # branch somewhere else if you have an overflow
1 回答
正如Luu Vinh Phuc建议的那样,你可以使用read int syscall来获得一个无符号的16位整数 . 系统调用实际上将读取32位有符号整数,但对于整个16位无符号整数范围,低16位将是相同的 . 您可以手动检查高16位是否为零,以验证没有溢出 .
这将在寄存器$ v0中留下无符号的16位整数 .