简体   繁体   English

尝试在MIPS中使用字符串和整数填充数组时遇到错误?

[英]Getting an error when trying to fill an array with Strings and ints in MIPS?

So I need to fill an array in MIPS with 10 "records", which consist of an employee's name, age, and salary. 因此,我需要在MIPS中用10条“记录”填充一个数组,其中包括员工的姓名,年龄和薪水。 The employee's name is a max of 40 characters and both the age and salary are supposed to be integers. 员工姓名最多40个字符,年龄和薪水均应为整数。 However, when testing this loop I wrote, I always get an "invalid integer input (syscall 5)" for line 18 after I go through the first 5 employees and I type "Emp6" and press enter and I can't seem to figure out why. 但是,在测试我编写的该循环时,经过前5位员工并键入“ Emp6”并按Enter键后,我总是在第18行收到“无效的整数输入(系统调用5)”,似乎看不到搞清楚为什么。 Any help would be greatly appreciated! 任何帮助将不胜感激!

Test Input: 测试输入:

Emp1
1
1
Emp2
2
2
Emp3
3
3
Emp4
4
4
Emp5
5
5
Emp6

Error Code: 错误代码:

Error in line 18: Runtime exception at 0x00400020: invalid integer input (syscall 5)

Go: execution terminated with errors.

Your main problem seems to be that the read_string system call expects the buffer size in $a1 , but you use that for your loop counter. 您的主要问题似乎是read_string系统调用期望$a1的缓冲区大小,但是您将其用于循环计数器。 Thus, you eventually run out of space, and there will be unprocessed text left in the input buffer which will then be read by the subsequent read_int and that blows up. 因此,您最终会用完空间,并且输入缓冲区中会留有未处理的文本,随后后续的read_int会读取这些文本,并且这些文本会read_int

Further problem is that you keep incrementing $a0 but fail to account for that in your addressing. 进一步的问题是,您不断增加$a0但在寻址中却没有考虑到这一点。 Also sw $v0, 0($a0) doesn't make much sense, the string has been read into memory already, $v0 has nothing interesting in it. sw $v0, 0($a0)也没有多大意义,该字符串已被读入内存, $v0没什么有趣的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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