首页 文章

MIPS汇编程序uint16作为输入

提问于
浏览
0

如何从控制台输入无符号整数16( uint16 ,半字)并将其存储在MIPS中?我应该将其加载为字符串或int?我知道我可以使用带有不同陷阱代码的系统调用来输入,但是如何输入 uint16

read_int        5   
read_float      6   
read_double     7 
read_string     8

1 回答

  • 1

    正如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
    

    这将在寄存器$ v0中留下无符号的16位整数 .

相关问题